23

while debugging in VS, the error will be raised when starting debug in VS.

The error is below:

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

When i create a C# project which use 'p4dn.dll' there isn't this error coming across.

this is my first ASP project, i also read the similar questions like "http://stackoverflow.com/questions/41449/i-get-a-an-attempt-was-made-to-load-a-program-with-an-incorrect-format-error-o" and "http://stackoverflow.com/questions/1648213/could-not-load-file-or-assembly-xxx-or-one-of-its-dependencies-an-attempt-was". They cannot address my problem.

how can I solve this problem?

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Lei Zhang
  • 331
  • 1
  • 2
  • 3

5 Answers5

54

There is now a menu option to run the 64bit version of IIS Express. From Visual Studio menu select Tools -> Options... -> Projects and Solutions -> Web Projects

Click the button for "Use the 64 bit version of IIS Express for web sites and projects"

JBrooks
  • 9,901
  • 2
  • 28
  • 32
23

Go to Respective ==> Site Application Pool ,

Click on ==> Advance Settings

     Change value of ==> "Enable 32-Bit Applications" from  False to True 
BJ Patel
  • 6,148
  • 11
  • 47
  • 81
  • This has always been the right answer for me when I hit this issue. – Dylan Hayes Jun 11 '15 at 15:07
  • 2
    hah, i just had this issue again, once again solved it, came back to the same post and tried to upvote it again, and then saw my old comment, ahhh memories :). – Dylan Hayes Oct 19 '16 at 13:53
  • :) Yes it Right, It happen a lot , we come again to same issue and we search around and come to it. and say hah.. ya I remember. !! :) – BJ Patel Oct 19 '16 at 18:25
  • ?? What option is "Respective"? I am using VS2017 Community – Fandango68 May 21 '18 at 05:28
  • 1
    So annoying! Would never have guessed this... @Fandango68 You've probably worked this out by now, but this is within Internet Information Services (IIS) not Visual Studio. "Respective" refers to the Web Application within the IIS structure. – Craig Mar 02 '21 at 09:42
  • I actually wanted to run in 64bit, so I set it to false! – Christian Oct 22 '21 at 07:01
5

I had this same error message trying to run (debug) a 64-bit MVC site using IIS Express 8.0. I verified that all my projects were targetting the x64 Platform.

The problem was occurring because Visual Studio runs the 32-bit version of IIS Express. The only way I could get it to work was to run the 64-bit IIS Express by executing the following command manually.

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

Then in your Visual Studio web project go to Properties, select "Use Custom Web Server", and enter the url to your site.

In order to Debug, go to debug > Attach to Process.. and then select your running IIS Express instance.

The Visual Studio team really should make this an option in the Project Properties.

Andrew Brown
  • 176
  • 3
  • 8
2

-create a new IIS pool for your web site -Enable 32bit for this pool

Wolf
  • 6,361
  • 2
  • 28
  • 25
1

Localization project on Asp.Net with C#

Project was working fine on Local Machine. After uploading on IIS and Web Server, it did not worked and Could not load file or assembly 'App_global.asax' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. was coming.

enter image description here

After changing Application Pool to V4.0 from v2.0 on IIS, the error got resolved.