I've converted a web application from ASP.NET 2.0 in VS 2005 to ASP.NET 3.5 in VS 2008. When I run the site from within VS everything works fine. When I deploy it to my local IIS 7 server I get the following error.
Server Error in '/PrzemekLach' Application.
Could not load file or assembly 'System.Data' 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 'System.Data' 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 'System.Data' 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 'System.Data' 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 'System.Data' 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.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +419
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
From that last line it appears the IIS is running only ASP.NET 2.0xxx. I have ASP.NET 3.5 installed.
So, is the problem in fact that IIS is using the wrong version of ASP.NET and if so how do I go about changing it. Or is this another problem altogether.
First, enabling assembly load logging (easiest way is with fuslogvw.exe tool) will allow you to see what .NET is trying to load (and from where).
przemeklach
From that last line it appears the IIS is running only ASP.NET 2.0xxx. I have ASP.NET 3.5 installed.
So, is the problem in fact that IIS is using the wrong version of ASP.NET and if so how do I go about changing it. Or is this another problem altogether.
.NET 3.5 is new compilers and assemblies added on top of 3.0, which was assemblies added on top of 2.0: i.e. to use .NET 3.5, you need IIS configured to be ASP.NET 2.0.
I started the Assembly Binding Log Viewer and ran my site in IE. Nothing showed up in the logger.
I went through all the settings in IIS. I'm not sure where I'm supposed to look to see if IIS is configure for ASP.NET 2.0. In my Application Pool settings the .NET version is set to v2.0xxx. I'm assuming that is it?
In my Application Pool settings the .NET version is set to v2.0xxx. I'm assuming that is it?
You should be checking this on the web site root or virtual directory rather than application pool.
przemeklach
Nothing showed up in the logger.
Hmm.... another route to getting this data is to look at the details of the exception... you'll need to ensure debugger is running and stop on the exception to look at the details.
All of this seems to be either a configuration problem (which can be all about the details -- double check everything like the output from "aspnet_regiis -lk"), or the .NET installation has been corrupted (but this seems
a lot less likely).
I could not find a drop down anywhere where I can switch between the differnet versions of .NET. When I looked under the .NET Compilations/Assemblies settings I saw a mixture of 2.0, 3.0 and 3.5 ASP.NET assembly references. Not sure if that is where I'm
supposed to look and if these are correct? Can you tell me where I'm supposed to look? I'm not that familiar with IIS.
I'm don't know where to get the output from aspnet_regiis. I ran my site again and for some reason I got more error information this time. Here it is, maybe this is what you're looking for. I've also attached my web.config file.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = System.Data
(Partial)
LOG: Appbase = file:///C:/inetpub/wwwroot/PrzemekLach/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\PrzemekLach\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\PrzemekLach\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/przemeklach/e61519c5/f77cb8c9/System.Data.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/przemeklach/e61519c5/f77cb8c9/System.Data/System.Data.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/PrzemekLach/bin/System.Data.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
So I still have no solution. I started a project from scratch and I tested it everytime I added something. I incrementally added stuff: masterpage, sitemaps etc... each time testing to see if things would run. The error came up when I added an AJAX extender
to a button.
The setup of IIS 7 that I have is just the default one. I'm confused as to why no one else has had this problem. What I'm trying to do here is run a simple website with and AJAX control. Has no one else done this yet?
The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll Running under executable C:\Documents and Settings\richard_cox\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe --- A detailed error log follows.
=== Pre-bind state information === LOG: User = XX\YY LOG: DisplayName = SystemX.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (Fully-specified) LOG: Appbase = file:///C:/Documents and Settings/YY/Local Settings/Application Data/Temporary Projects/ConsoleApplication1/bin/Debug/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = NULL Calling assembly : ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Post-policy reference: SystemX.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///C:/Documents and Settings/richard_cox/Local Settings/Application Data/Temporary Projects/ConsoleApplication1/bin/Debug/SystemX.Data.DLL. LOG: Attempting download of new URL file:///C:/Documents and Settings/richard_cox/Local Settings/Application Data/Temporary Projects/ConsoleApplication1/bin/Debug/SystemX.Data/SystemX.Data.DLL. LOG: Attempting download of new URL file:///C:/Documents and Settings/richard_cox/Local Settings/Application Data/Temporary Projects/ConsoleApplication1/bin/Debug/SystemX.Data.EXE. LOG: Attempting download of new URL file:///C:/Documents and Settings/richard_cox/Local Settings/Application Data/Temporary Projects/ConsoleApplication1/bin/Debug/SystemX.Data/SystemX.Data.EXE. LOG: All probing URLs attempted and failed.
Note the highlighted lines [Appears highlighting gets lost when I post... lines starting "LOG: DisplayName" and "LOG: GAC Lookup"]:
In your log it shows "System.Data" for the display name, not the strong name. How exactly are you referencing System.Data?
There was a check in the GAC before probing application local paths.
It seems there is either something seriously wrong with your setup/configuration. Or that something is wrong with the reference to System.Data in the code.
For the first I can only think that a uninstall/reinstall is the approach (but if significantly broken may require an OS reinstall). For the latter try looking at the references in the compiled assembly (using IDLASM or (easier) Reflector for .NET).
When I try to run aspnet_regiis from the command line, it tells me that it's not recognized as an internal or external command.....
I searched my HD for aspnet_regiis and nothing was found either.
I downloaded Reflector but I don't really know what to do with it. When I start it up I get list of assemblies. System.Data is in the list and its path is: %SystemRoot%\Microsoft.net\Framework\v2.0.50727\System.Data.dll. Not sure if that's right or not.
Despite all this I have found a solution for my problem. I use a web deployment project to pre-compile, merge and move my site from my development folder to my C:\inetpub\wwwroot\PrzemekLach directory. When I run the deployment poject it creates a whole
bunch of assemblies in both my development bin folder and the bin folder in the C:\inetpub\wwwroot\PrzemekLach directory, these include: System.Data.dll, System.Data.OracleClient.dll, System.EnterprisesServices.dll just to name a few.
If I move the site manually, without precompiling and using the deployment project the website runs fine. What gives? Why is it doing this?
I searched my HD for aspnet_regiis and nothing was found either.
It should be in %WinDir%\Microsoft.NET\Framework\v2.0.50727
If not you don't have a complete install.
przemeklach
I downloaded Reflector
Select something (e.g. an assembly, or a function) in the tree, and press space to expand to show details (assembly level attributes, code). Details for a reference is the compiled in stroing name.
przemeklach
Despite all this I have found a solution for my problem. I
I think you have a problem, core .NET dll's should not be included directly in an install... but I'm not expert on deployment projects so don't know how they know what is part of the .NET install itself and what is part of the application install.
This problems seems to be related to trying to use the DLL in it's x32 version while the server is x64, or vice versa.
I fixed the problem by setting the plataform target to "any cpu", and then I change the System.Data reference property "Copy local" to false. In this way, the server can get it's own local version of the DLL, and the website can work without changes independently
of the server version.
Now it works perfectly for me.
PS: be sure you delete the System.Data.dll file from your output /DLL folder, otherwise it will continue to try to get this version instead of the server .net framework version.
przemeklach
Member
227 Points
119 Posts
Could not load file or assembly 'System.Data' or one of its dependencies
Jan 19, 2008 04:42 AM|LINK
Hopefully I got the right forum here.
I've converted a web application from ASP.NET 2.0 in VS 2005 to ASP.NET 3.5 in VS 2008. When I run the site from within VS everything works fine. When I deploy it to my local IIS 7 server I get the following error.
Server Error in '/PrzemekLach' Application.
Could not load file or assembly 'System.Data' 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 'System.Data' 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 'System.Data' could not be loaded.
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
From that last line it appears the IIS is running only ASP.NET 2.0xxx. I have ASP.NET 3.5 installed.
So, is the problem in fact that IIS is using the wrong version of ASP.NET and if so how do I go about changing it. Or is this another problem altogether.
Thanks in advance.
rjcox
Contributor
7064 Points
1444 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 19, 2008 07:15 AM|LINK
First, enabling assembly load logging (easiest way is with fuslogvw.exe tool) will allow you to see what .NET is trying to load (and from where).
.NET 3.5 is new compilers and assemblies added on top of 3.0, which was assemblies added on top of 2.0: i.e. to use .NET 3.5, you need IIS configured to be ASP.NET 2.0.
przemeklach
Member
227 Points
119 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 19, 2008 06:26 PM|LINK
Thanks for your reply.
I started the Assembly Binding Log Viewer and ran my site in IE. Nothing showed up in the logger.
I went through all the settings in IIS. I'm not sure where I'm supposed to look to see if IIS is configure for ASP.NET 2.0. In my Application Pool settings the .NET version is set to v2.0xxx. I'm assuming that is it?
Thanks.
rjcox
Contributor
7064 Points
1444 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 20, 2008 07:04 AM|LINK
You should be checking this on the web site root or virtual directory rather than application pool.
Hmm.... another route to getting this data is to look at the details of the exception... you'll need to ensure debugger is running and stop on the exception to look at the details.
All of this seems to be either a configuration problem (which can be all about the details -- double check everything like the output from "aspnet_regiis -lk"), or the .NET installation has been corrupted (but this seems a lot less likely).
przemeklach
Member
227 Points
119 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 21, 2008 07:09 PM|LINK
I could not find a drop down anywhere where I can switch between the differnet versions of .NET. When I looked under the .NET Compilations/Assemblies settings I saw a mixture of 2.0, 3.0 and 3.5 ASP.NET assembly references. Not sure if that is where I'm supposed to look and if these are correct? Can you tell me where I'm supposed to look? I'm not that familiar with IIS.
I'm don't know where to get the output from aspnet_regiis. I ran my site again and for some reason I got more error information this time. Here it is, maybe this is what you're looking for. I've also attached my web.config file.
przemeklach
Member
227 Points
119 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 23, 2008 12:22 AM|LINK
So I still have no solution. I started a project from scratch and I tested it everytime I added something. I incrementally added stuff: masterpage, sitemaps etc... each time testing to see if things would run. The error came up when I added an AJAX extender to a button.
The setup of IIS 7 that I have is just the default one. I'm confused as to why no one else has had this problem. What I'm trying to do here is run a simple website with and AJAX control. Has no one else done this yet?
rjcox
Contributor
7064 Points
1444 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 23, 2008 07:38 AM|LINK
That is what you will see,. both 3.0 and 3.5 are incremental additons to 2.0 core (now with SP1).
You run it from the command line, it outputs to standard output.
Yes... and it shows there is something wrong, why is there no looking for the assembly in the GAC?
This is what I get from looking for System.Data (with correct full assembly name):
Note the highlighted lines [Appears highlighting gets lost when I post... lines starting "LOG: DisplayName" and "LOG: GAC Lookup"]:
It seems there is either something seriously wrong with your setup/configuration. Or that something is wrong with the reference to System.Data in the code.
For the first I can only think that a uninstall/reinstall is the approach (but if significantly broken may require an OS reinstall). For the latter try looking at the references in the compiled assembly (using IDLASM or (easier) Reflector for .NET).
przemeklach
Member
227 Points
119 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 24, 2008 01:10 AM|LINK
When I try to run aspnet_regiis from the command line, it tells me that it's not recognized as an internal or external command.....
I searched my HD for aspnet_regiis and nothing was found either.
I downloaded Reflector but I don't really know what to do with it. When I start it up I get list of assemblies. System.Data is in the list and its path is: %SystemRoot%\Microsoft.net\Framework\v2.0.50727\System.Data.dll. Not sure if that's right or not.
Despite all this I have found a solution for my problem. I use a web deployment project to pre-compile, merge and move my site from my development folder to my C:\inetpub\wwwroot\PrzemekLach directory. When I run the deployment poject it creates a whole bunch of assemblies in both my development bin folder and the bin folder in the C:\inetpub\wwwroot\PrzemekLach directory, these include: System.Data.dll, System.Data.OracleClient.dll, System.EnterprisesServices.dll just to name a few.
If I move the site manually, without precompiling and using the deployment project the website runs fine. What gives? Why is it doing this?
Thanks in advance.
rjcox
Contributor
7064 Points
1444 Posts
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 24, 2008 07:17 AM|LINK
It should be in %WinDir%\Microsoft.NET\Framework\v2.0.50727
If not you don't have a complete install.
Select something (e.g. an assembly, or a function) in the tree, and press space to expand to show details (assembly level attributes, code). Details for a reference is the compiled in stroing name.
Good.
I think you have a problem, core .NET dll's should not be included directly in an install... but I'm not expert on deployment projects so don't know how they know what is part of the .NET install itself and what is part of the application install.
SaciPerere
Member
2 Points
1 Post
Re: Could not load file or assembly 'System.Data' or one of its dependencies
Jan 22, 2010 12:48 AM|LINK
This problems seems to be related to trying to use the DLL in it's x32 version while the server is x64, or vice versa.
I fixed the problem by setting the plataform target to "any cpu", and then I change the System.Data reference property "Copy local" to false. In this way, the server can get it's own local version of the DLL, and the website can work without changes independently of the server version.
Now it works perfectly for me.
PS: be sure you delete the System.Data.dll file from your output /DLL folder, otherwise it will continue to try to get this version instead of the server .net framework version.