C# 无法加载文件或程序集HttpException(0x80004005)

C# 无法加载文件或程序集HttpException(0x80004005),c#,dll,C#,Dll,可能重复: 我正在尝试编译我的解决方案,但收到一个关于dll的错误。我已将该dll复制到另一个解决方案的bin文件夹中,但它没有编译它(第二个解决方案与该dll无关,它没有使用它) 我收到的错误是以下错误: Server Error in '/browsertest1' Application. Could not load file or assembly 'KT.AF.Engine.Core' or one of its dependencies. An attempt was made

可能重复:

我正在尝试编译我的解决方案,但收到一个关于dll的错误。我已将该dll复制到另一个解决方案的bin文件夹中,但它没有编译它(第二个解决方案与该dll无关,它没有使用它)

我收到的错误是以下错误:

Server Error in '/browsertest1' Application.

Could not load file or assembly 'KT.AF.Engine.Core' or one of its dependencies. An attempt was made to load a program with an incorrect format.
描述:
在执行当前web请求期间发生未处理的异常。请查看堆栈跟踪,以了解有关错误的更多信息以及错误源于代码的位置。

异常详细信息:
System.BadImageFormatException:无法加载文件或程序集“KT.AF.Engine.Core”或其依赖项之一。试图加载格式不正确的程序。

源错误:

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.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'KT.AF.Engine.Core' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
堆栈跟踪:

[BadImageFormatException: Could not load file or assembly 'KT.AF.Engine.Core' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   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, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +118

[ConfigurationErrorsException: Could not load file or assembly 'KT.AF.Engine.Core' 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) +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, Exception appDomainCreationException) +1087

[HttpException (0x80004005): Could not load file or assembly 'KT.AF.Engine.Core' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11524352
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4782309

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

看起来DLL文件是为不同于您的解决方案所构建的系统体系结构而编译的

确保两件事:

您的项目已设置为“任意CPU”生成-这可以在Visual Studio的项目属性中找到


IIS已设置为允许在应用程序池中使用32位应用程序。

您是否在任何地方编译为x64/x86?您正在使用com吗?HttpException与之有什么关系?KT.AF.Engine.Core.dll是用托管代码编写的吗?您是否阅读了备注部分中提到的所有当前建议。KT.AF.Engine.Core.dll是用托管代码编写的。我编译为x86。DLL文件已在x86下使用visual studio 2010 sp1编译。我正在使用VisualStudio2010,但升级到sp1,仍然无法工作。