我正在构建一个只能使用64位的Web应用程序(
当我在
我已经尝试将
我已经使用此问题:如何确定.NET程序集是为x86还是x64构建的? 确认所有引用的程序集都是
我已经使用启用了
[BadImageFormatException]: 无法加载文件或程序集'AssemblyB'或其某个依赖项。尝试加载格式不正确的程序。
在System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro spection, Boolean suppressSecurityChecks)中:
在System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String code Base, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& s tackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntros pection, Boolean suppressSecurityChecks)中:
在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark &stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)中:
在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark &stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)中:
在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark &stackMark, Boolean forIntrospection)中:
在System.Reflection.Assembly.Load(String assemblyString)中:
在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)中:
[ConfigurationErrorsException]: 无法加载文件或程序集'AssemblyB'或其某个依赖项。尝试加载格式不正确的程序。
在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)中:
在System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomain BinDirectory()中:
在System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)中:
在System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)中:
在System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()中:
在System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStar tInitListPath, Boolean& isRefAssemblyLoaded)中:
在System.Web.Compilation.BuildManager.ExecutePreAppStart()中:
在System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, Host ingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)中:
我已经查看了相关的问题,但都没有回答这个问题。大多数与IIS配置有关,但这是编译错误,或者解决方案是将项目设置为允许32位平台目标,这对我的情况不适用。
AssemblyA
),并引用另一个我构建的也只能使用64位的应用程序(AssemblyB
)。当我在
AssemblyA
中添加AssemblyB
作为引用时,在Visual Studio中会出现以下编译错误:
我的两个应用程序的平台目标设置都设置为ASPNETCOMPILER无法加载文件或程序集“AssemblyB”或其某个依赖项。尝试加载格式不正确的程序。
x64
,目标框架设置都是.Net Framework 4.6
,且Prefer 32bit
未选中。我已经尝试将
AssemblyB
的每个依赖引用都引用到AssemblyA
中,并确保所有依赖引用的版本都相同。我已经使用此问题:如何确定.NET程序集是为x86还是x64构建的? 确认所有引用的程序集都是
MSIL
或AMD64
。我已经使用启用了
errorstack
选项的aspnet_compiler.exe
命令行工具,并获得了以下堆栈跟踪:[BadImageFormatException]: 无法加载文件或程序集'AssemblyB'或其某个依赖项。尝试加载格式不正确的程序。
在System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro spection, Boolean suppressSecurityChecks)中:
在System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String code Base, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& s tackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntros pection, Boolean suppressSecurityChecks)中:
在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark &stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)中:
在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark &stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)中:
在System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark &stackMark, Boolean forIntrospection)中:
在System.Reflection.Assembly.Load(String assemblyString)中:
在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)中:
[ConfigurationErrorsException]: 无法加载文件或程序集'AssemblyB'或其某个依赖项。尝试加载格式不正确的程序。
在System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)中:
在System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomain BinDirectory()中:
在System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)中:
在System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)中:
在System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()中:
在System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStar tInitListPath, Boolean& isRefAssemblyLoaded)中:
在System.Web.Compilation.BuildManager.ExecutePreAppStart()中:
在System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, Host ingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)中:
我已经查看了相关的问题,但都没有回答这个问题。大多数与IIS配置有关,但这是编译错误,或者解决方案是将项目设置为允许32位平台目标,这对我的情况不适用。
- 即使平台相同,“尝试加载格式不正确的程序” (使用IIS配置无效)
- 无法加载文件或程序集...“尝试加载格式不正确的程序”(System.BadImageFormatException)(是运行时错误,无效)
- System.BadImageFormatException “尝试加载格式不正确的程序”(使用32位解决方案,无效)
- 无法加载文件或程序集'xxx'或其某个依赖项。“尝试加载格式不正确的程序”(使用32位解决方案,无效)
我不知道该怎么办。再次强调,我不想将我的任何项目设置为32位,并且这不是IIS配置问题,因为这是编译错误。
我还在几台不同的机器上和全新的应用程序上尝试了它,但结果相同。
我该如何解决这个编译错误?