How are non-CLR dependencies resolved in C#?

1

I have a DLL written in C called amzi.dll, and a wrapper DLL written in Managed C++ called amzinet.dll. amzinet.dll calls amzi.dll.

In my C# project I have added amzinet.dll as a reference and as per the requirement, copied the non-CLR DLL amzi.dll to the bin directory of my application.

When I run my C# Project, I get a "could not load file or assembly amzinet.dll or one of its dependencies". I broke on that exception to see that it was actually failing on amzi.dll, and it was trying to load amzi.dll as a .NET Runtime Assembly and failing with a BadImageException.

These DLLs are Open-Sourced. amzinet which is written in Managed C++ adds amzi.h and uses a linking library amzi.lib to link to amzi.

Why is amzi being attempted to be loaded as a CLR DLL?

Here is the code to amzinet assembly.

Here is the code to amzi DLL

Here is the exception: Notice the HRESULT Value at the end (0x80131018), Could not find that in Error Lookup, but Google says that error means "The module was expected to contain an assembly manifest" which is an indication that system is treating a native dll as a 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.
c#
c++
dll
asked on Stack Overflow Mar 9, 2017 by fahadash • edited Mar 9, 2017 by fahadash

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0