My proxy generator is having trouble generating proxies for internal mapped Nhibernate classes. I have tried adding them as visible using InternalsVisibleTo in assemblyinfo.cs but it doesn’t seem to work. Worse, I don’t know how to tell if I’ve even successfully managed to friend the proxy assemblies I want to because if I change a few numbers in the proxy assemblies public key in assemblyinfo.cs there is no error thrown.
Error:
Test method TestProject1.UnitTest1.TestMethod1 threw exception:
NHibernate.HibernateException: Creating a proxy instance failed —> Castle.DynamicProxy.Generators.GeneratorException: Type is not public, so a proxy cannot be generated. Type: BaseSystemCore.Domain.Lot
StackTrace:
Castle.DynamicProxy.DefaultProxyBuilder.AssertValidType(Type target)
Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
NHibernate.ByteCode.Castle.ProxyFactory.GetProxy(Object id, ISessionImplementor session)
NHibernateUtilities.BaseUnitOfWork.handleException(Exception e) in C:\Users\Isaac.G\Desktop\svn.bolinger.ca\Library Projects\NHibernateUtilities\NHibernateUtilities\BaseUnitOfWork.cs: line 871
NHibernateUtilities.BaseUnitOfWork.getAllT in C:\Users\Isaac.G\Desktop\svn.bolinger.ca\Library Projects\NHibernateUtilities\NHibernateUtilities\BaseUnitOfWork.cs: line 115
TestProject1.UnitTest1.TestMethod1() in C:\Users\Isaac.G\Desktop\svn.bolinger.ca\Library Projects\BaseSystemCore\TestProject1\UnitTest1.cs: line 71
Has anyone ever got this to work before?
Thanks
Isaac
NHibernate 3.2 has built in proxy provider. I briefly look at the sources at it seems like they use this format: {0}ProxyAssembly. Where {0} is a type name for lazy mapped class. I have not tested it though. Try adding following to your AssemblyInfo.cs and replace {0} with your lazy class name:
If you still want to use older version of NHibernate you can try using this (for castle byte code provider):
DynamicProxyGenAssembly2 is a temporary assembly that gets generated on the fly by Castle. It contains classes derived from your mapped classes (proxies).