如何在C#中解析非CLR依赖项?

时间:2017-03-09 18:36:27

标签: c# c++ dll

我有一个用C编写的DLL,名为amzi.dll,还有一个用Managed C ++编写的包装DLL,名为amzinet.dllamzinet.dll致电amzi.dll

在我的C#项目中,我添加了amzinet.dll作为参考,并根据要求将非CLR DLL amzi.dll复制到我的应用程序的bin目录中。

当我运行我的C#项目时,我得到一个“无法加载文件或程序集amzinet.dll或其依赖项之一”。我打破了这个异常,看到它实际上在amzi.dll上失败了,并且它试图加载amzi.dll作为.NET运行时程序集并且失败了BadImageException

这些DLL是开源的。用托管C ++编写的amzinet添加amzi.h并使用链接库amzi.lib链接到amzi。

为什么要尝试将amzi加载为CLR DLL?

Here is the code to amzinet assembly.

Here is the code to amzi DLL

以下是例外:注意最后的HRESULT值(0x80131018),在错误查找中找不到,但Google说错误意味着“模块预计包含程序集清单”,这表明系统将原生dll视为CLR DLL。

=== Pre-bind state information ===
LOG: DisplayName = amzi
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: amzi | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Dev/temp/ASP.Net Core Demo/AmziMvcFxTest/AmziMvcFxTest/
LOG: Initial PrivatePath = C:\Dev\temp\ASP.Net Core Demo\AmziMvcFxTest\AmziMvcFxTest\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Dev\temp\ASP.Net Core Demo\AmziMvcFxTest\AmziMvcFxTest\web.config
LOG: Using host configuration file: C:\Users\fashfaque\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/db74aa31/e82619c1/amzi.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/db74aa31/e82619c1/amzi/amzi.DLL.
LOG: Attempting download of new URL file:///C:/Dev/temp/ASP.Net Core Demo/AmziMvcFxTest/AmziMvcFxTest/bin/amzi.DLL.
ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.

0 个答案:

没有答案