Hi, when I try to create
var repo = Substitute.For<IRepository>();
where IRepository is defined as an internal interface in the assembly
under test, I get the following error:
Castle.DynamicProxy.Generators.GeneratorException: Type
SomeNamespace.IRepository is not visible to DynamicProxy. Can not
create proxy for types that are not accessible. Make the type public,
or internal and mark your assembly with [assembly:
InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]
attribute.
at Castle.DynamicProxy.DefaultProxyBuilder.AssertValidType(Type
target)
at
Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options)
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options, IInterceptor[] interceptors)
at
NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.CreateProxyUsingCastleProxyGenerator(Type
typeToProxy, Type[] additionalInterfaces, Object[]
constructorArguments, IInterceptor interceptor, ProxyGenerationOptions
proxyGenerationOptions)
at
NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.GenerateProxy(ICallRouter
callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[]
constructorArguments)
at NSubstitute.Proxies.ProxyFactory.GenerateProxy(ICallRouter
callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[]
constructorArguments)
at NSubstitute.Core.SubstituteFactory.Create(Type[] typesToProxy,
Object[] constructorArguments)
at NSubstitute.Substitute.For(Type[] typesToProxy, Object[]
constructorArguments)
at NSubstitute.Substitute.For[T](Object[] constructorArguments)
The way to possibly solve it:
http://groups.google.com/group/moqdisc/browse_thread/thread/d40c0ab145f77be9
It seems that the 'InternalsVisible.ToDynamicProxyGenAssembly2' class
and constant are not 'merged' into the NSubstitute assembly.
If I then add the 'ridiculously long' name in manually, I still get
this error:
System.TypeLoadException: Type 'Castle.Proxies.IRepositoryProxy' from
assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null' is attempting to implement an inaccessible
interface.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule
module, Int32 tk, ObjectHandleOnStack type)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder
type)
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
at
Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String
typeName, Type proxyTargetType, Type[] interfaces, INamingScope
namingScope)
at
Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass1.<GenerateCode>b__0(String
n, INamingScope s)
at
Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey
cacheKey, Func`3 factory)
at
Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type
proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
at
Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options)
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type
interfaceToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options, IInterceptor[] interceptors)
at
NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.CreateProxyUsingCastleProxyGenerator(Type
typeToProxy, Type[] additionalInterfaces, Object[]
constructorArguments, IInterceptor interceptor, ProxyGenerationOptions
proxyGenerationOptions)
at
NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.GenerateProxy(ICallRouter
callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[]
constructorArguments)
at NSubstitute.Proxies.ProxyFactory.GenerateProxy(ICallRouter
callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[]
constructorArguments)
at NSubstitute.Core.SubstituteFactory.Create(Type[] typesToProxy,
Object[] constructorArguments)
at NSubstitute.Substitute.For(Type[] typesToProxy, Object[]
constructorArguments)
at NSubstitute.Substitute.For[T](Object[] constructorArguments)
Any ideas, if this could/should/would be supported?