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

时间:2016-10-23 19:49:24

标签: 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

7 个答案:

答案 0 :(得分:15)

尝试从web.config中删除该部分

public class Test
{
    public static void main(String[] args) {
        String s ="<table border=\"0\" align=\"center\" cellpadding=\"0\" style=\"width:101%;\" class=\"maintable\" id=\"table5\">\n" +
                "        <tbody><tr class=\"parent\" title=\"Please Click Here To View The Content\">\n" +
                "        <td colspan=\"4\" class=\"MTTD1\" align=\"center\"><b><u>Personal Details</u></b></td>";
        Document doc = Jsoup.parse(s);
        Element elements = doc.select("table").first();
        for (Element element :elements.select("tr")){
            System.out.println(element.text());
        }
}

答案 1 :(得分:1)

删除\bin目录,重新生成项目。

答案 2 :(得分:0)

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

[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)]

我发现彻底清洁解决方案并进行重建可以为我解决此问题。仅执行Visual Studio Clean还不够。实际上,我也必须删除\bin文件夹。

答案 3 :(得分:0)

如果您正在使用.NET Core,并且具有以下功能:

using System.Data.SqlClient;

然后,将其切换为一个可能的解决方案:

using Microsoft.Data.SqlClient;

答案 4 :(得分:0)

我注意到我的dll只有1.0,错误框说4.0

我回到 NuGet 包管理器并放入 System.Management.dll 4.0 —

不走运,然后我就回去单独放入 System.Management.dll(我记得),它提出了一个 5.0。不太确定我是如何促使它这样做的,但它似乎很愿意。

安装成功!

答案 5 :(得分:0)

当我从“[build folder]\ref”文件夹附加我的 DLL 时,也会发生同样的错误。

它应该从 [build 文件夹] 中引用。 (Net5)

答案 6 :(得分:-1)

我已经从本地删除了现有代码,并再次克隆了该代码。后记开始为我工作。