无法加载文件或程序集 [英] Could not load file or assembly

查看:682
本文介绍了无法加载文件或程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的系统上使用与NHibernate一个SqlServerCe。从我的驱动程序,如果我添加对System.Data.SqlServerCe程序集作为一个参考,我可以创建和运行对数据库就好了查询。当试图使用NHibernate的,不过,我得到以下异常:

第一个机会异常类型'System.IO.FileNotFoundException'在mscorlib.dll发生 其他信息:无法加载文件或程序集System.Data.SqlServerCe或它的某一个依赖。该系统找不到指定的文件。

我跟踪的异常调用的Assembly.Load(System.Data.SqlServerCe),这似乎像它应该工作。对System.Data.SqlServerCe程序集是在GAC(我也试着将其添加为与CopyLocal = true一个本地引用,但没有成功),我可以使用它的成员细,所以为什么我不能显式地加载它?当我在反射器打开装配体,它有麻烦加载System.Transactions的参考(我也试着将它作为一个本地引用,再次无果),因此加载该程序集可能是问题,而不是系统。 Data.SqlServerCe组装。

这是一个共同的问题?系统配置错误,也许?

qualifyAssembly>
解决方案

显然,这可以通过添加&LT解决;元素app.config文件。添加以下有我的应用程序流畅运行:

 <运行>
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
        < qualifyAssembly partialName =System.Data.SqlServerCe全名=System.Data.SqlServerCe,版本= 3.5.1.0,文化=中性公钥= 89845dcd8080cc91/>
    < / assemblyBinding>
< /运行>
 

谢谢!

I'm working on a system to use a SqlServerCe with NHibernate. From my driver program, if I add the System.Data.SqlServerCe assembly as a reference, I can create and run queries against a database just fine. When trying to use NHibernate, though, I get the following exception:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll Additional information: Could not load file or assembly 'System.Data.SqlServerCe' or one of its dependencies. The system cannot find the file specified.

I've traced the exception to a call to Assembly.Load("System.Data.SqlServerCe"), which seems like it should work. The System.Data.SqlServerCe assembly is in the GAC (I've also tried to add it as a local reference with CopyLocal=true, to no avail), and I can use its members fine, so why can't I explicitly load it? When I open the assembly in Reflector, it has trouble loading the System.Transactions reference (I've also tried adding it as a local reference, again to no avail), so loading that assembly might be the problem, rather than the System.Data.SqlServerCe assembly.

Is this a common problem? System misconfiguration, maybe?

解决方案

Apparently this can be solved by adding a <qualifyAssembly> element to the app.config file. Adding the following has my app running smoothly:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <qualifyAssembly partialName="System.Data.SqlServerCe" fullName="System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </assemblyBinding>
</runtime>

Thanks!

这篇关于无法加载文件或程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