Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference assemblies should not be loaded for execution

All of a sudden my website is throwing this error message when I try to debug it within Visual Studio. If I deploy the website, it works without any errors.

Any suggestions to resolve this error.

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.Win32.Primitives' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.Win32.Primitives' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9946132
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
like image 846
Prashan Pratap Avatar asked Oct 23 '16 19:10

Prashan Pratap


People also ask

What is a reference assembly?

Reference assemblies are a special type of assembly that contain only the minimum amount of metadata required to represent the library's public API surface.

How do I fix missing assembly reference in Visual Studio?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.

What is assembly reference in asp net?

NET-based applications. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (. dll) files, and are the building blocks of . NET applications.


4 Answers

Try delete that section from your web.config

<dependentAssembly>
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
  </dependentAssembly>
like image 184
AllmanTool Avatar answered Oct 15 '22 19:10

AllmanTool


I had this problem, but with System.Runtime specified in the error message:

[BadImageFormatException: Could not load file or assembly &#39;System.Runtime&#39; or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)]

I found that thoroughly cleaning the solution and rebuilding fixed this problem for me. And just doing a Visual Studio Clean wasn't enough. I actually had to delete my \bin folders as well.

like image 40
OutstandingBill Avatar answered Oct 15 '22 18:10

OutstandingBill


Delete the \bin directory, Rebuild your project.

like image 26
Case 303 Avatar answered Oct 15 '22 19:10

Case 303


If you are working with .NET Core, and have this:

using System.Data.SqlClient;

Then, switching it to this is a potential solution:

using Microsoft.Data.SqlClient;
like image 28
Jim Avatar answered Oct 15 '22 18:10

Jim