简体   繁体   English

无法加载类型'NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu'

[英]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. 我正在尝试通过“ 你的第一个基于NHibernate的应用程序 ”来获取其他类型的ORM(我习惯使用DevExpress'XPO)并且我知道tut使用的版本和最新的可用版本。

When I try to run the can_add_new_product test I get the error that titles this question. 当我尝试运行can_add_new_product测试时,我得到了标题这个问题的错误。

  1. I've added a reference to NHibernate.ByteCode.LinFu (CopyLocal=true) 我添加了对NHibernate.ByteCode.LinFu的引用(CopyLocal = true)
  2. I added the property to my hibernate.cfg.xml like so (spaced to multiple lines for readability): 我将属性添加到我的hibernate.cfg.xml中(为了便于阅读,间隔为多行):

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

And I made sure that I'm running the build in x86. 我确保我在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: 还要确保使用您的DLL,您有以下内容:

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) 我使用它来进行延迟加载,并且它与2.1.0GA分支一起成功运行(即使我们的分支有一些来自主干的后向移植修复(SqlServerCE问题)

Update 1 更新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? 你还可以发布你的完整的hibernate.cfg.xml,NHibernate配置文件吗?

Update 2 更新2

Have you enabled log4net output? 你启用了log4net输出吗? 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 更新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 在FirstSolution / Domain / Product.cs中添加了虚拟子句
  • Added LinFu.DynamicProxy and NHibernate.ByteCode.LinFu assemblies to FirstSolution File 将LinFu.DynamicProxy和NHibernate.ByteCode.LinFu程序集添加到FirstSolution文件
  • Added NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu to the configuration file 将NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu添加到配置文件中
  • Changed new SchemaExport(cfg).Execute(false, true, false, false); 更改了新的SchemaExport(cfg).Execute(false,true,false,false); to new SchemaExport(cfg).Execute(false, true, false); 到新的SchemaExport(cfg).Execute(false,true,false);

Add an App.Config (Application Configuration File) to your TEST project, and paste the following into it After : 将App.Config(应用程序配置文件)添加到您的TEST项目,并将以下内容粘贴到其中:

<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. 更改Mapping Assembly行并添加连接字符串。 The App.Config needs to be in the file that is Running - ie. App.Config需要位于正在运行的文件中 - 即。 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. 对于基本的NHibernate测试项目并不重要,但通常认为城堡字节码实现更好。

What are the differences between LinFu.DynamicProxy and Castle.DynamicProxy? LinFu.DynamicProxy和Castle.DynamicProxy之间有什么区别?

Did you try enabling Fusion logs ? 您是否尝试启用Fusion日志 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. 对我来说问题是,由于代理类是动态加载的,因此Visual Studio不会将所有依赖项正确复制到bin目录或bin \\ debug目录。 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 LinFu.DynamicProxy.dll NHibernate.ByteCode.LinFu.dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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