0
votes

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.
2
Which version of c# do you use? How do you add a reference(NuGet or path to a DLL)? Do you use a package.config or packageReferences? Could you please provide a name and version of this library?Basil Kosovan
It’s not in NuGet, just a path to the DLL, LicenseSpring.dll. Using VS2019 by adding it as a reference.PigsIncorporated
Which DLLs couldn't be found? Some custom DLLs?Basil Kosovan
Well I’m not sure. Since it says file or dependency. It’s either 3rd party LicenseSpring dll or a dependencyPigsIncorporated
There is a build output. And there should be a name of DLL which couldn't be found. Or even an error should contain the name of DLL, which couldn't be foundBasil Kosovan

2 Answers

0
votes

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:

  1. When you are adding a library from disk - you need to add all dependencies as well.
  2. You can add your assemblies to GAC - but this will be more complicated
0
votes

If you cannot find out, what Assembly the system is missing at runtime, you can enable FUSLOG (https://docs.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.