Now, lets look into possible solutions: Solution There are two solutions: Upgrade NuGet package of Lib C in Lib A to v2 Adding binding Redirect element in config file Lets see binding redirect solution first.It is easy to resolve provided that the new assembly version is backward compatible.
Could Not Load File Or Assembly Accreatorlib.Net How To Resolve ThisBefore going into how to resolve this issue, lets understand how runtime locates the assembly. If you just want to know the solution, you can skip this section, however, I recommend to go through it once to understand why we get this exception. How Run-time locates assembly Consider the scenario wher e I am using Newtonsoft.Json in my project. ![]() Could Not Load File Or Assembly Accreatorlib.Net .Dll In BindebugWhen you build solution there can be one Newtonsoft.JSON.dll in bindebug or binrelease folder. Visual studio), run it from developers command prompt with admin privileges. Here is sample log of probing (relevant parts are made bold ): LOG: This bind starts in default load context. LOG: Using application configuration file: F:visual studio 2017ProjectsTestBindingAppTestBindingAppbinDebug TestBindingApp.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319config machine.config. LOG: Post-policy reference: Newtonsoft.Json, Version10.0.0.0, Cultureneutral, PublicKeyToken30ad4fe6b2a6aeed LOG: GAC Lookup was unsuccessful. Could Not Load File Or Assembly Accreatorlib.Net Download Of NewLOG: Attempting download of new URL file:F:visual studio 2017ProjectsTestBindingAppTestBindingAppbinDebugNewtonsoft.Json.DLL. LOG: Assembly download was successful. Attempting setup of file: F:visual studio 2017ProjectsTestBindingAppTestBindingAppbinDebugNewtonsoft.Json.dll LOG: Entering run-from-source setup phase. LOG: Assembly Name is: Newtonsoft.Json, Version11.0.0.0, Cultureneutral, PublicKeyToken30ad4fe6b2a6aeed WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: The assembly reference did not match the assembly definition found. Probing terminated This log gives insights into how assembly is located. More details are available at Microsoft Docs How runtime locates the assembly. Below is summary: Determine the correct assembly version: appweb config, publisher policy and machine.config are examined for this. Cached Assembly: Check the same assembly bound before then use it, if it failed then current request is failed immediately without any further steps. GAC: Assembly is checked in Global Assembly Cache, it must be strongly named. ![]() The Application base is location from executable is run Then coming to question why error of assembly cannot be loaded It is failing in one of the above steps. More often the first step the assembly is not found matching the version. Consider the scenario: Lib A references Lib C v1 Lib B references Lib C v2 Lib A references Lib B Then after building the project there would be one version of Lib C in Application base so Lib A cant find other version. Can you guess which version of Lib C would be present in Application base It is Lib C v1. The reason is dependency resolver follows 4 rules Lowest applicable version (e.g. Version 2.2 for 2.2 and if 2.2 is not available and 2.3 is next then 2.3) Wildcard (e.g. Nearest wins (as in this scenario Lib C v1 directly referenced by Lib A. Thus, this rule can result in a downgrade of the package version) Cousin dependency (lowest maximum version that satisfies all requirements. This is case when different package versions are referred to at the same distance in the graph from the application). We understood which version the application gets and how runtime probes it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |