GAC - 大会是在GAC中,但“无法加载文件或程序集” [英] GAC – Assembly is in the GAC but “Could not load file or assembly”

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

问题描述

我是由Visual Studio生成的,我消耗了.NET的DLL第三方COM对象的互操作的dll。

I have an Interop dll that was generated by Visual Studio for a third-party COM object that I am consuming in a .NET dll.

我已经注册了我的两个消费DLL和互操作的dll在GAC中。我必须使用GAC,因为这些DLL正在使用由SharePoint 2010的工作流。

I have registered both my consuming dll and the Interop dll in the GAC. I have to use the GAC because these DLLs are being used by a SharePoint 2010 workflow.

当执行到达在我的DLL调用的互操作DLL中的以下错误被抛出无法加载文件或程序集......系统找不到指定的文件与预期版本和公钥一起点

When the execution gets to the point where my dll calls the Interop dll the following error was thrown" "Could not load file or assembly" … "The system could not find the file specified" together with the expected version and public key.

如果我检查融合集绑定日志查看器,下面的错误被列在互操作DLL的日志条目:

If I examine the Fusion Assembly Binding Log Viewer, the following error is listed in the log entry of the Interop dll:

LOG: GAC Lookup was unsuccessful.

我可以看到在GAC的程序集,它具有正确的版本和公钥令牌作为FileNotFound例外规定。

I can see that assembly in the GAC, and it has the correct version and public key token as specified in the FileNotFound exception.

这是怎么回事?

推荐答案

问题在于,以及版本和公钥是有效的,互操作的处理器架构必须与您的调用DLL。当然,目标框架必须是同一版本。

The problem is that, as well as Version and Public Key being valid, the Processor Architecture of the Interop must match that of your calling DLL. And, of course, the Target Framework must be the same version.

我的DLL被编译成MSIL(不可知论者,值为anycpu)处理器,但由于一些奇怪的原因,Visual Studio的坚持编译互操作为X386。

My dll was compiled to the MSIL (Agnostic, AnyCPU) processor, but for some strange reason Visual Studio insisted on compiling the Interop to x386.

(也许这通常不会引起问题,但我的SharePoint服务器是64位,这可能导致出现的症状)。

(Maybe this wouldn’t normally cause an issue, but my SharePoint server is 64 bit, which may have caused the symptoms to appear).

解决的办法是编译互操作自己:

The solution is to compile the Interop yourself:

1 - 取消注册DLL和互操作从海关总署

1 - Unregister your dll and the Interop from the GAC.

2 - 启动Visual Studio命令提示符的,涉及到了.NET框架您的DLL是针对在Visual Studio版本(即我开发我在Visual Studio 2010的dll,针对.NET 3.5要做到这一步,我需要启动Visual Studio 2008的命令提示符)

2 - Start the Visual Studio Command Prompt of the Visual Studio version that relates to the .NET framework your dll is targeting (i.e. I was developing my dll in Visual Studio 2010, targeting .NET 3.5. To do this step I needed to start the Visual Studio 2008 Command Prompt)

3 - 生成使用Tlbmp互操作

3 - Generate the Interop using Tlbmp

tlbimp <full path and filename of  COM .tlb>  /out:c:\.\Interop.CoolThirdParty.dll /keyfile: <full path and filename of snk> /machine:Agnostic /Namespace:CoolThirdParty  

/机:不可知论会导致互操作必须建立针对MSIL处理器架构,这是一样的我的DLL

The /machine:Agnostic causes the Interop to be built targeting the MSIL Processor Architecture, which is the same as my dll.

4 - 删除旧参考的Interop在你的DLL项目

4 - Remove the old reference to the Interop in your dll project

5 - 删除旧的互操作性文件,并与你刚才生成的替换:

5 - Delete the old Interop file and replace it with the one that you have just generated (e.g. c:.\Interop.CoolThirdParty.dll)

6 - 添加引用您的项目到新的互操作。

6 - Add a reference in your project to the new Interop.

7 - 重建

8 - 注册新建的DLL和新的互操作在GAC

8 - Register your newly build dll and the new Interop in the GAC

它的应该的开始工作。

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

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