Skip to content

Impossible to add a migration with efcore 10 when targeting net48 #37745

@mnivet

Description

@mnivet

Bug description

Using dotnet ef migrations add command with the --framework net48 option do not work with dotnet-ef version 10.0.2 nor 10.0.3

We have some projects that target both net10.0 and still net48
We were used to use the dotnet ef migrations add command with the --framework net48 option to produce code compatible with net48.

However now we migrate from EFCore8 to EFCore10 (10.0.2) we face an issue where it try to load ef assembly.

If we target net10.0 in the command it works, but the code produced for the ModelSnapshot do not compile on net48.

Your code

dotnet ef migrations add newmigration --context AppDbContext --project .\Repository\EFCore --framework net48

Stack traces

System.BadImageFormatException: Could not load file or assembly exception 'ef, Version=10.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' 
Filename : 'ef, Version=10.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at System.Runtime.Serialization.FormatterServices.LoadAssemblyFromString(String assemblyName)
   at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor..ctor(String assembly, String startupAssembly, String designAssembly, String project, String projectDir, String dataDirectory, String rootNamespace, String language, Boolean nullable, String[] remainingArguments, IOperationReportHandler reportHandler)
   at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor(String[] remainingArguments)
   at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)

Verbose output


EF Core version

10.0.2

Database provider

No response

Target framework

NetFramework

Operating system

Windows 11

IDE

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions