Question

Hi I know this has been asked but it did not get an answer. I have a problem when I want to use a dll that is installed on C:\Program files (x86)\Dummu_API.dll

When I run my app it throws exception:

Could not load file or assembly 'Dummy_API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

My project have the reference as Copy Local = false and specific version = false. My project also is a x86 platform target.

I don´t know why my app don't find the assembly. Any Idea what it is happening?

Was it helpful?

Solution

Option 1

You can tell your application that you will resolve the Assemblies yourselves if not found in references. To do that:

In your applications main method attach assembly resolver:

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

Make sure you are not using the dynamically resolved assembly in your main method.

Your resolver method code (This is where you load an assembly - look at ResolveEventArgs I have just hard coded one but you can resolve various assemblies from different locations here)

static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    return Assembly.LoadFile(@"C:\temp\ClassLibrary1.dll");
}

Option 2

Add this to your app.config (Only works for application base directory's sub folders)

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <probing privatePath="PathToMyAssemblies\" />
  </assemblyBinding>
</runtime>

OTHER TIPS

So the file is not in the GAC, and there is not a local copy. You've eliminated the only two places it could be loading from - I don't know why you are expecting this to work.

You need to set Copy Local=true or install Dummy_API.dll into the Global Assembly Cache on the machine that will be running your code. One or the other.

I don`t know if you chose the right project type, as for me, I found me selecting the dot net core type(console app) project at the very beginning, then I shifted the project to dot net framework(console app), and it works for me.

There`s another quick way to check if you have the same issue as I do:

  1. After you create item app.config and compiled it, you found .dll.config but not .exe.config
  2. Reference tab replaced by dependencys tab
  3. Project property framework selection can only be core x.x or net 5.0 but not framework 3.0/4.0/4.5 etc.

Just a hint or tip, hope helped!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top