.NET 5.0 published winforms application return System.BadImageFormatException on db access
See original GitHub issueAfter updating winforms core 3.1 app with linq2db reference to net5.0 (need the ability to deploy through clickonce) and publishing to folder (without clickonce) and after running that app I see System.BadImageFormatException
on any db access.
All db queries works when on debug.
db: MSSQL
linq2db version: 3.1.6
publish target framework: net5.0-windows
target runtime: win-x64 and win-x86 - reproduced for both
stacktrace:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
at System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)
at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrentNative()
at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent()
at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.OpenAsync(CancellationToken cancellationToken)
-- End of stack trace from previous location ---
at LinqToDB.Data.DataConnection.EnsureConnectionAsync(CancellationToken cancellationToken)
Also, when I’ve published that app via clickonce, installing it and trying to start I see the following entry in the Windows Application Event Log after crash:
An assembly specified in the application dependencies manifest (TestApp.deps.json) was not found:
package: 'runtime.win-x64.runtime.native.System.Data.SqlClient.sni', version: '4.4.0'
path: 'runtimes/win-x64/native/sni.dll'
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
"An attempt was made to load a program with an incorrect ...
I received "BadImageFormatException" that normally occurs when you mix platform targets (for example using a dll file compiled in X64 in an ...
Read more >BadImageFormatException Class (System)
The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.
Read more >How to fix System.BadImageFormatException
I have a project with a method that uses a DLL from another project. It used to work just fine, but now when...
Read more >Deployment Troubleshooting Guide
This topic provides a list of common deployment problems and ways of resolving them. It is assumed that the application runs normally at...
Read more >All .Net Exceptions List
AppDomainUnloadedException. The exception that is thrown when an attempt is made to access an unloaded application domain. throw [System.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Glad to help how I can! I’m sure we’ll see plenty of these friction bugs over the next couple months. Hopefully they won’t take too long to wash out.
Download this repo here: https://github.com/viceroypenguin/l2db-publish-net50
If that doesn’t work, then there’s a problem with the build/publish system on your machine; I’d suggest a repair of Visual Studio/reinstall of .net5.0
If that does work, then there’s a dependency management problem. Try restoring packages? Or open the package manager console and execute
Update-Package -Reinstall
. The first should work, the second forces VS to refresh the dependency chain. Hopefully that will help it to recognize the issues.