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

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

问题描述:

在VS中调试时,在VS中启动调试时将引发错误.

错误如下:

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



当我创建一个使用``p4dn.dll''的C#项目时,不会遇到此错误.

这是我的第一个ASP项目,我也阅读了类似的问题,例如"http://*.com/questions/41449/i-get-a-an-attempt-was-made-to-load-a-program-with -an-incorrect-format-error-o"和"http://*.com/questions/1648213/could-not-load-file-or-assembly-xxx-or-one-of-its-dependencies-an -attatt-was".他们无法解决我的问题.

我该如何解决这个问题?

感谢



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://*.com/questions/41449/i-get-a-an-attempt-was-made-to-load-a-program-with-an-incorrect-format-error-o" and "http://*.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?

thanks

最可能的原因是p4dn.dll不是托管程序集,因此您试图以此方式加载它.您可能需要改为通过DLLImport语句访问文件.
The most likely reason is the p4dn.dll is not a managed assembly, and you are trying to load it as such. You probably need to access the file via DLLImport statements instead.