NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException

浪尽此生 提交于 2019-12-23 12:25:02

问题


I have the following code set up in my Startup

IDictionary<string, string> properties = new Dictionary<string, string>();

properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
properties.Add("connection.connection_string", "Data Source=ZEUS;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;Password=xxxxxxxx");
InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), (IDictionary<string, string>) properties);

Assembly asm = Assembly.Load("Repository");

Castle.ActiveRecord.ActiveRecordStarter.Initialize(asm, source);

I am getting the following error:

failed: NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException : Unable to load type 'NNHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.

Possible causes are:

  • The NHibernate.Bytecode provider assembly was not deployed.
  • The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.

I have read and read I am referecning the All the assemblies listed and I am at a total loss as what to try next.

Castle.ActiveRecord.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
log4net.dll
NHibernate.dll
NHibernate.ByteCode.Castle.dll
Castle.Core.dll.

I am 100% sure the assembly is in the bin. Anyone have any ideas?


回答1:


This problem occurs when NHibernate.ByteCode.Castle.dll was built with a different target platform as your project. To test this, change your program target platform from one or more of the following:

  • x64 to x86
  • x86 to x64
  • "Any CPU" to x86
  • "Any CPU" to x64

If any of those solve your problem, then you know that you just need to synchronize the DLL and your target platform.




回答2:


I had this problem also, my solution was to add in the Assembly that creates session following code.

private NHibernate.ByteCode.Castle.ProxyFactoryFactory requiredButNeverUsed;


来源:https://stackoverflow.com/questions/2481586/nhibernate-bytecode-unabletoloadproxyfactoryfactoryexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!