“无法加载文件或程序集或其依赖项之一。尝试加载格式不正确的程序。”

问题描述 投票:0回答:6

在VS中调试时,在VS中启动调试时会引发错误。

错误如下:

Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[BadImageFormatException: Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +232
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +51
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337

[HttpException (0x80004005): Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8921851
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

当我创建使用“p4dn.dll”的 C# 项目时,不会出现此错误。

这是我的第一个 ASP 项目,我还阅读了类似的问题,例如“http://stackoverflow.com/questions/41449/i-get-a-an-attempt-was-made-to-load-a-program- with-an-in Correct-format-error-o”和“http://stackoverflow.com/questions/1648213/could-not-load-file-or- assembly-xxx-or-one-of-its-dependency-一次尝试是”。他们无法解决我的问题。

我该如何解决这个问题?

asp.net
6个回答
55
投票

现在有一个菜单选项可以运行 64 位版本的 IIS Express。 从 Visual Studio 菜单中选择工具 -> 选项... -> 项目和解决方案 -> Web 项目

单击“对网站和项目使用 64 位版本的 IIS Express”按钮


23
投票

转到相应的 ==> 站点应用程序池,

点击==>高级设置

     Change value of ==> "Enable 32-Bit Applications" from  False to True 

5
投票

我在尝试使用 IIS Express 8.0 运行(调试)64 位 MVC 站点时遇到了同样的错误消息。 我验证了我的所有项目都针对 x64 平台。

出现此问题的原因是 Visual Studio 运行 32 位版本的 IIS Express。 我让它工作的唯一方法是通过手动执行以下命令来运行 64 位 IIS Express。

"C:\Program Files\IIS Express\iisexpress.exe"  /config:"U:\IISExpress\config\applicationhost.config"  /site:"Imaging.Web" /apppool:"Clr4IntegratedAppPool"

然后在 Visual Studio Web 项目中转到“属性”,选择“使用自定义 Web 服务器”,然后输入站点的 url。

为了调试,请转到“调试”>“附加到进程..”,然后选择正在运行的 IIS Express 实例。

Visual Studio 团队确实应该在项目属性中将此作为一个选项。


2
投票

-为您的网站创建一个新的 IIS 池 -为此池启用 32 位


1
投票

使用 C# 在 Asp.Net 上进行本地化项目

项目在本地计算机上运行良好。在 IIS 和 Web 服务器上上传后,它不起作用,并且无法加载文件或程序集“App_global.asax”或其依赖项之一。该程序集是由比当前加载的运行时更新的运行时构建的,无法加载。即将到来。

enter image description here

在IIS上将应用程序池从v2.0更改为V4.0后,错误得到解决。


0
投票
另一件事是要查找项目属性中的多个引用路径: 右键单击项目->属性->引用选项卡 右上角有参考路径 - 单击它。 就我而言,这里有两个相同库的参考路径 - 删除重复项。

© www.soinside.com 2019 - 2024. All rights reserved.