突然间,我的网站没有加载并给我以下错误。我在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
有什么建议吗?
答案 0 :(得分:29)
对我有用的是删除我的网络应用程序下的bin和obj目录,然后重建。
答案 1 :(得分:5)
这里的派对有点晚了,但是there's a known issue with .NET Framework 4.7.1 in this regard。据说按4.7.2排序,但与此同时你能做什么?
该问题与序列化程序集有关,您可以选择将其设置为生成或不作为构建的一部分(rclick项目 - >属性 - >构建选项卡 - >请参阅底部的'生成序列化程序集'。 )
对我有用的 - 我站在其他部分的肩膀上 - 是为了确保此设置设置为'自动'。做一个完整的“干净解决方案”,另外如果偏执,这个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>
如果仍然没有运气,请明确将“生成序列化程序集”设置为“打开”以强制生成,并重建&amp;运行
答案 2 :(得分:4)
今天我安装了Acumatica 2018 R1,我遇到过这个问题。从bin文件夹中删除System.IO.Compression.ZipFile修复了问题。
答案 3 :(得分:1)
我也多次遇到此问题,此错误可能是由于在bin文件夹中引用或加载dll引起的。只需删除.bin文件夹并重建您的应用程序即可。
快乐的编码。
答案 4 :(得分:0)
除了创建新实例并迁移所有自定义外,没有解决方案。这些错误只是随机的,很难追查或解决。
答案 5 :(得分:0)
我对此错误进行了研究
从错误中我们可以看到,当我们在Aspnetcore项目中引用基于SOAP的项目时,我们不能直接使用它们。这是由于平台Aspnetcore的实现。
可以使用reflection加载它。但是,它允许我们动态使用内部类型。可能会在Aspnetcore的更高版本中释放对licenced肥皂装配等的支持。
当dll版本不同于X86或64等时,删除bin文件夹等是一个解决方案。真正的问题是SOAP协议,WebSocket,Proxy等实现。它们不能直接与Aspnetcore项目一起使用。 github中有patch个项目为此