November 2007 (2)
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:
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.
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.
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.
[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
I was approached by an attendee at the Christchurch Code Camp yesterday with question that at the time I could not answer - I should have been able to answer but my brain was frazzled.
What is the difference between a virtual directory and an application in IIS 7?
The correct answer is:
A Virtual Directory and an application allows you to create an alias for a physical folder that may actually reside in a different folder, or disk drive or even computer than the current physical path.
The difference with IIS 7 is that an Application allows you to specify a different Application Pool where as a Virtual Directory does not.