I've been having a problem with the .NET application I'm working on ever since I started working on it last April. My development computer runs Windows XP Pro 2003 64-bit Edition. All of the projects in my solution are set to compile
with the "Any CPU" mode. I can run the application just fine in debug and release modes, but I've tried and tried to make it work when I publish it in inetpub/wwwroot and it just won't work. I always get the following error :
Server Error in '/Requisitions' Application.
Could not load file or assembly 'App_Code' 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 'App_Code' 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 'App_Code' could not be loaded.
=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = App_Code
(Partial)
LOG: Appbase = file:///c:/inetpub/wwwroot/Requisitions/
LOG: Initial PrivatePath = c:\inetpub\wwwroot\Requisitions\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\inetpub\wwwroot\Requisitions\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/requisitions/833f9d68/80608f77/App_Code.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/requisitions/833f9d68/80608f77/App_Code/App_Code.DLL.
LOG: Attempting download of new URL file:///c:/inetpub/wwwroot/Requisitions/bin/App_Code.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'App_Code' 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 'App_Code' 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) +3642024
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +402
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.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +514
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +274
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
Well, I said it never works, well it does work on computers who run Windows XP 32-bit without any problems. I also manager to get it working on my computer by doing the following :
<script type=text/javascript>loadTOCNode(2, 'moreinformation');</script> To run the 32-bit version of ASP.NET 2.0, follow these steps:
1.
Click Start, click
Run, type cmd, and then click
OK.
2.
Type the following command to enable the 32-bit mode: <div class=indent>cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1</div>
3.
Type the following command to install the version of ASP.NET 2.0 (32-bit) and to install the script maps at the IIS root and under: <div class=indent>%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe
-i </div>
4.
Make sure that the status of ASP.NET version 2.0.50727 (32-bit) is set to
Allowed in the Web service extension list in Internet Information Services Manager.
The problem is that I can't remain in that mode, because all of my other apps don't work when I do it, only the one that I wanna be able to use. I switched back to the 64-bit mode and all of my other apps started working again except for the one specified
in my error message.
I've tried absolutely every trick that was suggested on these forums as well as everywhere else, and absolutely nothing seems to work.
All of our other apps work fine on both 32-bit and 64-bit platforms. I compared them with the one that doesn't work and I can't see anything wrong or different between the 2.
You said, "All of the projects in my solution are set to compile with the "Any CPU" mode. "
Because you want to run it on a 64-bit CPU, what happens when you set it to specifically compile for a 64-bit CPU instead of "Any CPU" and then publish to Inetpub\wwwroot ?
You said, "All of the projects in my solution are set to compile with the "Any CPU" mode. "
Because you want to run it on a 64-bit CPU, what happens when you set it to specifically compile for a 64-bit CPU instead of "Any CPU" and then publish to Inetpub\wwwroot ?
When I try that, it gives me another error message that I didn't see before...
Error 110 Could not create activity of type 'Requisitions.Workflow.Approbation.ApprobationWorkflow.Workflow1'. System.IO.FileNotFoundException: Could not load file or assembly 'Requisitions.Workflow.Approbation.ApprovalExternalEvent, Version=1.2.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'Requisitions.Workflow.Approbation.ApprovalExternalEvent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'
at Requisitions.Workflow.Approbation.ApprobationWorkflow.Workflow1..cctor()
=== Pre-bind state information ===
LOG: User = xxxxxx_xx\xxxxxxx
LOG: DisplayName = Requisitions.Workflow.Approbation.ApprovalExternalEvent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\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: The same bind was seen before, and was failed with hr = 0x80070002.
C:\Working Folder\Requisitions_TEST\Requisitions.Workflow.Approbation.ApprobationWorkflow 1 1
Are you trying to publish the application to c:\Inetpub\wwwroot\ on your own computer or are you trying to publish to a web server (i.e. different computer)?
You might try deleting all of the files in
C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/requisitions/
Thanks a lot for replying to my post, I really appreciate it.
"Are you trying to publish the application to c:\Inetpub\wwwroot\ on your own computer or are you trying to publish to a web server (i.e. different computer)?"
I tried on my own computer (wwwroot) and also on a web server (different computer). It doesn't work on my computer because of the fact that I'm running Windows 2003 x64, and it works on a distinct web server
when the web server is not x64 (and it doesn't work if it is).
You might try deleting all of the files in
C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/requisitions/
Yes I am absolutely positive that it is the 64 bit version of the framework. I had installed it myself and I just double-checked to make sure it was and it is.
There are 2 things that I forgot to mention... My project uses the Microsoft Enterprise Library (v. 3.1.0.0) and also the AjaxControlToolkit.
I read some more about that problem on various sites and someone mentionned something that seemed like an interesting lead.
I found the problem: I complied my code with the "Any CPU" setting, but the Enterprise Library is complied with the "x86" setting. When .NET runs my code and tries to load EntLibrary, it assumes the EntLibrary is also 64bit, thus cause the problem.
I then decided to grab the MS Enterprise source code and add it to my project (only the parts I need) to make sure it was compiled the right way. Still didn't work...
Also, one thing that I need to mention is that we have another application that is very similar to the one I'm having trouble with. It also uses Microsoft Enterprise Library AND AjaxControlToolkit and it runs perfectly fine both on 32-bit and 64-bit computers...
I even tried using the same DLLs (Ent. Library + Ajax) for the app that won't work (copied them from the other project that works regardless of the fact that the OS is 32-bit or 64-bit)., and it still didn't work. I compared the way the compilation is done
(x86, x64, Any CPU, Mixed Platform) and both are set to use "Any CPU".
I really don't know what's wrong with that other app... Any ideas? I'm seriously running out of ideas...
"IIS 6.0 supports both the 32-bit mode and the 64-bit mode. However IIS 6.0 does not support running both modes at the same time on a 64-bit version of Windows."
"Unlike previous versions of IIS, you can now configure specific worker processes to run in 32-bit or 64-bit mode independently of each other on the same server."
Because this troublesome ASP.NET application does run OK as 32-bit application, if you are using IIS 7.0 perhaps you can configure it specifically to run in a 32-bit application pool on IIS while all the others run as 64-bit.
blakthorn
0 Points
5 Posts
Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to loa...
Jul 28, 2008 03:56 PM|LINK
Hi everyone,
I've been having a problem with the .NET application I'm working on ever since I started working on it last April. My development computer runs Windows XP Pro 2003 64-bit Edition. All of the projects in my solution are set to compile with the "Any CPU" mode. I can run the application just fine in debug and release modes, but I've tried and tried to make it work when I publish it in inetpub/wwwroot and it just won't work. I always get the following error :
Server Error in '/Requisitions' Application.
Could not load file or assembly 'App_Code' 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 'App_Code' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
Assembly Load Trace: The following information can be helpful to determine why the assembly 'App_Code' could not be loaded.
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
Well, I said it never works, well it does work on computers who run Windows XP 32-bit without any problems. I also manager to get it working on my computer by doing the following :
http://support.microsoft.com/kb/894435/en-us
ASP.NET 2.0, 32-bit version
<script type=text/javascript>loadTOCNode(2, 'moreinformation');</script> To run the 32-bit version of ASP.NET 2.0, follow these steps:
The problem is that I can't remain in that mode, because all of my other apps don't work when I do it, only the one that I wanna be able to use. I switched back to the 64-bit mode and all of my other apps started working again except for the one specified in my error message.
I've tried absolutely every trick that was suggested on these forums as well as everywhere else, and absolutely nothing seems to work.
Here are some of the things I tried :
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2679445&SiteID=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=665884&SiteID=1
http://support.microsoft.com/default.aspx?scid=kb;en-us;329065
http://blogs.componentone.com/CS/forums/t/74096.aspx
http://www.dotnetjunkies.ddj.com/Forums/ShowPost.aspx?PostID=1633
All of our other apps work fine on both 32-bit and 64-bit platforms. I compared them with the one that doesn't work and I can't see anything wrong or different between the 2.
Any suggestions? I'm desperate...
Thanks a lot in advance!
Tom.NET
Member
57 Points
22 Posts
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Jul 28, 2008 10:21 PM|LINK
You said, "All of the projects in my solution are set to compile with the "Any CPU" mode. "
Because you want to run it on a 64-bit CPU, what happens when you set it to specifically compile for a 64-bit CPU instead of "Any CPU" and then publish to Inetpub\wwwroot ?
blakthorn
0 Points
5 Posts
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Jul 29, 2008 01:31 PM|LINK
When I try that, it gives me another error message that I didn't see before...
Error 110 Could not create activity of type 'Requisitions.Workflow.Approbation.ApprobationWorkflow.Workflow1'. System.IO.FileNotFoundException: Could not load file or assembly 'Requisitions.Workflow.Approbation.ApprovalExternalEvent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'Requisitions.Workflow.Approbation.ApprovalExternalEvent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'
at Requisitions.Workflow.Approbation.ApprobationWorkflow.Workflow1..cctor()
=== Pre-bind state information ===
LOG: User = xxxxxx_xx\xxxxxxx
LOG: DisplayName = Requisitions.Workflow.Approbation.ApprovalExternalEvent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\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: The same bind was seen before, and was failed with hr = 0x80070002.
C:\Working Folder\Requisitions_TEST\Requisitions.Workflow.Approbation.ApprobationWorkflow 1 1
Tom.NET
Member
57 Points
22 Posts
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Jul 30, 2008 08:40 PM|LINK
Are you trying to publish the application to c:\Inetpub\wwwroot\ on your own computer or are you trying to publish to a web server (i.e. different computer)?
You might try deleting all of the files in
C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/requisitions/
after publishing to c:\Inetpub\wwwroot\
Are you sure you have the 64 bit version of the .NET Framework Redistributable Package? Please click on: http://www.microsoft.com/downloads/details.aspx?familyid=b44a0000-acf8-4fa1-affb-40e78d788b00&displaylang=enblakthorn
0 Points
5 Posts
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Jul 31, 2008 03:05 PM|LINK
Hi Tom,
Thanks a lot for replying to my post, I really appreciate it.
"Are you trying to publish the application to c:\Inetpub\wwwroot\ on your own computer or are you trying to publish to a web server (i.e. different computer)?"
I tried on my own computer (wwwroot) and also on a web server (different computer). It doesn't work on my computer because of the fact that I'm running Windows 2003 x64, and it works on a distinct web server when the web server is not x64 (and it doesn't work if it is).
You might try deleting all of the files in
C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/requisitions/
after publishing to c:\Inetpub\wwwroot\I tried multiple times to do that to no avail...
Are you sure you have the 64 bit version of the .NET Framework Redistributable Package? Please click on: http://www.microsoft.com/downloads/details.aspx?familyid=b44a0000-acf8-4fa1-affb-40e78d788b00&displaylang=en
Yes I am absolutely positive that it is the 64 bit version of the framework. I had installed it myself and I just double-checked to make sure it was and it is.
There are 2 things that I forgot to mention... My project uses the Microsoft Enterprise Library (v. 3.1.0.0) and also the AjaxControlToolkit.
I read some more about that problem on various sites and someone mentionned something that seemed like an interesting lead.
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic35207.aspx
Here's what he said :
"All,
I found the problem: I complied my code with the "Any CPU" setting, but the Enterprise Library is complied with the "x86" setting. When .NET runs my code and tries to load EntLibrary, it assumes the EntLibrary is also 64bit, thus cause the problem.
This http://blogs.msdn.com/jaiprakash/archive/2005/10/06/477645.aspx page has more information on this problem."
I then decided to grab the MS Enterprise source code and add it to my project (only the parts I need) to make sure it was compiled the right way. Still didn't work...
Also, one thing that I need to mention is that we have another application that is very similar to the one I'm having trouble with. It also uses Microsoft Enterprise Library AND AjaxControlToolkit and it runs perfectly fine both on 32-bit and 64-bit computers... I even tried using the same DLLs (Ent. Library + Ajax) for the app that won't work (copied them from the other project that works regardless of the fact that the OS is 32-bit or 64-bit)., and it still didn't work. I compared the way the compilation is done (x86, x64, Any CPU, Mixed Platform) and both are set to use "Any CPU".
I really don't know what's wrong with that other app... Any ideas? I'm seriously running out of ideas...
Thanks in advance!
blakthorn
0 Points
5 Posts
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Jul 31, 2008 03:06 PM|LINK
bump
Tom.NET
Member
57 Points
22 Posts
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Aug 05, 2008 10:20 PM|LINK
Which version of IIS are you using?
According to http://support.microsoft.com/kb/894435 ,
"IIS 6.0 supports both the 32-bit mode and the 64-bit mode. However IIS 6.0 does not support running both modes at the same time on a 64-bit version of Windows."
According to http://learn.iis.net/page.aspx/201/32-bit-mode-worker-processes/ , IIS 7.0 can be configured to run 32 and 64-bit applications simultaneously. According to this URL,
"Unlike previous versions of IIS, you can now configure specific worker processes to run in 32-bit or 64-bit mode independently of each other on the same server."
Because this troublesome ASP.NET application does run OK as 32-bit application, if you are using IIS 7.0 perhaps you can configure it specifically to run in a 32-bit application pool on IIS while all the others run as 64-bit.
Read http://www.andornot.com/about/developerblog/2008/05/how-to-install-webpublisher-on-64-bit.aspx , especially Step 6, and it might help you set up a 32-bit application pool on IIS 7.0 where you can publish and run this troublesome application.
Reading http://www.bibble-it.com/2008/06/09/32bit-web-app-inside-64bit-website-iis-70 might also help.
kjun0306
Member
2 Points
1 Post
Re: Could not load file or assembly 'App_Code' or one of its dependencies. An attempt was made to...
Feb 08, 2010 07:13 PM|LINK
I have the same problems and tried all tricks I found on the web but it is still not working.
Please help me...