PDA

View Full Version : Object does not match target type



zblock
03-21-2006, 10:38 PM
I'm trying out a small 2.0 web app with the latest nightly build... Anytime I change my UI (aspx or aspx.cs) I get a System.Reflection.TargetException. This is a very simple test web - 1 page only.

I have a hunch that this might be related to the new ASP.NET compilation model??


[[TargetException: Object does not match target type.]
System.Reflection.RuntimeMethodInfo.CheckConsisten cy(Object target) +2328549
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +114
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.RuntimePropertyInfo.SetValue(Obj ect obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +96
System.Reflection.RuntimePropertyInfo.SetValue(Obj ect obj, Object value, Object[] index) +24
Spring.Expressions.PropertyOrFieldNode.SetProperty OrFieldValueInternal(Object context, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\PropertyOrFieldNode.cs:326
Spring.Expressions.PropertyOrFieldNode.SetProperty OrFieldValue(Object context, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\PropertyOrFieldNode.cs:267
Spring.Expressions.PropertyOrFieldNode.Set(Object context, IDictionary variables, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\PropertyOrFieldNode.cs:181
Spring.Expressions.BaseNode.SetValue(Object context, IDictionary variables, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\BaseNode.cs:134
Spring.Expressions.Expression.Set(Object context, IDictionary variables, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\Expression.cs:128
Spring.Expressions.BaseNode.SetValue(Object context, IDictionary variables, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\BaseNode.cs:134
Spring.Expressions.BaseNode.SetValue(Object context, Object newValue) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Expressions\BaseNode.cs:117
Spring.Objects.ObjectWrapper.SetPropertyValue(IExp ression propertyExpression, Object val) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\ObjectWrapper.cs:261
Spring.Objects.ObjectWrapper.SetPropertyValue(Prop ertyValue pv) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\ObjectWrapper.cs:277
Spring.Objects.ObjectWrapper.SetPropertyValues(IPr opertyValues propertyValues, Boolean ignoreUnknown) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\ObjectWrapper.cs:336
Spring.Objects.ObjectWrapper.SetPropertyValues(IPr opertyValues pvs) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\ObjectWrapper.cs:302
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ApplyPropertyValues(String name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:298
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:394
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:703

[ObjectCreationException: Error creating object with name 'Default' defined in 'config [objects]' : Initialization of object failed : Object does not match target type.]
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:753
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:609
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :242
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1203
Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractObjectFactory.cs :1163
Spring.Context.Support.AbstractApplicationContext. GetObject(String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Context\Support\AbstractApplicationContext.cs:11 22
Spring.Web.Support.PageHandler.System.Web.IHttpHan dler.ProcessRequest(HttpContext context) in c:\projects\daily\Spring.Net\src\Spring\Spring.Web \Web\Support\PageHandlerFactory.cs:195
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute() +154
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +64

Erich Eichinger
03-22-2006, 12:06 AM
i just had a similar problem with the same result. I'm using a BasePage class for my pages which calls ApplicationContext.Configure( this, "common") where "common" is an abstract object-definition common to all pages.

I already found the reason of the exception: Spring.Core.Expressions.PropertyOrFieldNode caches PropertyInfo/FieldInfo in it's node-field. Since Aleks replaced the line


object value = ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value);
PropertyValue propertyValue = new PropertyValue(copiedProperty.Name, value);


with


object value = ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value);
PropertyValue propertyValue = new PropertyValue(copiedProperty.Name, value, copiedProperty.Expression);


in the AbstractAutowireCapableObjectFactory.ApplyProperty Values()method, the previously cached PropertyInfo doesn't match the real type anymore, if you change your Page - since this will be compiled to a new type.
The same applies, if I try to configure different page-classes using the same abstract object-definition.

br,
oaky

Erich Eichinger
03-22-2006, 12:39 AM
btw i just fixed this by changing the method InitializeNode() in Spring.Expressions.PropertyOrFieldNode to this:


private void InitializeNode(object context)
{
memberName = this.getText();

if (node != null && !node.DeclaringType.IsAssignableFrom(context.GetTy pe()) )
{
// reinitialize
node = null;
}

if (context != null && node == null && typeNode == null && enumValue == null)

...


br,
oaky

Erich Eichinger
03-22-2006, 07:12 AM
Of course calls to Get(), Set() and GetPropertyInfo() must be synchronized now, since we're modifying a possibly shared instance.

But i'm sure, locking is cheaper than parsing the expression every time.

br,
oaky

Aleks Seovic
03-23-2006, 06:35 AM
Done. Thanks for catching this and recommending solution.

- Aleks

zblock
03-23-2006, 01:31 PM
Thanks oaky and Aleks.