ASP.NET -- IIS7 -- IBM DB2 Issue - asp.net

I'm working on a ASP.NET website that calls a DB2 database. I have Visual Studio installed on a Windows 2008 server where the site will be hosted. When I debug the site in Visual Studio, using the integrated web server, I can connect to the database and the site runs fine. When I set the site up in IIS7, on the same server, I cannot access the site or the database because of the following error.
Here are the technical details:
Windows 2008 Server
IIS 7
Visual Studio 2010 Premium
DB2 v9.5.301.436
Could not load file or assembly 'IBM.Data.DB2' 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 'IBM.Data.DB2' 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.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'IBM.Data.DB2' 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].
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'IBM.Data.DB2' 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 'IBM.Data.DB2' 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) +11424435
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) +1167
[HttpException (0x80004005): Could not load file or assembly 'IBM.Data.DB2' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11556592
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4813333
I don't understand how the site can run fine using the Visual Studio web server and not work in IIS. I don't know if it's an IIS issue or and issue with the version of IMB.Data.DB2.dll I'm using. If anyone has a solution or any ideas, they would be greatly appreciated.
Thank you.

To make this work I had to go into IIS Manager, click on the application pool node, click on the application pool for the site, then click on advanced settings on the right hand side of the screen. Then I changed Enable 32 bit applications to true.
This fixed my issue and the site is functioning correctly.

For some bizarre reason Visual Studio 2012 (and later) always copies the 32-bit version of IBM.Data.DB2.dll to your bin folder, even though that is not needed because that DLL is registered GAC when DB2 Connect is installed.
The simplest solution is to add a post-build script to delete that DLL from your bin folder after each build. That way IIS will be able to find the correct version (whether it needs the 32-bit or 64-bit version depends from your AppPool settings) in the GAC.

In Visual Studio: right click the Reference in question and change Copy Local to "False"
https://i.stack.imgur.com/y0Dre.png
More info:
IBM DB2 issue--System.BadImageFormatException: Could not load file or assembly IBM.DB2.DLL or one of its dependencies

It sounds like the .Net framework version is wrong in your AppDomain. In the AppDomain settings, make sure the .Net framework version that is selected matches the version of your IBM.Data.DB2 assembly.

Related

Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found

I've seen the ticket “Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies” by Harsh Gupta and I'm having the same problem but without those solutions working for me.
I have an web application including ImageMagick that is freshly installed on a new Windows Server 2012 instance (that we're migrating to from a Windows Server 2008 R2 instance). The application runs ok on Server 2008 and locally, but not on Server 2012.
I have rebuilt the project after upgrading Magick.Net from 6.8.7.502 to 7.0.7.300, in the hope that the .Net Standard / .Net Core support mentioned in the Readme, introduced in 7.0.6, would solve my problem, but to no avail. Before doing that, I had also installed VC++ 2012 and 2015 as Harsh Gupta mentioned in their accepted answer.
Despite all this, I'm still getting a "HTTP Error 500.0 - Internal Server Error" page, telling me:
Module: AspNetInitializationExceptionModule
Notification: BeginRequest
Handler: ExtensionlessUrlHandler-Integrated-4.0
Error Code: 0x00000000
Requested URL: [redacted]
Physical Path: [redacted, but correct]
Logon Method: Not yet determined
Logon User: Not yet determined
The Event log shows a Warning event from ASP.NET 4.0.30319.0 with an Event ID of 1310 and the following Stack trace:
Event code: 3008
Event message: A configuration error has occurred.
Event time: 9/20/2017 6:20:40 PM
Event time (UTC): 9/20/2017 6:20:40 PM
Event ID: 4775ecdb4601401ca30aa057f77ae78a
Event sequence: 1
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: [redacted]
Trust level: Full
Application Virtual Path: /
Application Path: [redacted]
Machine name: [redacted]
Process information:
Process ID: 5096
Process name: w3wp.exe
Account name: IIS APPPOOL\[redacted]
Exception information:
Exception type: ConfigurationErrorsException
Exception message: Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found.
at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
at System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)
at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
at System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)
Could not load file or assembly 'Magick.NET-x86.DLL' or one of its dependencies. The specified module could not be found.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
Request information:
Request URL: [redacted]
Request path: /
User host address: [redacted]
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\[redacted]
Thread information:
Thread ID: 8
Thread account name: IIS APPPOOL\[redacted]
Is impersonating: False
Stack trace: at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
at System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)
at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
at System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)
Custom event details:
Looking in the webroot, the bin folder does contain Magick.NET-x86.dll (and Magick.NET-Q16-x86.dll and Magick.NET-Q16-x86.Native.dll), and the IIS_IUSRs group does have read access to these DLLs (and all the others).
While it is a 64-bit server, the AppPool does have Enable 32-bit applications set to True. Changing the AppPool's Managed Pipeline Mode from Integrated to Classic also has no effect. I do note, however, that the number of applications for the AppPool is listed as zero (despite the website's advanced settings dialog showing the correct AppPool name):
I am completely at a loss and we are behind schedule on the migration of this application now, so any suggestions would be gratefully received.
Thanks!
Edited to add: There is a little more information at ticket #107 on Github.
I don't have an answer but a few ideas on troubleshooting, although you probably tried these.
You mention the apppool isn't showing the application. Try recreating the apppool or using one of the preexisting apppools as a temporary option to see if there was an issue with apppool.
You're using apppool I'd, which is best but does changing to network service account help, if so points at permission issue.
Have you compared installed Windows features on the old and new servers? Just wondering if it requires WCF.
Has the bin directory been given execute perms in iis.
Do basic aspx pages work or is the configuration breaking those as well.
Maybe you've tried all that but hopefully it might help give you another direction, even if it doesn't help directly.
Try using the Global Assembly Cache Tool (gacutil.exe) to publish the missing assembly to the GAC:
gacutil.exe /i Magick.NET-x86.dll /f
gacutil.exe /i Magick.NET-Q16-x86.dll /f
gacutil.exe /i Magick.NET-Q16-x86.Native.dll /f
The .NET runtime scans for assemblies in the GAC when it cannot locate an assembly referenced by the project at a local path. We typically use the GAC for assemblies shared by several applications, but we can try this approach for troubleshooting.
If the application in question runs successfully after publishing these assemblies to the GAC, there may be a problem with the assembly reference properties in the project that uses them.
After testing, we can remove the assemblies that we added from the GAC:
gacutil.exe /u Magick.NET-x86
...
gacutil.exe comes with the .NET Windows SDK. To avoid installing this on the server, we can use PowerShell to install the assemblies:
[Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") > $null
[System.EnterpriseServices.Internal.Publish] $publisher = new-object System.EnterpriseServices.Internal.Publish
$publisher.GacInstall('Path\To\Magick.NET-x86.dll')
Both tools require administrator privileges on the server.
In a separate conversation on Github with the creator of ImageMagick, we eventually got to checking the version numbers of DLLs, which led us to realise that — as well as the expected files Magick.NET-Q16-x86.dll and Magick.NET-Q16-x86-Native.dll both at version 7.0.7.300 — there was also a file Magick.NET-x86.dll that is version 6.8.7.502.
Quoting Dirk Lemstra directly:
The Magick.NET-x86.dll file is an old file that should not be there. Can you remove that file and check if that resolves your issue? I apologize for not noticing this much earlier.
You no longer need to install the C++ redistributable. The necessary libraries are statically linked which means that you don't need to install that anymore.
Removing that superfluous file has solved the problem. 🎉

Error loading file or assembly in Web Application

i need some pro help here,
I'm trying to install the DevInfo 7 Web application on my server, had A LOT of problems with SQL Server and IIS, after 2 days, i managed to fix it, but now that IIS and SQL are working fine, i can't get past this error because i have no idea about this language (btw, i'll add some tags, but as i don't know this language, i'm not sure they are actually related to the question, if i chose a tag wrong, tell me that i take it of!)
If somebody can explain to me what's wrong, or how to fix it, i would appreciate, as i'm not creating a Web Application (i have no idea on how to do so), and only trying to install one, i may not understand (please be as simplistic as you can)
I dunno if this changes something, but i'm installing it on a Windows Server 2012, x64...
Here's the error:
Server Error in '/devinfo' Application.
Could not load file or assembly 'DI5_INIFile' 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 'DI5_INIFile' 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.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'DI5_INIFile' 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].
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'DI5_INIFile' 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, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122
[ConfigurationErrorsException: Could not load file or assembly 'DI5_INIFile' 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) +12761078
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): Could not load file or assembly 'DI5_INIFile' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601
It sounds as if you have entered .net Version Hell. I've had this problem when there are conflicting dll versions.
Things to try:
1 - Clean your solution (Right click on the top of the solution tree in Visual Studio and click "Clean"), then do Rebuild All.
2 - If that doesn't work, clean out the ../bin/Debug folder for you project, and repeat step 1. If this is a web application and you have a local version of IIS running, you should consider doing an IIS reset first. This will release any locks that processes may have on dlls in your bin folder.
3- In addition to step 2, you could clear out the ../obj folder too. The clean and rebuild should do this for you, however.
4 - One more thing to try is clear out the temporary asp.net files:
del /F /Q "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files"
5 - Failing that, you will need to look at which project is trying to reference 'DI5_INIFile' and check its version number (right-click on the dll > properties > version) and see if it's in your web.config under a different version number.
If it is, you could remove the referenced assembly from your project and try to re-add it again.
Hope that helps!

"Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format."

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?
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"
Go to Respective ==> Site Application Pool ,
Click on ==> Advance Settings
Change value of ==> "Enable 32-Bit Applications" from False to True
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.
-create a new IIS pool for your web site
-Enable 32bit for this pool
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.
After changing Application Pool to V4.0 from v2.0 on IIS, the error got resolved.

Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies

I am working on a web application which interacts with TFS. When I upload my application to windows azure cloud I am getting this error message .
appreciate your inputs to resolve this issue.
pasted below is the error message I am receiving
Server Error in '/' Application.
--------------------------------------------------------------------------------
Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' 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 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' 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.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' 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].
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' 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) +123
[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' 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) +11568240
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.TeamFoundation.WorkItemTracking.Client.Cache' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700976
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869205
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
This is because ,your project is trying to use a 32-bit dll in a 64-bit environment(azure)
To solve this type of issues ,create a start up script with the below given commands
Copy below startup script to a text file and save as "setup.cmd" .
Then include this file into your web role project,set "copy local"=true
then open your ServiceDefinition.csdef below given startup command inside webrole tag
<webrole > --your webrole
<Startup>
<Task commandLine="setup.cmd" executionContext="elevated" />
</Startup>
</webrole >
start up script pasted below:
%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.enable32BitAppOnWin64:"True" /commit:apphost
I resolved this issue by removig the respective DLL from the bin folder of my asp.net web project.
Thanks and regards,
I resolved this by setting the Enable 32-Bit applications option to True in the Advanced Settings of the application pool which the site used.
BadImageFormat Exception is almost always a problem between a 32bit dll trying to load up a 64bit dll or a DLL or executable is loaded as a 64-bit assembly, but it contains 32-bit features or resources.
Try compiling your application down to x86 or vice versa and let me know how that works

Could not load file or assembly 'Interop.EDOfficeLib' or one of its dependencies

I've faced with this problem when deploying the web site on Windows Server 2008 x64. I don't have any idea. Can anyone help me?
Could not load file or assembly 'Interop.EDOfficeLib' 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 'Interop.EDOfficeLib' 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.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Interop.EDOfficeLib' could not be loaded.
=== Pre-bind state information ===
LOG: User = IIS APPPOOL\DefaultAppPool
LOG: DisplayName = Interop.EDOfficeLib
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Interop.EDOfficeLib | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/TSDX 3.0.0/WebService/
LOG: Initial PrivatePath = C:\TSDX 3.0.0\WebService\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\TSDX 3.0.0\WebService\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9d46c957/8adcacab/Interop.EDOfficeLib.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/9d46c957/8adcacab/Interop.EDOfficeLib/Interop.EDOfficeLib.DLL.
LOG: Attempting download of new URL file:///C:/TSDX 3.0.0/WebService/bin/Interop.EDOfficeLib.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Interop.EDOfficeLib' 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) +123
[ConfigurationErrorsException: Could not load file or assembly 'Interop.EDOfficeLib' 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) +11568160
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167
[HttpException (0x80004005): Could not load file or assembly 'Interop.EDOfficeLib' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700896
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869125
You are running your application written for AnyCPU on a 64bit operating system and one or more of your referenced assemblies is not compiled/available for an x64 system.
The first solution is to recompile your application for x86 platform.
The second solution is to distribute a specific x64 version of the EDOfficeLib
I have to add that in addition my problem can be solved by the following way: Should set an Enable 32-Bit Applications parameter to True on an Advanced Settings panel of an Application Pool. (IIS Manager). In this case I don't need to recompile something. Maybe it will be useful for somebody.

Resources