question

ThurmanAllen-0353 avatar image
0 Votes"
ThurmanAllen-0353 asked ThurmanAllen-0353 answered

System.BadImageFormatException after installing my nuget

Hello All, I have my own solution that builds a .dll (mytest.dll). I then pack the .dll for referencing into a nuget package using a .nuspec file. When doing this process on my laptop, I can install the nuget into a test app and create objects from the nuget in the code no problem.

Testing on my build machine, which is Windows Server 2012 R2, I do this same process but after installing the nuget and trying to run my test app I get a runtime exception:

System.BadImageFormatException: 'Could not load file or assembly 'mytest.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)'

Any ideas on what to check on the Windows Server machine? Note: 1. Both machines have Visual Studio 2019 used to build 2. I use nuget.exe from the command line to pack the nuget (nuget update --self before packing)

vs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ThurmanAllen-0353 avatar image
0 Votes"
ThurmanAllen-0353 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DylanZhu-MSFT avatar image
0 Votes"
DylanZhu-MSFT answered ThurmanAllen-0353 commented

Hi ThurmanAllen,

You can have a try to re-compile your dll to "Any CPU" instead of "x86".

Best Regards,
Dylan


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am using x64 and I have to use that because the client app that will use the nuget is x64

0 Votes 0 ·
DylanZhu-MSFT avatar image DylanZhu-MSFT ThurmanAllen-0353 ·

Hi @ThurmanAllen-0353 , did you try to directly add this dll as reference in your project? Then confirm if it can work.

0 Votes 0 ·

I did try that got the same error during run time.... As is. I update to a new issue....


https://docs.microsoft.com/en-us/answers/questions/340969/badimageformatexception-building-c-dll-in-server-2.html

0 Votes 0 ·