【发布时间】:2011-04-05 10:31:45
【问题描述】:
当我尝试在 IIS 7.0(在 Windows Server 2008 上使用 VSTS 2010 + .Net 4.0 开发)访问网站中的页面 (default.aspx) 时,我遇到了以下错误消息。有什么想法有什么问题吗?什么意思 BadImageFormatException?
顺便说一句:我正在运行 Windows Server 2008 64 位(不是 R2)并且尚未激活 Windows Server 2008,这可能是根本原因吗?
[BadImageFormatException:无法加载文件或程序集“test.foo”或其依赖项之一。尝试加载格式错误的程序。 ] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,证据 assemblySecurity,StackCrawlMark 和 stackMark,Boolean for Introspection,Boolean suppressSecurityChecks)+567 System.Reflection.RuntimeAssembly.InternalLoad(字符串 assemblyString,证据 assemblySecurity,StackCrawlMark 和 stackMark,Boolean forIntrospection)+192 System.Reflection.Assembly.Load(String assemblyString) +35 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +118 [ConfigurationErrorsException:无法加载文件或程序集“test.foo”或其依赖项之一。尝试加载格式错误的程序。 ] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11392147 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +484 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +127 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334 System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,IApplicationHost appHost,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,异常 appDomainCreationException)+1087 [HttpException(0x80004005):无法加载文件或程序集“test.foo”或其依赖项之一。尝试加载格式错误的程序。 ] System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文)+11524352 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext 上下文)+4782309【问题讨论】:
-
我认为您的程序集名称缺少“.dll”。请提供代码sn-p。
-
64 位/32 位不匹配?您是否为特定平台编译了程序集?
-
@George2:它确实不在您的代码中,程序集加载器引发了此异常(您可以拥有自己的程序集加载器,但这里似乎并非如此)。关于 32/64 不匹配:在 64 位上运行时指定 32 位(为什么请参阅我的答案)。
-
@George2 - 通常你不应该指定平台类型。您应该使用“任何 CPU”,并让主机\框架在运行时选择平台。当前选择的平台类型显示在 VS 菜单栏中的一个框中。如果没有显示,可以从tools->Customize->commands->Add command->Build->Solution Platforms添加
-
PS:升级到R2可能是件好事。微软已经修复了大量的问题,其中不少是与 .NET 相关的。因此,如果上述修复没有帮助或不适用,请确保将所有内容升级到最新版本 (!)。
标签: c# asp.net .net visual-studio-2010 iis