Web API unable to reference DLL - c#

I have a .Net 4.5 project which has been built to a 64-bit DLL that needs to be included in my Web API project. The Web API project is also built to 64-bit. No matter what I try, I keep getting the exception "Could not load file or assembly '*.DLL' or one of its dependencies. The specified module could not be found.". This DLL is created from a mixed-mode project which contains an unmanaged C++ project and a C++/CLI wrapper compiled with /clr.
I have used DependencyWalker to check and make sure all the dependencies DLL are in the same folder as the Web API project as well as the bin folder. I also checked bitness to make sure they are all 64-bit. I then created a C# console project which loads this DLL along with its dependencies and everything worked just fine.
My Web API project uses local IIS 6.2 server and the application pool is using the default identity (ApplicationPoolIdentity). Even if I changed the identity to NetworkService it still failed. At this point I'm out of ideas on how to debug further. I have used Process Monitor before to nail down the missing DLL but not sure how to use it with Web API. Any suggestions on how to proceed with this issue would be appreciated.
Edit - here's the Fusion log:
The operation was successful. Bind result: hr = 0x0. The operation
completed successfully.
Assembly manager loaded from:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under
executable c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows.
=== Pre-bind state information === LOG: DisplayName = TestBridge (Partial) WRN: Partial binding information was supplied for an
assembly: WRN: Assembly Name: TestBridge | Domain ID: 12 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:///D:/build/MSVC/ImageSearchService/ LOG: Initial PrivatePath =
D:\build\MSVC\ImageSearchService\bin LOG: Dynamic Base =
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\imagesearchservice\d0503829 LOG: Cache Base =
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\imagesearchservice\d0503829 LOG: AppName = 7ee35914 Calling
assembly : (Unknown).
=== LOG: This bind starts in default load context. LOG: Using application configuration file:
D:\build\MSVC\ImageSearchService\web.config LOG: Using host
configuration file:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG:
Using machine configuration file from
C:\Windows\Microsoft.NET\Framework64\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/Framework64/v4.0.30319/Temporary
ASP.NET Files/imagesearchservice/d0503829/7ee35914/TestBridge.DLL.
LOG: Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary
ASP.NET
Files/imagesearchservice/d0503829/7ee35914/TestBridge/TestBridge.DLL.
LOG: Attempting download of new URL
file:///D:/build/MSVC/ImageSearchService/bin/TestBridge.DLL. LOG:
Assembly download was successful. Attempting setup of file:
D:\build\MSVC\ImageSearchService\bin\TestBridge.dll LOG: Entering
download cache setup phase. LOG: Assembly Name is: TestBridge,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null LOG: A
partially-specified assembly bind succeeded from the application
directory. Need to re-apply policy. LOG: Using application
configuration file: D:\build\MSVC\ImageSearchService\web.config LOG:
Using host configuration file:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG:
Using machine configuration file from
C:\Windows\Microsoft.NET\Framework64\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: Binding
succeeds. Returns assembly from
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\imagesearchservice\d0503829\7ee35914\assembly\dl3\584c8f8c\64f0e4b3_4a53cf01\TestBridge.dll.
LOG: Assembly is loaded in default load context.

You may need to enable 64 bit IIS Express support as part of VS 2013 / 2015 / 2017:
Tools -> Options -> Projects and Solutions -> Web Projects -> Use the
64 bit version of IIS Express
Credit to the response in this question

Try the following:
Fusion Log for better error message: http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx
Ensure App Pool is 4.0
Go to App Pool Settings in IIS and check if 'Enable 32 bit applications' is true
If Fusion Log shows that everything is peachy, then it might be a problem with a dependent module which is unmanaged.. use SysInternal's ProcMon utility to see if that reports any issues.
another issue is checking the VC++ 11 runtime on the machine.. some machines have it installed and some don't.
Check the CPU (any cpu, x86 vs 64 again) just to be sure.

Related

Referencing a DLL from another DLL - Missing Dependency

