Ste*_*eve 5 .net c# compiler-errors compilation badimageformatexception
我正在构建一个仅64位的Web应用程序(AssemblyA)并引用我已经构建的另一个应用程序,它也是64位(AssemblyB).
当我添加AssemblyB作为引用时AssemblyA,我在Visual Studio中得到以下编译错误:
ASPNETCOMPILER无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.
我的应用程序的平台目标设置都设置为x64,两个Target Framework设置都是.Net Framework 4.6和Prefer 32bit is unchecked.
我尝试引用AssemblyBin的每个依赖引用AssemblyA,确保所有依赖引用的版本相同.
我使用过这个问题:如何确定.NET程序集是为x86还是x64构建的?确认所有引用的程序集是MSIL或AMD64.
我使用了aspnet_compiler.exe命令行工具并errorstack启用了选项,并获得了以下堆栈跟踪:
[BadImageFormatException]:无法加载文件或程序集"AssemblyB"或其依赖项之一.尝试加载格式不正确的程序.
at 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文件名,字符串的代码库,证据assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&S tackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntros pection,布尔suppressSecurityChecks)
在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔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位平台目标,这不适合我的情况:
我不知道从哪里开始.要重申的是,我不希望任何设置我的项目中,以32位和因为这是一个编译错误,这不是与IIS配置的问题.
我也在几台不同的机器和全新的应用程序上尝试了相同的结果.
如何修复此编译错误?
该指令采用一个可以定向到 64 位版本的<AspNetCompiler />参数。这篇博文对此进行了描述。其要点是,编辑您的 csproj 文件:ToolPathaspnet_compiler.exe
ToolPath向节点添加属性AspNetCompiler:
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" ToolPath="$(AspNetToolPath)" />
Run Code Online (Sandbox Code Playgroud)
在定义的位置MvcBuildViews,添加属性FrameworkVersion和AspNetToolPath,如下所示:
<MvcBuildViews>true</MvcBuildViews>
<FrameworkVersion>v4.0.30319</FrameworkVersion>
<AspNetToolPath Condition=" '$(Platform)' == 'x64'">$(windir)\Microsoft.NET\Framework64\$(FrameworkVersion)</AspNetToolPath>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
647 次 |
| 最近记录: |