不应加载引用程序集以执行

Pra*_*tap 10 asp.net-mvc visual-studio

当我尝试在Visual Studio中调试它时,我的网站突然抛出此错误消息.如果我部署网站,它的工作没有任何错误.

任何解决此错误的建议.

[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

All*_*ool 18

尝试从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>
Run Code Online (Sandbox Code Playgroud)

  • @AllmanTool非常感谢,您救了我的日子。您能否解释为什么我们需要删除此部分? (2认同)

Cas*_*303 12

删除\bin\obj目录,重建您的项目。


Out*_*ill 5

我遇到了这个问题,但System.Runtime在错误消息中指定:

[BadImageFormatException:无法加载文件或程序集“System.Runtime”或其依赖项之一。不应加载参考程序集来执行。它们只能在仅反射加载器上下文中加载。(HRESULT 异常:0x80131058)]

我发现彻底清理解决方案并重建可以解决这个问题。仅仅进行 Visual Studio Clean 是不够的。\bin实际上我还必须删除我的文件夹。