无法加载参考组件进行执行



突然间,我的网站没有加载,给我以下错误。我正在Windows 10 Home上使用.NET Framework 4.7.1运行VS2017。

[BadImageFormatException: Cannot load a reference assembly for execution.]
[BadImageFormatException: Could not load file or assembly 'System.IO.Compression.ZipFile' 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.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 'System.IO.Compression.ZipFile' 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) +729
   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) +321
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734
[HttpException (0x80004005): Could not load file or assembly 'System.IO.Compression.ZipFile' 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) +525
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +118
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +708

有什么建议?

对我有用的是在我的Web应用下删除bin和obj目录,然后重建。

在这方面存在.NET Framework 4.7.1的已知问题。据说在4.7.2中排序,但与此同时,您该怎么办?

该问题与序列化组件有关,您可以选择将其设置为生成或不作为构建的一部分(rclick project-> properties-> build tab-> ward of tocare of tocare''。P>

对我有用的东西 - 我站在这里的其他人肩上 - 是为了确保将此设置设置为"自动"。做一个完整的"干净解决方案",此外,如果在解决方案的根文件夹中运行,则此PowerShell片段很方便:

Get-ChildItem . -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

接下来,将以下目标添加到您的CSPROJ(仅在封闭的<Project>标签中:

<Target Name="RemoveDesignTimeFacadesBeforeSGen" BeforeTargets="GenerateSerializationAssemblies">
    <ItemGroup>
      <ReferencePath Remove="@(_DesignTimeFacadeAssemblies_Names->'%(OriginalIdentity)')" />
    </ItemGroup>
    <Message Importance="normal" Text="Removing DesignTimeFacades from ReferencePath before running SGen." />
  </Target>
  <Target Name="ReAddDesignTimeFacadesBeforeSGen" AfterTargets="GenerateSerializationAssemblies">
    <ItemGroup>
      <ReferencePath Include="@(_DesignTimeFacadeAssemblies_Names->'%(OriginalIdentity)')" />
    </ItemGroup>
    <Message Importance="normal" Text="Adding back DesignTimeFacades from ReferencePath now that SGen has run." />
  </Target>

如果仍然没有运气,则明确将"生成序列化组件"设置为" on",以强迫生成,然后重建&amp;运行。

今天我已经安装了Acumatica 2018 R1,并且遇到了这个问题。emoving system.io.compression.pression.zipfile从bin文件夹解决了问题。

我也多次遇到此问题,此错误可能会通过在您的bin文件夹中的引用或加载问题引起。只需删除.bin文件夹并重建您的应用程序即可。

快乐的编码。

我对错误有一些研究

从错误中可以看到,当我们参考ASPNETCORE项目中的基于肥皂的项目时,我们不能直接使用它们。这是由于实现了平台AspnetCore。

可以使用反射加载。但是,它允许我们动态使用内部类型。支持可以在以后的Aspnetcore版本中发布,用于许可肥皂组件等。

删除bin文件夹等是当DLL版本不同的x86或64等。真正的问题是SOAP协议,WebSocket,代理等实现。它们不能直接与Aspnetcore项目一起使用。在GitHub中有补丁项目

我在从4.6.2升级到4.8时遇到了这个问题。

修复:

  1. 从web.config删除汇编重定向
  2. 重建项目
  3. 双击组件绑定在VS中的绑定警告,以重新生成必要的重定向
  4. 没有警告的重建

我删除了启动项目的bin和obj文件夹。然后重建解决方案。它起作用。

在所有删除NBIN文件夹/OBJ文件夹/清洁/重建之后:无效。错误清楚地告诉您有关问题的组件。转到您的web.config文件并找到该组件。删除并重新引用

我从.NET Framework 4.6.2到4.8迁移后遇到了相同的问题,并且推荐的修复程序都不适合我,直到我将项目更新为最新的.NET Framework 4.8.1。我继续删除bin文件夹,然后开始再次工作

最新更新