I have a DLL written in C# that runs a job from within the context of a 3rd party application. The DLL needs to reference another 3rd party DLL. Intellisense in VS works great but during runtime the error is generated: "Could not load file or assembly or one of its dependencies. The system cannot find the file specified."
I ran the dependency tool and saw a missing reference to mscorwks and perfcounter.dll. Putting these 2 missing DLLS in the same folder as the 3rd party DLL corrects the missing references in the dependency tool.
I'm not sure what to do next. Where do all these files need to reside for my DLL to work properly? The interesting thing is I also have a stand-alone executable that references the same 3rd party DLL and it doesn't have any issues with missing references.
What should I try next?
Edit:
Downloaded Fusion++ and this is the result from the log. Looks like it can't find the parent. Not sure how to point the dependent DLL to the right folder when it's running in the context of a 3rd party application.
*** Assembly Binder Log Entry (11/24/2019 # 6:59:35 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files\Autodesk\Vault Professional 2020\Explorer\Connectivity.JobProcessor.Delegate.Host.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = LicenseSpring, Version=4.7.0.0, Culture=neutral, PublicKeyToken=2d5c13cc31edbaaf
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Connectivity.JobProcessor.Delegate.Host.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: LicenseSpring, Version=4.7.0.0, Culture=neutral, PublicKeyToken=2d5c13cc31edbaaf
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring/LicenseSpring.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring/LicenseSpring.EXE.
LOG: All probing URLs attempted and failed.
When you added LicenseSpring.dll from disk(via Browse) - VS just copied this DLL and placed it to the package folder. But VS doesn't know anything about dependent DLL. Let's consider that LicenseSpring.dll contains two methods. The first method, do some simple stuff and don't have any dependencies from another DLL. The second method depends on some other DLL. If you call the first method - it will work fine. But when you try to exec the second method - you will get an error:
"Could not load file or assembly or one of its dependencies ...
How to fix this:
When you are adding a library from disk - you need to add all dependencies as well.
You can add your assemblies to GAC - but this will be more complicated
If you cannot find out, what Assembly the system is missing at runtime, you can enable FUSLOG (https://learn.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer) and use Assembly Binding Log Viewer to find out what is missing.
To be honest: FUSLOG is not very comfortable, but it's working great. Don't forget to disable it, when you are done.

C# binding failure on missing ".resources" files

I have a C# program that links to a (large) third-party library and builds successfully with it. All necessary references between my program and the library are included, and the program starts correctly.
Upon loading the .NET managed DLL for the aforementioned library, I get a System.IO.FileNotFoundException that says that the library or one of its dependencies could not be loaded ("The specified module could not be found.").
Since the relevant DLL is present in the Release directory, I went through the fusion event logs and found only binding failures for a bunch of nonexistent <PROJECT>.resource.<DLL|EXE> files under a nonexistent Release\en directory. This doesn't make much sense to me at all, since the project's only resource (a single icon) is internalized.
The logs look like this, with some information redacted:
*** Assembly Binder Log Entry (7/11/2016 # 10:08:49 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Users\USER\Desktop\PROJECT\bin\x86\Release\PROJECT.vshost.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = PROJECT.resources, Version=1.0.0.0, Culture=en, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/USER/Desktop/PROJECT/bin/x86/Release/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = PROJECT.vshost.exe
Calling assembly : PROJECT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\USER\Desktop\PROJECT\bin\x86\Release\PROJECT.vshost.exe.Config
LOG: Using host configuration file:
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:/Users/USER/Desktop/PROJECT/bin/x86/Release/en/PROJECT.resources.DLL.
LOG: Attempting download of new URL file:///C:/Users/USER/Desktop/PROJECT/bin/x86/Release/en/PROJECT.resources/PROJECT.resources.DLL.
LOG: Attempting download of new URL file:///C:/Users/USER/Desktop/PROJECT/bin/x86/Release/en/PROJECT.resources.EXE.
LOG: Attempting download of new URL file:///C:/Users/USER/Desktop/PROJECT/bin/x86/Release/en/PROJECT.resources/PROJECT.resources.EXE.
LOG: All probing URLs attempted and failed.
Update: This is what Process Monitor shows when loading the DLL:
The first three loads are the relevant DLL, and the following ones are (ostensibly) its dependencies, all from the standard VS C++ redistributable.
Update 2: Dependency Walker shows the same DLLs as missing, although this doesn't seem to manifest at load time:

IIS 7 Classic ASP application DLL load issue

I am migrating an classic asp site from Windows 2003 IIS 6 .net framework 1.1 to Windows 2008 32 bit IIS7 .net framework 2.0. I'm facing some strange issue in assembly loading.
There are set of Com callable wrapper dlls written in C# 1.1 and these dlls use a dll registered in GAC (IConfigSectionHandler implementation).
Com callable wrapper fails to load this gac dll and fusion logs says;
*** Assembly Binder Log Entry (3/30/2015 # 6:22:28 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = NT AUTHORITY\IUSR
LOG: DisplayName = Enterprise.Configuration
(Partial)
LOG: Appbase = file:///c:/windows/system32/inetsrv/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = w3wp.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\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/system32/inetsrv/Enterprise.Configuration.DLL.
LOG: Attempting download of new URL file:///c:/windows/system32/inetsrv/Enterprise.Configuration/Enterprise.Configuration.DLL.
LOG: Attempting download of new URL file:///c:/windows/system32/inetsrv/Enterprise.Configuration.EXE.
LOG: Attempting download of new URL file:///c:/windows/system32/inetsrv/Enterprise.Configuration/Enterprise.Configuration.EXE.
LOG: All probing URLs attempted and failed.
If I put this dll to c:/windows/system32/inetsrv it loads in the second attempt.(If I refresh the sites on first failure)
And the Com callable wrappers also load in the second attempt and it also searches the Com callable wrappers in same manner and fails to load at first time.
Why CLR searches Com callable wrappers in c:/windows/system32/inetsrv and why GAC registered dll also searches in the same place.
Any idea

Could not load file or assembly 'Magick.NET-x64' issue on mvc application

I am using the Magick.net library in an mvc3 web application and these are steps i did
My project is targeting AnyCPU and my machine is 64bit
Add reference of Magick.NET-x64.dll to the project.
Installed Visual C++ Redistributable for Visual Studio 2012 Update 4 from here http://www.microsoft.com/en-us/download/details.aspx?id=30679
Installed Ghostscript 9.14 for Windows (64 bit) on machine
Added
<add assembly="Magick.NET-x64, Version=7.0.0.0002, Culture=neutral, PublicKeyToken=2004825badfa91ec" />
on web.config file
Project is rebuilded successfully [and all dlls are in bin folder also], but while running i am getting the exceptions
Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information > about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was > made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the > exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Magick.NET-x64' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Magick.NET-x64
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Magick.NET-x64 | Domain ID: 6
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:/Fagbokforlaget/SourceCodes/fbf_internal/picsilo/Source/ImageTagger/
LOG: Initial PrivatePath = C:\Fagbokforlaget\SourceCodes\fbf_internal\picsilo\Source\ImageTagger\bin
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Fagbokforlaget\SourceCodes\fbf_internal\picsilo\Source\ImageTagger\web.config
LOG: Using host configuration file:
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:/Users/jibinmathew/AppData/Local/Temp/Temporary ASP.NET Files/root/a5b5e44f/dc1c4c69/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Users/jibinmathew/AppData/Local/Temp/Temporary ASP.NET Files/root/a5b5e44f/dc1c4c69/Magick.NET-x64/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Fagbokforlaget/SourceCodes/fbf_internal/picsilo/Source/ImageTagger/bin/Magick.NET-x64.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
A revision to the blog post sited by #dlemstra has the easiest solution I've found for this:
In VS2013/2015, go to Tools --> Options --> Projects and Solutions --> Web Projects and select "Use the 64 bit version of IIS Express for web sites and projects."
There seems to be a problem when running the 64 bit version of Magick.NET in Visual Studio 2013's IIS Express. You need to set a registry key according to the following answer 'High quality JPEG compression with c#'. You could set this flag or switch to the AnyCPU version of Magick.NET.
Make sure redistributable C++ package is also installed.
https://magick.codeplex.com/documentation
Make sure you have installed Visual C++ Redistributable for Visual
Studio
.NET 4.0: Visual C++ Redistributable for Visual Studio 2015 (x64 or x86)
.NET 2.0: Visual C++ Redistributable for Visual Studio 2008 (x64 or x86).

Run time error - after settting enabled 32 bit application to false IIS

I had a old application running in asp which was migrated to .net recently and was deployed on Windows 2008 server but it was still being run in 32 bits due to some dll (old MSXML dll was being used) dependency.
The dependency was removed and it was rebuild on 2012 VS. When I deploy and change the app pool setting to disable 32 bit application flag (under advanced settings), it gives me following error.
However if i change the flag to true the application starts working again.
Can anyone suggest some solution please?
---------------------------------------------------------------------------------------
Could not load file or assembly 'System.Web' or one of its dependencies. An attempt was made to load a program with an incorrect format.
---------------------------------------------------------------------------------------
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\*******\******\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\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/Framework64/v2.0.50727/Temporary ASP.NET Files/root/70aa83e0/80464c61/System.Web.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/root/70aa83e0/80464c61/System.Web/System.Web.DLL.
LOG: Attempting download of new URL file:///D:/Websites/XML_NET/bin/System.Web.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Categories

Resources