none
Could not load file or assembly 'System.Data' or one of its dependencies

    Question

  • Hi,

    Hopefully I'm posting in the right forum. I'm not quite sure where this error is happening.

     

    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.

     

     

    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.

     

    Thanks in advance.

    Saturday, January 19, 2008 3:20 AM

Answers

  • Hi,

     

    Check your web.config. See your <assemblies> section. It should be 3.5 instead of 2.0

     

    <assemblies>

    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    </assemblies>

     

     

    There is a forum dedicated to asp.net and related technologies.

     

    In future, you can post asp.net questions in the asp.net forums at http://forums.asp.net

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    -----

    Saturday, January 19, 2008 5:06 AM
    Moderator

All replies

  • Hi,

     

    Check your web.config. See your <assemblies> section. It should be 3.5 instead of 2.0

     

    <assemblies>

    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    </assemblies>

     

     

    There is a forum dedicated to asp.net and related technologies.

     

    In future, you can post asp.net questions in the asp.net forums at http://forums.asp.net

     

    HTH,
    Suprotim Agarwal

    -----
    http://www.dotnetcurry.com
    -----

    Saturday, January 19, 2008 5:06 AM
    Moderator
  • I have also had this problem when moving to a 64-bits server. Setting "Enable 32-bit Applications" in the app pool solved it for me.

    See my blog for a detailed description and a screenshot where to find the setting.

     

    Regards,

    Michael

    -----
    http://jepsonsblog.blogspot.com
    -----

    Monday, December 20, 2010 2:08 PM
  • I have the same problem. Setting "Enable 32-bit Applications" in the app pool solved it for me.

     

    Thanks

    Michael Jepson

    Thursday, August 18, 2011 6:33 AM
  • All of the projects in your solution need to be set to compile with the "Any CPU" mode. Platform should be: Active (Any CPU) and Platform target should be: Any CPU.

     

    Thanks

    KKR

    Wednesday, September 07, 2011 7:01 AM
  • Enable 32 bit in the application pool.
    • Proposed as answer by MRat2014 Tuesday, April 08, 2014 5:11 PM
    Tuesday, April 08, 2014 5:11 PM