Skip to content

How to scaffold when having x64 and x86 .NET Core SDKs installed #95

Open

Description

@lauxjpn

I am encountering this error when I try to scaffold an existing older version of .mdb (likely Access '97 version)

Could not load assembly 'Legacy.Test.RDBMSMigrations'. Ensure it is referenced by the startup project 'Legacy.Test.RDBMSMigrations'.

In Visual Studio my project is the default startup project and default project on PMC

command I ran via PMC

Scaffold-DbContext -Connection "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\RDBMS\cdb2.mdb;Jet OLEDB:Database Password=mypassword;" -Provider EntityFrameworkCore.Jet -OutputDir CDB2\Models -ContextDir CDB2\Context -Project Legacy.Test.RDBMSMigrations -StartupProject Legacy.Test.RDBMSMigrations

or

Scaffold-DbContext -Connection "Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\RDBMS\cdb2.mdb; Pwd=mypassword;" -Provider EntityFrameworkCore.Jet -OutputDir CDB2\Models -ContextDir CDB2\Context -Project Legacy.Test.RDBMSMigrations -StartupProject Legacy.Test.RDBMSMigrations

Yet same error comes up, also same using the alternate dotnet ef dbcontext scaffold command via CLI

Any idea on what is wrong?

My project setup is as follows

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.Jet" Version="3.1.0-alpha.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Data.Odbc" Version="5.0.0" />
    <PackageReference Include="System.Data.OleDb" Version="5.0.0" />
  </ItemGroup>

</Project>

Originally posted by @olakusibe in #34 (comment)

Activity

  1. lauxjpn commented on Dec 23, 2020

    @lauxjpn
    MemberAuthor

    Your project file looks fine.

    Your .Net SDK however (if my suspicion is correct) is where the problem lies. Can you confirm whether you have the x64 or x86 version of .Net?

    You can use the following command to get that info: dotnet --info

    My guess is that you have the x64 SDK installed. To do the scaffolding the dotnet.exe needs to load your assembly to use it. As it is 2 different platforms (x64 vs x86) it can't load.

    To fix, manually download and install the x86 SDK. Then edit your PATH environment variable (or however else you want to do it) so that the x86 SDK is picked before the x64 version

    Originally posted by @ChrisJollyAU in #34 (comment)

  2. lauxjpn commented on Dec 23, 2020

    @lauxjpn
    MemberAuthor

    Thanks @ChrisJollyAU , following your steps worked.

    Is there another technical way to run both x86 and x64 SDKs without going back and forth to set their priority order in PATH?

    Originally posted by @olakusibe in #34 (comment)

  3. lauxjpn commented on Dec 23, 2020

    @lauxjpn
    MemberAuthor

    Haven't tried anything but https://stackoverflow.com/questions/39497807/configure-net-core-to-use-x86-sdk has a couple of potential solutions. I think the Dicretory.Build.Targets file may have more chance of success

    Originally posted by @ChrisJollyAU in #34 (comment)

  4. lauxjpn commented on Dec 23, 2020

    @lauxjpn
    MemberAuthor

    @olakusibe A simple way is to just use appropriate full path to the x86 or x64 dotnet.exe in your CLI command:

    PS C:\> & 'C:\Program Files (x86)\dotnet\dotnet.exe' --info
    .NET Core SDK (reflecting any global.json):
     Version:   3.1.201
     Commit:    b1768b4ae7
    
    Runtime Environment:
     OS Name:     Windows
     OS Version:  10.0.19041
     OS Platform: Windows
     RID:         win10-x86
     Base Path:   C:\Program Files (x86)\dotnet\sdk\3.1.201\
    
    Host (useful for support):
      Version: 5.0.1
      Commit:  b02e13abab
    
    .NET SDKs installed:
      2.2.207 [C:\Program Files (x86)\dotnet\sdk]
      2.2.402 [C:\Program Files (x86)\dotnet\sdk]
      3.0.100-rc1-014190 [C:\Program Files (x86)\dotnet\sdk]
      3.1.201 [C:\Program Files (x86)\dotnet\sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.All 2.2.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.2.8 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.App 2.2.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.2.8 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 3.0.0-rc1.19457.4 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 3.1.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 3.1.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 3.1.10 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 5.0.1 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 2.2.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.2.8 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 3.0.0-rc1-19456-20 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 3.1.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 3.1.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 3.1.10 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 5.0.1 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.WindowsDesktop.App 3.0.0-rc1-19456-20 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
      Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
      Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
      Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
      Microsoft.WindowsDesktop.App 5.0.0-rc.1.20452.2 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
      Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files (x86)\dotnet\shared\Microsoft.WindowsDesktop.App]
    
    To install additional .NET runtimes or SDKs:
      https://aka.ms/dotnet-download

    So the following PowerShell command should work for you:

    & 'C:\Program Files (x86)\dotnet\dotnet.exe' ef dbcontext scaffold "connection_string" --your-other-options

    Another option is to install the Microsoft Access Database Engine 2010 Redistributable in its x64 version (which is the last release that still supports Access 97 Jet databases) and then use either its new ODBC or OLE DB provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions