Home > Software engineering >  Error [MSB3246] after adding MySql.EntityFrameworkCore 7 to app in DotNetCore 6
Error [MSB3246] after adding MySql.EntityFrameworkCore 7 to app in DotNetCore 6

Time:02-03

Using EntityFramework7 on DotNetCore6 (also tried upgrading to DotNetCore7 and it didn't fix anything). Although the app compiles and seems to run fine, having warnings every build concerns me. When doing DotNet build the error is (repeated 5 times).

  Microsoft.Common.CurrentVersion.targets(2352, 5): [MSB3246] Resolved file has a bad image, no metadata, or is otherwise inaccessible. System.BadImageFormatException: PE image does not have metadata.
   at System.Reflection.Metadata.MetadataReader.GetAssemblyName(String assemblyFile)
   at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path)
   at Microsoft.Build.Tasks.SystemState.GetAssemblyName(String path)
   at Microsoft.Build.Tasks.ReferenceTable.SetPrimaryAssemblyReferenceItem(ITaskItem referenceAssemblyName)

Which confused me, since it didn't specify the file it was having problems with. Eventually when I went run publish on our CI server I got more useful information:

    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. System.BadImageFormatException: Could not load file or assembly '/home/jenkins/.nuget/packages/mysql.data/8.0.32/lib/net6.0/comerr64.dll'. The module was expected to contain an assembly manifest. [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246: File name: '/home/jenkins/.nuget/packages/mysql.data/8.0.32/lib/net6.0/comerr64.dll' [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246:    at System.Reflection.AssemblyName.nGetFileInformation(String s) [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246:    at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246:    at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path) [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246:    at Microsoft.Build.Tasks.ResolveAssemblyReference.<>c.<Execute>b__255_3(String p) [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246:    at Microsoft.Build.Tasks.SystemState.GetAssemblyName(String path) [/home/jenkins/workspace/dashboard/dashboard.csproj]
    /usr/share/dotnet/sdk/6.0.405/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3246:    at Microsoft.Build.Tasks.ReferenceTable.SetPrimaryAssemblyReferenceItem(ITaskItem referenceAssemblyName) [/home/jenkins/workspace/dashboard/dashboard.csproj]

Which made me realize that it was MySql that was the problem.

I tried downgrading to MySql.EntityFrameworkCore 6 but I get the same error. Removing MySql.EntityFrameworkCore (and switching to Microsoft.EntityFrameWorkCore.Sqlite) the error goes away. Is there anything that can be done about this or is it safe to ignore the errors.

CodePudding user response:

It seems this is a known bug in Oracle's drivers. The error suggests that a non-Linux binary was included in the build. Oracle's MySQL drivers have several known problems, which is why most developers use the truly open-source Pomelo.EntityFrameworkCore.MySql provider and the related MySqlConnector ADO.NET provider.

The open source driver fixes a lot of the serious problems in Oracle's drivers, in fact they make a point of it. For example, they reference this very bug with a fix. They also have a migration guide with a long list of fixed bugs

In the 7.0 wave, the Pomelo driver has 47K downloads while Oracles only 6.5K

  • Related