System.BadImageFormatException after installing my nuget

Thurman, Allen 96 Reputation points
2021-03-30T11:30:03.28+00:00

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)

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,960 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2021-03-31T03:05:44.713+00:00

    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.**