Chris Crowe's Blog
Ramblings of an IIS MVP ( MVP Since 1997 )

Powered By IIS 7

Search my blog

Some of my readers



My Microsoft Certifications


Dec 15, 1998

Dec 20, 2000

Jan 31, 2001

Jul 22, 2002

Nov 1, 2004

My Microsoft MVP Awards




1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
mvp.support.microsoft.com

Have you seen the following error?

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

I have seen these a few times lately and the cause is usually that you have the following configuration:

  • IIS running on a 64Bit Operating System
  • The Assembly DLL in question has been compiled for 32Bit - check the project properties under the build tab, if under platform target you have x86 then it is 32bit only.

    x86 

Why would you have a 32bit only DLL? well it could be that you are using something that is not 64bit compatible, such as MAPI or ODBC...

The real problem is that the 64Bit IIS machine is using an Application Pool that is not allowing a 32bit DLL to be processed.

Open IIS Manager and find the application pool for the site and select the Advanced Settings.

AppPoolAdvSettings

 

Notice that there is an option called "Enable 32-Bit Applications" this is the cause of the error. Enable this and you should be good to go.

Here is an example of the full error for this message.


Server Error in '/' Application.


Could not load file or assembly 'XMLView' 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 'XMLView' 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 'XMLView' could not be loaded.

=== Pre-bind state information === LOG: User = NT AUTHORITY\NETWORK SERVICE LOG: DisplayName = XMLView (Partial) LOG: Appbase = file:///C:/dev/Projects/OSCARUtils/ LOG: Initial PrivatePath = C:\dev\Projects\OSCARUtils\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\dev\Projects\OSCARUtils\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\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/v2.0.50727/Temporary ASP.NET Files/root/8a8c3f22/9d24bab0/XMLView.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/root/8a8c3f22/9d24bab0/XMLView/XMLView.DLL. LOG: Attempting download of new URL file:///C:/dev/Projects/OSCARUtils/bin/XMLView.DLL. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Stack Trace:

[BadImageFormatException: Could not load file or assembly 'XMLView' 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.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +465 System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +181 System.Reflection.Assembly.Load(String assemblyString) +42 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190 [ConfigurationErrorsException: Could not load file or assembly 'XMLView' 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) +3637752 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +397 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +155 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +36 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +235 System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +214 System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +57 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +259 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +406 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +125 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +203 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +52 System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +50 System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +410 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +274

Version Information: Microsoft .NET Framework Version:2.0.50727.1378; ASP.NET Version:2.0.50727.1378
posted on Monday, November 05, 2007 2:49 PM |

Comments


# dll file

Gravatar
Could not load the assembly 'App_Web_lq1gcbsa'. Make sure that it is compiled before accessing the page.
and the 'App_Web_lq1gcbsa' is dll file exist in bin folder
Posted by Rawan on 3/25/2008 9:41 PM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Yes right am running a 64bit IIS Machine and am building a 32bit application, but i dunno why i cant find the option "Enable 32-Bit Application" on my IIS Pool advanced settings, u know why ?

thanks anyway for ur help
Posted by Galal on 9/22/2008 8:00 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
after some searching i figured out that i can do it in the command prompt by using the following command 'cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 “true” '

and everything is workin now :)

thanks again ...
Posted by Galal on 9/22/2008 8:15 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Thank you very much for that Description!!!

Salut
Marcel
Posted by Marcel on 10/27/2008 4:37 AM

# re: Could not load file or assembly 'name' or one of its dependencies


Hey, Marcel, I seem to have the same problem as you
Also can it be done using windows XP x64 ? the applicationPool info and options is missing ....
Posted by Henry Aloni on 11/6/2008 11:46 PM

# re: Could not load file or assembly 'name' or one of its dependencies


Right to the point !
Very nice article, short and clear.
You solved my problem, thanks !
Posted by G. Dumais on 11/13/2008 6:54 AM

# re: Could not load file or assembly 'name' or one of its dependencies


Thankyouthankyouthankyouthankyouthankyou :)
Posted by Grateful on 11/23/2008 11:50 AM

# re: Could not load file or assembly 'name' or one of its dependencies


Thanksssssssss !!!!
That's works for winform too.
Posted by firedeal on 12/11/2008 11:49 PM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
THANKS! You saved my day!
Posted by w. harms on 12/16/2008 2:09 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Very nice article. Congratulations.
How do I do it in IIS6?
Posted by Jonatas on 12/16/2008 4:59 AM

# re: Could not load file or assembly 'name' or one of its dependencies


Great...! Thanks.. You solved my problem.
Posted by Vijay Kumar Naidu on 12/18/2008 12:54 AM

# re: Could not load file or assembly 'name' or one of its dependencies


I am facing same problem of running 32-bit app on 64-bit server. But I am not getting app pool advanced setting tab in IIS6. How to go about?
Posted by manu_123 on 2/4/2009 5:42 PM

# re: Could not load file or assembly 'name' or one of its dependencies


manu, I am having the same problem. Did you found anything about that?
Posted by svdw on 2/4/2009 11:13 PM

# re: Could not load file or assembly 'name' or one of its dependencies


This worked for me: http://www.aboutmeadows.com/articles/how-to-enable-32-bit-asp.net-on-windows-server-2003.aspx
Posted by svdw on 2/5/2009 12:21 AM

# re: Could not load file or assembly 'name' or one of its dependencies


Cool. Trust another Kiwi to have the real required answer!
Thanks heaps.
Just what I was looking for. I had .NET stuff calling a 32bit COM component running under IIS on a x64 Vista machine and was getting the classic class not registered (80040154). So once I had it figured that the .NET side had to be built for x86 only, it then failed with BadImageFormatException etc.
Posted by Myles on 4/30/2009 10:32 PM

# re: Could not load file or assembly 'name' or one of its dependencies


OMG Thank you!

Dave
Posted by David Totzke on 5/7/2009 7:04 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Thanks man, it was the solution I needed!
Posted by Guilherme Lima on 5/12/2009 4:03 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Thought this had to be the answer, since I migrated a custom WSS site from a 32 bit win 2003 sear5ver to a 64 bit Win 2008 server, but enabling the 32 bit apps simply causes any WSS site on the app pool to be unreachable with a 500 error; so I'm guessin that wasn't the issue even though my error matched the one above in your example. hmmm..
Posted by K R on 7/30/2009 6:20 AM

# re: Could not load file or assembly 'name' or one of its dependencies


Thank you so much for posting this, it fixed my problem!
Posted by Robert on 8/10/2009 9:25 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Thanks man! It solved my problem.
Posted by raul on 8/23/2009 6:39 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
Thanks for the info, came in real handy!

Cheers!
Posted by gotospaceordie on 9/3/2009 4:06 AM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
thanks for good explanation!
Posted by Ivan on 9/16/2009 8:54 PM

# re: Could not load file or assembly 'name' or one of its dependencies


Thank you! Thank you! Thank you! I was tearing my hair out over this one. Setting "Enable 32-bit Applications" was exactly what I needed!
Posted by Megan on 10/8/2009 1:43 PM

# re: Could not load file or assembly 'name' or one of its dependencies

Gravatar
you are great!!!
i couldn't find it on my own...you saved me
Posted by julie on 10/8/2009 9:35 PM

Post Comment


Title *
Name *
Email
Url
Comment *  
Please add 4 and 5 and type the answer here: