Reference assemblies should not be loaded for execution

22

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
asp.net-mvc
visual-studio
asked on Stack Overflow Oct 23, 2016 by Prashan Pratap

5 Answers

27

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>
answered on Stack Overflow Mar 24, 2017 by AllmanTool
4

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;
answered on Stack Overflow Jul 11, 2019 by Jim
3

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.

answered on Stack Overflow Nov 20, 2018 by OutstandingBill
2

Delete the \bin directory, Rebuild your project.

answered on Stack Overflow Sep 21, 2020 by Case 303
-4

i have deleted existing code based from local and again cloned the code. afterword its started working for me.

answered on Stack Overflow Dec 20, 2019 by Dhiraj

User contributions licensed under CC BY-SA 3.0