BadImageFormatException on ServiceStack.OrmLite.MySql > 6.5.1

Hi,

Since ServiceStack.OrmLite.MySql 6.6+, I’ve been unable to build my project. I get the following error:
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)

While all my other packages are now on 6.8.1, I can only get the build to work if I use v6.5.1 of the OrmLite.MySql package.

Any idea what might be causing this? I’m developing on a Mac (M1), using .net 7+.

Thanks,
Melle

First time I’ve seen this for MySql. Are you sure you’re using v6.5.1 as there’s no such version on NuGet:

https://www.nuget.org/packages/ServiceStack.OrmLite.MySql

There would’ve been a temporary pre-release version on MyGet whilst v6.6 was in development, but that gets replaced when v6.6 was released.

Do you have issues trying to use MySql on a new empty project?

Hi @mythz,

Thanks for the quick reply. Yes, I am definitely using 6.5.1, it is still in my local NuGet packages.

Hadn’t tried a new empty project before. Just gave it a quick try with:
x new web MySQLEmpty && cd MySQLEmpty && x mix -f mysql

The project was created with .net6, and is referencing 6.8.0:
<PackageReference Include="ServiceStack.OrmLite.MySql" Version="6.8.0" />

When I try to build, I still get the same error:
2>------- Started building project: MySQLEmpty 2>/usr/local/share/dotnet/sdk/7.0.102/Microsoft.Common.CurrentVersion.targets(2352,5): Warning 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)
… and a few more repetitions of that same warning.

The build completes with only these warnings. But on any page where I try to query MySQL, I only get errors.

Any output I could produce to help find the culprit?

Thanks again,
Melle

Can you try forcing the project to use .NET 6 by adding a global.json at the root folder of your solution:

{
  "sdk": {
    "version": "6.0.100"
  }
}

Where the “version” is replaced with a 6.0.* that’s returned from:

$ dotnet --list-sdks

then try rebuilding the solution again.

Still warnings, but this time a little more helpful, I believe:
2>/usr/local/share/dotnet/sdk/6.0.404/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 '/Users/melle/.nuget/packages/mysql.data/8.0.32/lib/net6.0/comerr64.dll'. The module was expected to contain an assembly manifest. File name: '/Users/melle/.nuget/packages/mysql.data/8.0.32/lib/net6.0/comerr64.dll' at System.Reflection.AssemblyName.nGetFileInformation(String s) at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path) at Microsoft.Build.Tasks.ResolveAssemblyReference.<>c.<Execute>b__255_3(String p) at Microsoft.Build.Tasks.SystemState.GetAssemblyName(String path) at Microsoft.Build.Tasks.ReferenceTable.SetPrimaryAssemblyReferenceItem(ITaskItem referenceAssemblyName)

Looks like MySQL.data might actually be the problem?

Just tried manually adding MySql.Data v8.0.32.1 (rather than the implied 8.0.32.0), and it builds without warnings! Is that version dependency a reference from ServiceStack.OrmLite.MySql, or is that something from my machine specifically?

Good to hear, MySql.Data must have issues running on M1, our NuGet packages don’t include any native .dlls so it shouldn’t be able to cause any BadImageFormatException which can happen when trying to run native binaries on a different architecture it was built for.

“8.0.32” is just what OrmLite.MySql references which NuGet default behavior of using the minimum version resolves to, but you can force it to use a different version by explicitly including the dependency in your .csproj:

<PackageReference Include="MySql.Data" Version="8.0.32.1" />

But I’ve just deployed a new v6.8.1 on MyGet which now references MySql.Data v8.0.32.1 which is now available on MyGet where you wont need an explicit MySql.Data dependency.

1 Like