Answered by:
BadImageFormatException

Question
-
User364663285 posted
Hi,
What is reason of issue below?
[BadImageFormatException: Could not load file or assembly 'RegRec2' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +21 System.Reflection.Assembly.Load(String assemblyString) +28 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
Thursday, May 6, 2021 9:32 AM
Answers
-
User1535942433 posted
Hi wmec,
A 64-bit version of the 'Microsoft Access Database Engine 2010 Redistributable' that will allow you to use the 'Microsoft.ACE.OLEDB.12.0' provider.
Best regards,
Yijing Sun
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 18, 2021 9:52 AM
All replies
-
User409696431 posted
It could be a mismatch between 32 and 64 bit applications and libraries.
You could also try a clean build to see if that clears it up.
See discussions at https://stackoverflow.com/questions/5229310/system-badimageformatexception-could-not-load-file-or-assembly
Thursday, May 6, 2021 6:26 PM -
User364663285 posted
Hi,
I did enable 32-bit application in Application Pool and what should be the reason now to this?
Friday, May 7, 2021 3:31 AM -
User1535942433 posted
Hi wmec,
As far as I think,you could check if your operations are right.
To enable 32bit mode, open IIS and select your Application Pool. Mine was named "ASP.NET v4.0". Right click, go to "Advanced Settings" and change the section named: "Enabled 32-bit Applications" to true. And then note: Restart your web server and try again.
The another way you could try:running cmd as administrator.
Best regards,
Yijing Sun
Friday, May 7, 2021 5:16 AM -
User364663285 posted
Hi,
Can you advise which one below I should ensure it is with 32-bit application?
https://1drv.ms/u/s!Ai8CrEskdewXvwVjLbkxDgpU6Ntf?e=PsgKcUFriday, May 7, 2021 7:23 AM -
User1535942433 posted
Hi wmec,
Have you published your application to iis? If you publish it to iis, what is the .NET framework version in your application pool? If it is v2.0, you need to set Enable 32-Bit Applications to True.
Best regards,
Yijing Sun
Friday, May 7, 2021 9:16 AM -
User364663285 posted
My application pool is with V4.0 below
https://1drv.ms/u/s!Ai8CrEskdewXvwadgAebjYMzsZAz?e=BjcbMVand I've also set 32-bit application to be true for all those of version V4.0
https://1drv.ms/u/s!Ai8CrEskdewXvwc30dQoZgqGNzOC?e=rWI3jDFriday, May 7, 2021 4:54 PM -
User1535942433 posted
Hi wmec,
If your .net version is 4.0, there is no need to set Enable 32-Bit Applications to true. Do you publish on iis or run it directly in VS? If it is in VS, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile.
Best regards,
Yijing Sun
Tuesday, May 11, 2021 7:16 AM -
User364663285 posted
Hi,
I changed project's Platform target property to x86 and have re-deployed project, and keep 32-Bit Applications to false for the items with .net version 4.0, and have re-started IIS, but same issue still exist.
Tuesday, May 11, 2021 8:53 AM -
User1535942433 posted
Hi wmec ,
The BadImageFormatException is raised when the assembly file can be found, but is not a proper assembly, or is corrupted. you can refer to this link to trouble this error:
https://docs.microsoft.com/en-us/dotnet/api/system.badimageformatexception?view=net-5.0
Best regards,
Yijing Sun
Wednesday, May 12, 2021 8:00 AM -
User364663285 posted
Hi,
Can you see problem to URL below?
http://www.myfavouriteeshop.com/RegRec2?id=18&user_abbr=mc2&readonly=n
Sunday, May 16, 2021 2:57 AM -
User1535942433 posted
Hi wmec,
As mentioned already it is due to wrong architecture either a) Using x64 assembly with Windows x86 b) Using x86 assembly with x64 process or viceversa
For best results, ensure all .NET assemblies are built with "Any CPU", and same .NET profile (ie all using .NET Core, or Client Profile or Full .NET).
...or one dependency not being found at all, Enable Fusion Log to tell where is looking to gather the assemblies:
https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net
https://www.hanselman.com/blog/back-to-basics-using-fusion-log-viewer-to-debug-obscure-loader-errors
Best regards,
Yijing Sun
Monday, May 17, 2021 9:37 AM -
User364663285 posted
Hi,
Thanks a lot.
It is now only having issue below[InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.]
Is this a version issue and server machine must be with 32-bit version of Microsoft.ACE.OLEDB.12.0?
Monday, May 17, 2021 7:28 PM -
User1535942433 posted
Hi wmec,
You need to install:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=13255
Best regards,
Yijing Sun
Tuesday, May 18, 2021 3:27 AM -
User364663285 posted
Hi,
I've set up 32 bit version (of ACE.OLEDB) but there is still error below[InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.] System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +258 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +497 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +100 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +57 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1142 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +312 System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +23 System.Data.OleDb.OleDbConnection.Open() +52
Tuesday, May 18, 2021 4:52 AM -
User1535942433 posted
Hi wmec,
A 64-bit version of the 'Microsoft Access Database Engine 2010 Redistributable' that will allow you to use the 'Microsoft.ACE.OLEDB.12.0' provider.
Best regards,
Yijing Sun
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 18, 2021 9:52 AM -
User364663285 posted
Hi,
Owing to issue belowhttps://1drv.ms/u/s!Ai8CrEskdewXwCtT9mpmRAwVAco8?e=nQIJd8
I cannot set up 64-bit AccessDatabaseEngine. In the past, it was OK to work with the same Office version. Would it be fine that I continue to use the same Office version?
Tuesday, May 18, 2021 11:36 PM -
User1535942433 posted
Hi wmec,
According to your description,your Target Platform is x86. The app will only run in a 32-bit process. And Microsoft Access Database Engine 2010 Redistributable fit 32-bit and 64bit. You need to install AccessDatabaseEngine.exe with 32-bit.
I found a same problem with the thread you have post.You could borrow.
https://forums.asp.net/t/2175956.aspx
Best regards,
Yijing Sun
Wednesday, May 19, 2021 7:09 AM -
User364663285 posted
Hi,
That thread is not OK. I've un-marked it.I've put True to Enable 32-bit Application, in Application Pools. But it is still the same issue below.
[InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.] System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +258 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +497 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +100 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +57 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1142 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +312 System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +23 System.Data.OleDb.OleDbConnection.Open() +52
Wednesday, May 19, 2021 8:19 AM