简体   繁体   中英

Unable to load type 'NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu'

I'm trying to work through the " Your first NHibernate based application " to get the hang of other types of ORMs (I'm used to DevExpress' XPO) and I understand that there is a difference between the version that the tut uses and the newest available version.

When I try to run the can_add_new_product test I get the error that titles this question.

  1. I've added a reference to NHibernate.ByteCode.LinFu (CopyLocal=true)
  2. I added the property to my hibernate.cfg.xml like so (spaced to multiple lines for readability):

    NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu

And I made sure that I'm running the build in x86.

What else can I do to solve this?

The full syntax in the node should be like this:

<property name="proxyfactory.factory_class">
   NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
</property>

Can you verify this is your entire text? Also make sure that with your DLL's you have the following:

LinFu.DynamicProxy.dll
NHibernate.ByteCode.LinFu.dll

Hope this helps. I use this for lazy loading and it works successfully with the 2.1.0GA branch (even though our branch has some backported fixes from the trunk (SqlServerCE issues)

Update 1

Ok, in my projects I reference the following assemblies:

  • Antlr3.Runtime.dll
  • Iesi.Collections.dll
  • LinFu.DynamicProxy.dll
  • log4net.dll
  • NHibernate.byteCode.LinFu.dll
  • NHibernate.dll

Can you also post your full hibernate.cfg.xml, the NHibernate configuration file?

Update 2

Have you enabled log4net output? I found that the easiest way to do that was from code. Try doing something like this in your code so you can get some advanced logging:

FileAppender appender = new FileAppender();

appender.File = "nhibernate.log";
appender.LockingModel = new FileAppender.MinimalLock();
appender.ImmediateFlush = true;

pattern = "%timestamp, %thread, %level, %logger, %ndc,%message %newline";
PatternLayout pl = new PatternLayout(pattern);

appender.Layout = pl;
appender.ActivateOptions();
appender.Threshold = log4net.Core.Level.Verbose;

log4net.Config.BasicConfigurator.Configure(appender);

With this output we maybe able to further find what the cause of the issue is.

Would be nice to get a copy of your project so I can investigate and help you find the reason for your errors.

Update 3

Ok, I followed the tutorial and these are my notes and I was able to get a running example up to the update implementation:

  • Added virtual clause to FirstSolution/Domain/Product.cs
  • Added LinFu.DynamicProxy and NHibernate.ByteCode.LinFu assemblies to FirstSolution File
  • Added NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu to the configuration file
  • Changed new SchemaExport(cfg).Execute(false, true, false, false); to new SchemaExport(cfg).Execute(false, true, false);

Add an App.Config (Application Configuration File) to your TEST project, and paste the following into it After :

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>

    <property name="connection.connection_string">ADD CON STRING</property>

    <property name="connection.isolation">ReadCommitted</property>
    <property name="default_schema">dbo</property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>



    <property name="cache.use_second_level_cache">false</property>
    <property name="cache.use_query_cache">false</property>
    <!-- HBM Mapping Files -->
    <mapping assembly="Namespace.Assembly"/>
  </session-factory>
</hibernate-configuration>

Change the Mapping Assembly line and add your connection string. The App.Config needs to be in the file that is Running - ie. the Test assembly, not domain assembly.

Not that it matters for the basic NHibernate test project, but generally the castle bytecode implementation is considered better.

What are the differences between LinFu.DynamicProxy and Castle.DynamicProxy?

Did you try enabling Fusion logs ? Sometimes they're very helpful

I used the Castle Proxy and not linfu, but even i got similar error. The issue for me was that since the proxy class is being loaded dynamically, Visual Studio does not copy all the dependencies properly to the bin dir or bin\\debug dir. Check your build output directory, if the following files are not there, copy them over and then test

LinFu.DynamicProxy.dll NHibernate.ByteCode.LinFu.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM