View Full Version : Internal Interface Advice
tferreira
01-13-2007, 07:46 PM
I am trying to apply a throws advice to an internal object that implements an internal interface. I am using .NET 2.0 and have made the Spring.Proxy a friendly assembly using the following declaration in AssemblyInfo:
[assembly: InternalsVisibleTo("Spring.Proxy")]
I am getting the following error when the ApplicationContext attempts to load my config:
System.TypeLoadException: Type 'Spring.Proxy.CompositionAopProxy_30a28514796b4dc5 8a8d702e97d62111' from assembly 'Spring.Proxy, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
tferreira
01-13-2007, 07:52 PM
Whoops. Looks like I had a typo in the AssemblyInfo.cs file. Making Spring.Proxy a friendly assembly works.
Bruno Baia
01-18-2007, 06:35 PM
Oi,
nice tip for applying an aspect to an internal interface.
We should mention this in the doc.
Bruno
Hi.
I have the same problem.
I defined following the spring context object:
internal class AuthService
: IAuthService
{
[Transaction(TransactionPropagation.RequiresNew, IsolationLevel.ReadCommitted, ReadOnly = false)]
public string Login(string login, string password)
{
...
}
} // end internal class AuthService
I used Spring.Transaction.Interceptor.TransactionAttribut e to manage transactions here. Invoking AuthService.Login method throws a following exception:
System.MethodAccessException: MyProj.Core.Service.Security.Auth.Impl.AuthService .Login(System.String, System.String)
at Spring.DynamicReflection.Method_Login_267306e38c3d 4ab3a890e6c4c783d7be.Invoke(Object target, Object[] args)
at Spring.Aop.Framework.ReflectiveMethodInvocation.In vokeJoinpoint() in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\ReflectiveMethodInvocation.cs:line 87
at Spring.Aop.Framework.AbstractMethodInvocation.Proc eed() in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\AbstractMethodInvocation.cs:line 260
at Spring.Transaction.Interceptor.TransactionIntercep tor.Invoke(IMethodInvocation invocation) in c:\projects\daily\Spring.Net\src\Spring\Spring.Dat a\Transaction\Interceptor\TransactionInterceptor.c s:line 80
at Spring.Aop.Framework.AbstractMethodInvocation.Proc eed() in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\AbstractMethodInvocation.cs:line 283
at Spring.Aop.Framework.DynamicProxy.AdvisedProxy.Inv oke(Object proxy, Object target, Type targetType, MethodInfo targetMethod, Object[] args, IList interceptors) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\DynamicProxy\AdvisedProxy.cs:line 185
at CompositionAopProxy_e7fbf588880e445c86488eed78dcfc 40.Login(String login, String password)
...
I have been adviced to use InternalsVisibleTo.
I treid to declare it in my MyProj.Core assembly (AssebmlyInfo.cs).
[assembly: InternalsVisibleTo("Spring.Data")]
and I failed :( .
What do I do wrong? Any suggestions?
Best regards,
Nop.
Bruno Baia
03-27-2007, 12:38 PM
Hi,
The problem occurs in Spring.DynamicReflection dynamic assembly :
at Spring.DynamicReflection.Method_Login_267306e38c3d 4ab3a890e6c4c783d7be.Invoke(Object target, Object[] args)
So in your MyProj.Core assembly (AssebmlyInfo.cs), I guess the assembly that contains your internal class, you need to add :
[assembly: InternalsVisibleTo("Spring.DynamicReflection")]
But this is a temporary solution because AOP should use use MethodInfo.Invoke instead of Dynamic Reflection if the declaring type is internal.
I don't see a DynamicMethod.CreateSafe in the actual code. I'll ping Aleks about this.
HTH,
Bruno
Bruno Baia
03-28-2007, 09:30 AM
Hi,
I revert changes to use standard reflection in spring.Aop until we resolve the problem with dynamic reflection.
Give a try to the latest nightly build (http://www.springframework.net/downloads/nightly/).
Bruno
Hi.
I have still the problem with the AOP for the class with the "internal" attribute declaration.
Class:
namespace MyProj.Core.Service
{
internal class TestService
{
public TestService()
{
}
public void Test()
{
throw new TestServiceException("test");
}
}
}
AOP:
<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxy Creator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>TestService</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>TestAdvice</value>
</list>
</property>
</object>
I have following exception:
[AopConfigException: Cannot create decorator-based IAopProxy for a non public class [MyProj.Core.Service.TestService]]]
Spring.Aop.Framework.DynamicProxy.DecoratorAopProx yTypeBuilder..ctor(IAdvised advised) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\DynamicProxy\DecoratorAopProxyTypeB uilder.cs:66
Spring.Aop.Framework.DefaultAopProxyFactory.Create AopProxy(AdvisedSupport advisedSupport) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\DefaultAopProxyFactory.cs:81
Spring.Aop.Framework.AdvisedSupport.CreateAopProxy () in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\AdvisedSupport.cs:1152
Spring.Aop.Framework.ProxyFactory.GetProxy() in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\ProxyFactory.cs:92
Spring.Aop.Framework.AutoProxy.AbstractAutoProxyCr eator.PostProcessAfterInitialization(Object obj, String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\AutoProxy\AbstractAutoProxyCreator. cs:236
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ApplyObjectPostProcessorsAfterIn itialization(Object instance, String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:2016
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:1862
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:736
This code do not help:
[assembly: InternalsVisibleTo("Spring.DynamicReflection")]
An exception is genereated only if TestService is "internal".
Any suggestions?
Thanks in advance.
Nop.
Bruno Baia
04-11-2007, 01:58 PM
Hi,
forgot about :
[assembly: InternalsVisibleTo("Spring.DynamicReflection")]
because Dynamic reflection has been desactivated for now in spring.Aop.
If a member is not visible, Spring should use standard reflection and it seems it was not the case.
In your latest exemple, you have 2 solutions :
- internal class TestService implements a public interface, so the proxy will implement it too, so no problem.
- internal class TestService does not implement any interfaces, so the proxy will inherit from TestService and needs to be visible from the Spring.Proxy dynamic assembly. If TestService is internal, you can use the InternalsVisibleTo attribute for that :
[assembly: InternalsVisibleTo("Spring.Proxy")]
Bruno
Hi Bruno,
thanks for the quick reply.
I tested both solutions: the former works, the latter does not :( .
Fortunately, the former solution is more convenient for me.
Thanks a lot.
Nop.
Mark Pollack
04-13-2007, 08:02 PM
Hi,
In the second case without an interface were the methods marked as virtual? What was the error specifically in that se.
I've made a JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-525) entry to document the use of InternalsVisibleTo.
Cheers,
Mark
Hi Mark.
In the second case without an interface were the methods marked as virtual?
I tried to mark methods with the virtual attribute. I got the same result - an exception.
What was the error specifically in that se.
The exception is:
[AopConfigException: Cannot create decorator-based IAopProxy for a non public class [MyProj.Core.Service.TestService]]]
Spring.Aop.Framework.DynamicProxy.DecoratorAopProx yTypeBuilder..ctor(IAdvised advised) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\DynamicProxy\DecoratorAopProxyTypeB uilder.cs:66
Spring.Aop.Framework.DefaultAopProxyFactory.Create AopProxy(AdvisedSupport advisedSupport) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\DefaultAopProxyFactory.cs:81
Spring.Aop.Framework.AdvisedSupport.CreateAopProxy () in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\AdvisedSupport.cs:1152
Spring.Aop.Framework.ProxyFactory.GetProxy() in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\ProxyFactory.cs:92
Spring.Aop.Framework.AutoProxy.AbstractAutoProxyCr eator.PostProcessAfterInitialization(Object obj, String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Aop \Aop\Framework\AutoProxy\AbstractAutoProxyCreator. cs:236
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ApplyObjectPostProcessorsAfterIn itialization(Object instance, String name) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:2016
Spring.Objects.Factory.Support.AbstractAutowireCap ableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper) in c:\projects\daily\Spring.Net\src\Spring\Spring.Cor e\Objects\Factory\Support\AbstractAutowireCapableO bjectFactory.cs:1862
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:736
Regards,
Nop.
Bruno Baia
04-17-2007, 02:14 AM
Hi,
- internal class TestService does not implement any interfaces, so the proxy will inherit from TestService and needs to be visible from the Spring.Proxy dynamic assembly. If TestService is internal, you can use the InternalsVisibleTo attribute for that :
[assembly: InternalsVisibleTo("Spring.Proxy")]
This should work with the latest nightly build.
- Bruno
Hi, Bruno.
There is the same exception... :( .
NightBuild - Spring.NET-20070415-2227
AssemblyInfo.cs of the MyProj.Core assembly contains
[assembly: InternalsVisibleTo("Spring.Proxy")]
Service is:
namespace MyProj.Core.Service
{
internal class TestService
{
public TestService()
{
}
public void Test()
{
throw new TestServiceException("test");
}
}
}
Regards,
Nop.
Bruno Baia
04-17-2007, 06:08 AM
Hi,
Your code is oki, but the nightly build process seemed to fail last night, should be a Spring.NET-20070417-22XX
I'll ping Mark about it.
Sorry,
Bruno
Mark Pollack
04-18-2007, 04:43 PM
Hi,
CVS has been incredibly slow the past few days and cruisecontrol has been timing out even though I've given a very generous timeout value. I'd updated cvs by hand and did the build so you can pick it up from the download page but the cc.net web page doesn't show the new build.
The build # is Spring.NET-20070418-1234.zip
Cheers,
Makr
Hi.
Thanks a lot for help and quick replies.
It's work!
Best regards,
Nop.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.