PDA

View Full Version : GuidAttribute & Proxy -> Exception


mr_ST
06-20-2007, 10:47 AM
Part of AOP.xml

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="securityBeforeAdvisor"
type="Tld.Services.SecurityBeforeAdvice, Tld.Services" >
<property name="AuthSvc" ref="authorizationService"/>
</object>

<object id="securedUserService" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces" value="Tld.Contract.Interfaces.IUserService" />
<property name="isSingleton" value="true"/>
<property name="targetName" value="userService" />
<property name="InterceptorNames">
<list>
<value>securityBeforeAdvisor</value>
</list>
</property>
</object>
</objects>


UserService.cs:

[GuidAttribute("9D9057A1-AFA9-4896-9530-B8CCFECC45EA")]
public class UserService: IUserService
{}


When starting application I've got exception:

System.Configuration.ConfigurationErrorsException: Error instantiating context 'spring.root'. ---> Spring.Objects.FatalObjectException: Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Exception has been thrown by the target of an invocation.' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Spring.Objects.Factory.ObjectCreationException: Error creating object with name 'securedUserService' defined in 'assembly [Tld.AppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [Tld.AppServer.AOP.xml]' : Initialization of object failed : Invalid custom attribute provided: 'Incorrect UUID format.' ---> System.ArgumentException: Invalid custom attribute provided: 'Incorrect UUID format.'
at System.Reflection.Emit.TypeBuilder.InternalCreateC ustomAttribute(Int32 tkAssociate, Int32 tkConstructor, Byte[] attr, Module module, Boolean toDisk, Boolean updateCompilerFlags)
at System.Reflection.Emit.CustomAttributeBuilder.Crea teCustomAttribute(ModuleBuilder mod, Int32 tkOwner, Int32 tkAttrib, Boolean toDisk)
at System.Reflection.Emit.CustomAttributeBuilder.Crea teCustomAttribute(ModuleBuilder mod, Int32 tkOwner)
at System.Reflection.Emit.TypeBuilder.SetCustomAttrib ute(CustomAttributeBuilder customBuilder)
at Spring.Proxy.AbstractProxyTypeBuilder.ApplyTypeAtt ributes(TypeBuilder typeBuilder, Type targetType) in l:\projects\Spring.Net\src\Spring\Spring.Core\Prox y\AbstractProxyTypeBuilder.cs:line 236
at Spring.Aop.Framework.DynamicProxy.CompositionAopPr oxyTypeBuilder.BuildProxyType() in l:\projects\Spring.Net\src\Spring\Spring.Aop\Aop\F ramework\DynamicProxy\CompositionAopProxyTypeBuild er.cs:line 82
at Spring.Aop.Framework.DefaultAopProxyFactory.Create AopProxy(AdvisedSupport advisedSupport) in l:\projects\Spring.Net\src\Spring\Spring.Aop\Aop\F ramework\DefaultAopProxyFactory.cs:line 85
at Spring.Aop.Framework.AdvisedSupport.CreateAopProxy () in l:\projects\Spring.Net\src\Spring\Spring.Aop\Aop\F ramework\AdvisedSupport.cs:line 1353
at Spring.Aop.Framework.ProxyFactoryObject.set_Object Factory(IObjectFactory value) in l:\projects\Spring.Net\src\Spring\Spring.Aop\Aop\F ramework\ProxyFactoryObject.cs:line 302
at Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractAutowireCapableObjectF actory.cs:line 1884
at Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractAutowireCapableObjectF actory.cs:line 736
--- End of inner exception stack trace ---
at Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractAutowireCapableObjectF actory.cs:line 752
at Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.CreateObject(String name, RootObjectDefinition definition, Object[] arguments) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractAutowireCapableObjectF actory.cs:line 634
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractObjectFactory.cs:line 1322
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Type requiredType, Object[] arguments) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractObjectFactory.cs:line 250
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name, Object[] arguments) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractObjectFactory.cs:line 1267
at Spring.Objects.Factory.Support.AbstractObjectFacto ry.GetObject(String name) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\AbstractObjectFactory.cs:line 1227
at Spring.Objects.Factory.Support.DefaultListableObje ctFactory.PreInstantiateSingletons() in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\Factory\Support\DefaultListableObjectFactory.c s:line 463
at Spring.Context.Support.AbstractApplicationContext. Refresh() in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\AbstractApplicationContext.cs:line 753
at Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\XmlApplicationContext.cs:line 182
at Spring.Context.Support.XmlApplicationContext..ctor (String name, Boolean caseSensitive, String[] configurationLocations) in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\XmlApplicationContext.cs:line 121
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeConstructor(Obje ct[] args, SignatureStruct& signature, IntPtr declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(Objec t[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(Bi ndingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
at Spring.Objects.ObjectUtils.InstantiateType(Constru ctorInfo constructor, Object[] arguments) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\ObjectUtils.cs:line 171
--- End of inner exception stack trace ---
at Spring.Objects.ObjectUtils.InstantiateType(Constru ctorInfo constructor, Object[] arguments) in l:\projects\Spring.Net\src\Spring\Spring.Core\Obje cts\ObjectUtils.cs:line 176
at Spring.Context.Support.ContextHandler.RootContextI nstantiator.InvokeContextConstructor(ConstructorIn fo ctor) in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\ContextHandler.cs:line 539
at Spring.Context.Support.ContextHandler.ContextInsta ntiator.InstantiateContext() in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\ContextHandler.cs:line 477
--- End of inner exception stack trace ---
at System.Configuration.BaseConfigurationRecord.Evalu ateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evalu ate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey)
at System.Configuration.ClientConfigurationSystem.Sys tem.Configuration.Internal.IInternalConfigSystem.G etSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSecti on(String sectionName)
at Spring.Util.ConfigurationUtils.GetSection(String sectionName) in l:\projects\Spring.Net\src\Spring\Spring.Core\Util \ConfigurationUtils.cs:line 59
at Spring.Context.Support.ContextRegistry.InitializeC ontextIfNeeded() in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\ContextRegistry.cs:line 266
at Spring.Context.Support.ContextRegistry.GetContext( ) in l:\projects\Spring.Net\src\Spring\Spring.Core\Cont ext\Support\ContextRegistry.cs:line 166


It looks like Spring tried to apply GuitAttribute to proxy calss but it is impossible since "GuidAttribute supplies an explicit System.Guid for Type when an automatic GUID is undesirable." As far as I understand we should apply to proxy custom attributes not a "system specific" attributes...

Bruno Baia
06-20-2007, 05:09 PM
Hi,

GuidAttribute has the same problem than the TransactionAttribute (http://forum.springframework.net/showthread.php?t=2590), the guid can only be set using the constructor.
I've commited a fix for that.
Wait for the next nightly build and give it a try.


FYI, I've also introduced the ProxyTargetAttributes property to avoid target attributes to be copied (true by default) :

<object id="securedUserService" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces" value="Tld.Contract.Interfaces.IUserService" />
<property name="isSingleton" value="true"/>
<property name="targetName" value="userService" />
<property name="proxyTargetAttributes" value="false" />
<property name="InterceptorNames">
<list>
<value>securityBeforeAdvisor</value>
</list>
</property>
</object>



Cheers,
Bruno

mr_ST
06-21-2007, 01:03 PM
Thanks a lot!