0

I am trying to start an iis site (asp.net mvc) which has worked perfectly before my changes. I have referenced some nuget-packages (nothing special, but some of them reference netstandard) and have done some minor code changes. Now I am getting the error Could not load file or assembly 'Merged' or one of its dependencies with this stacktrace while trying to connect to the site:

[FileLoadException: Could not load file or assembly 'Merged' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +225
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Merged' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +725
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +247
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +157
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +226
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +73
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +319
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +820

[HttpException (0x80004005): Could not load file or assembly 'Merged' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +523
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +688

I also provide assembly binding logs:

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 = Merged
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Merged | Domain ID: 3
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:///C:/Proj/Test/FmsFront/
LOG: Initial PrivatePath = C:\Proj\Test\FmsFront\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Proj\Test\ProjFront\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/root/fcbbd808/fa43678c/Merged.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/fcbbd808/fa43678c/Merged/Merged.DLL.
LOG: Attempting download of new URL file:///C:/Proj/Test/ProjFront/bin/Merged.DLL.
WRN: Comparing the assembly name resulted in the mismatch: NAME
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

I have looked around trying to find the dll with the name "Merged". But it seems to be partial assembly name. Also it looks like this error is thrown before my actual code starts. I tried restoring packages. Also it works fine on local machine, but on the other server it fails.

How can I fix this error?

DenisFomin
  • 35
  • 6
  • Try restoring the Nuget packages – JamesS Feb 18 '20 at 10:20
  • I tried it already. – DenisFomin Feb 18 '20 at 10:40
  • plaese see this link :https://stackoverflow.com/questions/215026/the-located-assemblys-manifest-definition-does-not-match-the-assembly-reference – AminGolmahalle Feb 18 '20 at 10:47
  • This has been happening for me when I do larger refactoring and moving projects to .net Standard. Delete bin and obj folders. Clear nuget package cache in options->NuGet package manger and run Update-Package -reinstall from nuget comman line. – Archlight Feb 18 '20 at 10:50
  • @AminGolmahalle, in my case there is no reference to Merged assembly in my project. Also the stacktrace looks like the exception was thrown from iis execution context, before my actual code executes. but thnx anyway. – DenisFomin Feb 18 '20 at 11:11
  • @Archlight, yeah, I thougt that it might be connected with some netstandard packages. I tried to delete bin and obj folders, cleared nuget via `dotnet nuget locals --clear` and rebuilt the project, but it did not fix anything though. – DenisFomin Feb 18 '20 at 12:20
  • did you run Update-Package -reinstall ? That will force nuget to get the package again if the cache is cleared. – Archlight Feb 19 '20 at 08:05

1 Answers1

0

So finally I figured it out. The problem was that one of the packages that I've installed took the netcoreapp dependency. But my application is netframework. So none of this netcoreapp library dependencies was put to the binary directory and this library could not be loaded. I found this Merged.dll in my app's binary folder and removed it. After that it works.

Now I am in contact with this package authors to find out why netcoreapp dependency was put in netframework app.

DenisFomin
  • 35
  • 6
  • also some clarification in case it would help anybody else later. The package I used was for netstandard but it has implementations for each runtime as a resource. While executing it unpack one implementation depending on runtume using. Somehow the package thought that the runtime is netcore and so that unpacks a netcore dependency. – DenisFomin Feb 21 '20 at 08:47