Global Data Management Forum

Expand all | Collapse all

System.BadImageFormatException: Could not load file or assembly 'IBM.EntityFrameworkCore, Version=6.0.0.200

  • 1.  System.BadImageFormatException: Could not load file or assembly 'IBM.EntityFrameworkCore, Version=6.0.0.200

    Posted Mon April 04, 2022 09:57 AM
    I'm trying to use the .net6 osx packages to connect to our on prem db. It fails with the following error:

    Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'IBM.EntityFrameworkCore, Version=6.0.0.200, Culture=neutral, PublicKeyToken=7c307b91aa13d208'. An attempt was made to load a program with an incorrect format.
    
    File name: 'IBM.EntityFrameworkCore, Version=6.0.0.200, Culture=neutral, PublicKeyToken=7c307b91aa13d208'
       at DB2.NetCoreContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder)
       at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
       at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
       at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
       at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
       at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
       at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_Dependencies()
       at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Microsoft.EntityFrameworkCore.Storage.IDatabaseFacadeDependenciesAccessor.get_Dependencies()
       at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetFacadeDependencies(DatabaseFacade databaseFacade)
       at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlRaw(DatabaseFacade databaseFacade, String sql, IEnumerable`1 parameters)
       at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlRaw(DatabaseFacade databaseFacade, String sql, Object[] parameters)
       at DB2.NetCoreContext.GetData() in /Users/danielkvist/mio/repos/RND/DB2/NetCoreContext.cs:line 23
    ​

    This is my context class:

    public class NetCoreContext : DbContext
    {
        public NetCoreContext() : base()
        {
       
        }
        
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseDb2(
                @"Server=<redacted>;Database=<redacted>;userid=<redacted>;password=<redacted>",
                p=>p.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_02));
        }
    
        public void GetData()
        {
            var query = "select * from <redacted> limit 10";
            var result = this.Database.ExecuteSqlRaw(query);
            
            Console.Write(result);
        }
    }

    This is the project config:

    <Project Sdk="Microsoft.NET.Sdk">
    
        <PropertyGroup>
            <OutputType>Exe</OutputType>
            <TargetFramework>net6.0</TargetFramework>
            <ImplicitUsings>enable</ImplicitUsings>
            <Nullable>enable</Nullable>
        </PropertyGroup>
        
        <ItemGroup>
          <PackageReference Include="IBM.EntityFrameworkCore-osx" Version="6.0.0.200" />
        </ItemGroup>
    
    </Project>
    

    And finally, dotnet info:

    $ dotnet --info
    .NET SDK (reflecting any global.json):
     Version:   6.0.101
     Commit:    ef49f6213a
    
    Runtime Environment:
     OS Name:     Mac OS X
     OS Version:  12.2
     OS Platform: Darwin
     RID:         osx.12-arm64
     Base Path:   /usr/local/share/dotnet/sdk/6.0.101/
    
    Host (useful for support):
      Version: 6.0.1
      Commit:  3a25a7f1cc
    
    .NET SDKs installed:
      6.0.101 [/usr/local/share/dotnet/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    
    To install additional .NET runtimes or SDKs:
      https://aka.ms/dotnet-download
    

     

    I've read through multiple guides, e.g.

    https://www.ibm.com/mysupport/s/question/0D50z000068AfvhCAC/could-not-load-file-or-assembly-ibmdatadb2?language=en_US
    https://community.ibm.com/community/user/hybriddatamanagement/blogs/michelle-betbadal1/2020/04/29/getting-started-with-ibm-data-server-provider-for
    https://www.ibm.com/support/pages/systembadimageformatexception-could-not-load-file-ibmdatadb2dll
    https://stackoverflow.com/questions/30647897/ibm-db2-issue-system-badimageformatexception-could-not-load-file-or-assembly-i
    https://stackoverflow.com/questions/59528086/system-badimageformatexception-while-connecting-to-db2-from-net
    https://stackoverflow.com/questions/60458243/ibm-data-db2-core-throws-exception-in-azure-function-app
    https://github.com/dotnet/runtime/issues/26404

    Any ideas why the dll won't load?

    ------------------------------
    Daniel Kvist
    ------------------------------


    #DataManagementGlobal
    #DataServerDrivers


  • 2.  RE: System.BadImageFormatException: Could not load file or assembly 'IBM.EntityFrameworkCore, Version=6.0.0.200

    Posted Thu June 23, 2022 02:29 PM
    dotnet --info states that you are using M1 Mac (not intel). IBM has not released a DB2 client for Apple Silicon Macs (M1)

    ------------------------------
    Prabhdeep Singh
    ------------------------------