Third party dependency not loaded for class library I created and being referenced by a WPF project

16 views Asked by At

I have a class library that has dependencies to a lot of packages from NuGet. Examples include Microsoft.Identity.Client, System.Diagnostics.DiagnosticSource, and System.Text.Json. I reference this class library from a WPF Project in a separate solution, create an object from the class library, and then call a method on that object. In the WPF project I get an exception when creating the object from my class library saying that it could not load file or assembly. Even weirder, it says it could not load the file or assembly and lists a lower version than what is referenced in the class library. I am not sure what is going on here.

My understanding was that the class library having referenced everything it needs to operate that it would be sufficient for other projects to reference the dll from that project. If the project is called ATestProject then a dll with the name ATestProject.dll would be created and that would be referenced by other projects. Then when you use the classes and methods in the project that references ATestProject.dll then it would resolve the dependencies it needs and call them as it needs.

When I reference the ATestProject in another solution/project then I am constantly having some issues with either some missing reference dll or just some other version of the dll being shown in the exception message. For example this exception message being shown:

System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

when the project targets version 4.3.4.

The projects are like so. There is a project A in solution A that has a unit test project A. Project A has a few Nuget packages that it depends on. Some of those are: System.Net.Http, Microsoft.Identity, and System.Text.Json. Then I have a project B in solution B. Project B references the dll in the bin directory of project A which is created when you build project A. In the bin folder for project A we will find all the other dlls it depends on as well, including the previously mentioned dlls. In project B we create an object from a class in project A. In the constructor of that class is a call to the previously mentioned Microsoft.Identity dll. Then it complains that the dll is either missing or a wrong version. I can fix it by installing Microsoft.Identity in project B with Nuget but I do not want to have to do that for every project that references project A and I believe it should not be neccessary. Next it complains that it cannot load the file or assembly System.Net.Http with version 4.1.1.3 when project A uses version 4.3.4 of System.Net.Http.

Can someone explain what is going on here or how I can identify what is going on?

0

There are 0 answers