在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-wrong-format-error-o“和”http://stackoverflow.com/questions/1648213/could-not-load-file-or-assembly-xxx-or-one-of-its-依赖-AN-尝试,是”。他们无法解决我的问题。
我该如何解决这个问题?
答案 0 :(得分:28)
现在有一个菜单选项可以运行64位版本的IIS Express。 从Visual Studio菜单中选择工具 - >选项...... - >项目和解决方案 - >网络项目
单击“为网站和项目使用64位版本的IIS Express”按钮
答案 1 :(得分:12)
转到各处==>站点应用程序池,
点击==>高级设置
Change value of ==> "Enable 32-Bit Applications" from False to True
答案 2 :(得分: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。
要进行调试,请转到debug>附加到Process ..然后选择正在运行的IIS Express实例。
Visual Studio团队确实应该在项目属性中将其作为一个选项。
答案 3 :(得分:1)
- 为您的网站创建一个新的IIS池 - 此池的启用32位
答案 4 :(得分:1)