Does anyone have any idea what would cause the Fusion loader to simply skip over a DLL with no warning or acknowledgement?
When I attempt to do this (in C#) from a command-line application
Assembly.LoadFrom("c:\\Deploy\\bin\\WebServices.dll")
I see this:
"Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."
That DLL has a dependency on Platform.DLL, but the loading of that dependency fails so this line of code throws an exception. When I check the Fusion assembly loading message, this is what I see:
=== Pre-bind state information ===
LOG: DisplayName = Platform, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified)
...
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
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:/Project/bin/Debug/Platform.DLL.
LOG: Attempting download of new URL file:///C:/Project/bin/Debug/Platform/Platform.DLL.
LOG: Attempting download of new URL file:///C:/Project/bin/Debug/Platform.EXE.
LOG: Attempting download of new URL file:///C:/Project/bin/Debug/Platform/Platform.EXE.
LOG: Attempting download of new URL file:///c:/Deploy/bin/Platform.DLL.
LOG: Attempting download of new URL file:///c:/Deploy/bin/Platform/Platform.DLL.
LOG: Attempting download of new URL file:///c:/Deploy/bin/Platform.EXE.
LOG: Attempting download of new URL file:///c:/Deploy/bin/Platform/Platform.EXE.
The thing is, the DLL is present at c:\Deploy\bin\Platform.DLL, with proper version and no signed public key.
Things I've thought of:
1. Maybe it's really a dependency of Platform.DLL that's broken, causing this behavior? (I chased the dependency tree in Reflector but found no missing DLLs)
2. Maybe there's a release/debug mismatch, or a 64-bit vs 32-bit? but everything was built on the same machine
3. Maybe I'm misreading the logs, but shouldn't it stop when it hits a DLL that it finds? I don't see either the "successful" OR the "unsuccessful" message in this log. I just know it failed because of the exception.
PS more tech details:
Machine environment is Windows 2008 64-bit, with .NET 2.0, 3.0 & 3.5 installed.
This same application runs just fine on another machine (Vista 32-bit), with the same directory structure and DLLs, although those were built on that machine
Yep it should stop when it finds the required dll so the fifth "Attempting to download..." should have found it...
However where is the command line app being run from? If it's the Debug folder then a few things you can try are
Have the dependent dll's in the same folder
Sign the assembly and reference through a .config file in the following format
<dependentAssembly>
<assemblyIdentity name="WebServices.dll" publicKeyToken="<whatever this public key it>" />
<codeBase version="1.0.0.0" href="..\WebServices.dll" />
</dependentAssembly>
Sign them and then put the dependent assemblies in the GAC.
I might be way off but that's a few things to try.
Related
I am really stuck on this one and could use some help.
This problem started when I added an async method involving httpclient to a class library. I call the class library from a short test console application. When it gets to the async method I get an exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Originally it said Could not load System.Net.Http Version 4.1.1.2 (I had version 4.0.0.0 in the project) and I was using Framework 4.5.2. I could not find a system.net.http version 4.1.1.2 for NET Framework 4.5.2 so I first updated the class library and test projects to NFW 4.7.2 and then added a reference to the version of System.Net.Http associated with this framework (i.e. choosing it from the assemblies tab).
When I look at the properties of the dll in the class lib project (toolslib) it shows 4.2.0.0.
I added the same reference to the test project used to call it and it also now shows 4.2.0.0.
Additionally I added a redirect section to the app.config for toolslib
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
</dependentAssembly>
I put the same lines in the app.config for the test console app.
However I still get the same issue now with it saying it can't load 4.2.0.0. I set up Fusion Logs and got the following after running and getting the exception:
*** Assembly Binder Log Entry (7/9/2020 # 9:12:52 PM) ***
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\smjhu\Documents\DevProjects\IDXUtil\Test\bin\Debug\Test.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http, Version=4.2.0.0, Culture=neutral, ]PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Test.exe
Calling assembly : ToolsLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\smjhu\Documents\DevProjects\IDXUtil\Test\bin\Debug\Test.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: Redirect found in application configuration file: 4.2.0.0 redirected to 4.2.0.0.
LOG: Post-policy reference: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http.EXE.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http/System.Net.Http.EXE.
LOG: All probing URLs attempted and failed.
The only thing I can see from the logs is it appears to be attempting to look for the dll in the test/bin/debug folder.
I tried setting the dll to copy local but same result.
I then tried copying the system.net.http dll into the bin/debug folder manually but then when I hit that method I get a badimage exception saying I cannot use reference assemblies.
BTW also tried updating system.net.http with nuget with same result
If I remove the bindingredirect from the console app, the problem goes away.
Unfortunately, this does not really provide an explanation for the problem but it does at least for now resolve it.
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.
In a C# application I'm Loading 2 DLLs provided by user during runtime (not a pre-difined reference) Let it be A.dll, B.dll.
A.dll is referencing B.dll, but they are supplied separately.
When I try to access a method from A.dll, with a parameter of type that is declared in B.dll, I get an:
"Could not load file or assembly 'B, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot
find the file specified.".
error, although both DLLs were loaded. Even calling MethodInfo.GetParameters() will throw the exception.
Tried to Load both DLLs with different methods:
Assembly.Load(<Path>)
Assembly.LoadFile(<Path>)
Assembly.LoadFrom(<Path>)
I set the reference in project A to B.dll as "Copy Local = false".
Any usage of types and method from A or B which does not involve the connection described above seems to work fine.
I made sure both assembly were loaded with
AppDomain.CurrentDomain.GetAssemblies()
(they both are).
I have to presume I don't have developer access to A.dll and B.dll projects (provided by users), but for testing purpose I can try to change stuff in them as well.
Fusion log For A.dll:
*** Assembly Binder Log Entry (8/10/2019 # 11:47:04 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:\Users\<username>\AppData\Local\JetBrains\Installations\ReSharperPlatformVs15_95cb26a8\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///<project fullpath>/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\<username>\AppData\Local\Temp\u5r0nb10.kwf\k2mn3yzp.umi
LOG: AppName = AppTest
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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A.DLL.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A/A.DLL.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A.EXE.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A/A.EXE.
LOG: All probing URLs attempted and failed.
You are missing are probably missing another dependency of B.dll it.
When you try to load a dll, Windows will try to look all dependency of it (other dlls). Unfortunately, the error you see will be:
"The system can not find the specified"
All dependencies of B.dll should be also copied to the local directory.
Use Dependency Walker .NET to find the missing dependencies.
Since everything is "there" I've got another possibility. Normally, this is obscure, but it can happen.
If B.dll depends on a higher version of a dll that your main program depends on, sometimes the lower version dll you loaded can't be made to work with the higher version B wants. In that case, you get this error.
I've got a simple .NET application written in C#, which links with a C++/CLI DLL
which is itself just a thin wrapper around a C++ static library.
The app runs fine on the development machine (Windows 8), but, when the EXE and
DLL are copied over to another machine (Windows 10) it crashes immediately on
startup.
Looking in Event Viewer, I can see that the crash is due to an unhandled
exception, System.IO.FileNotFoundException, and the call-stack indicates that
the exception occurs in a function that makes a call into the DLL.
If I edit the function in the DLL to return immediately, then the crash still
occurs. Adding a try-catch block around the call also has no effect. However,
if I remove the call entirely, then the application runs.
The app runs fine on the development box, even if I move the EXE and DLL to a
different location. However, if I delete the DLL from the directory in which the
EXE is located, then exactly the same crash occurs.
This suggests that the problem is that the app cannot find the DLL when run on
the other machine.
The projects for both the application and the DLL are included in the same
Visual Studio 2015 solution, and the application is linked to the DLL via a
project reference.
The application targets .NET 4.5.2, and the other machine has .NET 4.6
installed. The only other references in the application project are to parts of
.NET, such as Microsoft.CSharp and System.Core.
How can I fix this crash?
EDIT: As suggested by #Alex K. in the comments, I tried logging bind failures with fuslogvw.exe, which garnered the following log excerpt:
*** Assembly Binder Log Entry (08/04/2016 # 14:47:02) ***
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 D:\[Path]\[App Name].exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = [DLL Name], Version=1.0.5941.28221, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///D:/[Path]/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = [App Name].exe
Calling assembly : [App Name], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///D:/[Path]/[DLL Name].DLL.
LOG: Attempting download of new URL file:///D:/[Path]/[DLL Name]/[DLL Name].DLL.
LOG: Attempting download of new URL file:///D:/[Path]/[DLL Name].EXE.
LOG: Attempting download of new URL file:///D:/[Path]/[DLL Name]/[DLL Name].EXE.
LOG: All probing URLs attempted and failed.
So it seems that the file that cannot be found is my DLL, and that .NET is
indeed looking in the correct location for the file, but for some reason it is
not finding it there.
Note that I obtained the same error log on my development machine when I attempted to run the EXE with the DLL deleted.
As discussed in the comments, I tried installing the Visual C++ 2015 Redistributable. This didn't appear to have any effect at the time. However, a couple of days later, the problem is no longer reproducible, and I can't think of anything else that would have fixed it. (The Redistributable installer didn't request a reboot, but my best guess is that one was actually required.)
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.