I have a asp.net app, using NLog. I can run it for x32 platform with success. But for x64 platform I get error on start:
BadImageFormatException Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format
I think, it is due to x32 version of NLog.dll, loaded with Nuget. I try to load NLog with Nuget for x64 platform, but always get only x32. Is it mean, than NLog has not x64 version of NuGet package in repo? And NLog is only example. My app depends by many such other packages as NJsonSchema.dll, System.Web.Razor.dll and other. But all of them have only x32 version in Nuget repo, Why? It is, obviously, system package from MS, why it hasn't x64 version? And is it mean, that I should build only x32 platform of my asp.net app?
Ok, let's try to validate this hypothesis. First, I create a new project using
dotnet new console, then I build it a few times,dotnet build,dotnet build -r win-x86,dotnet build -r win-x64. Then, I use ILSpy to inspect the dlls. For thewin-x64build, ILSpy tells me "// Architecture: x64". For thewin-x86build, ILSpy tells me "// Architecture: x86". And the build that did not specify a runtime, ILSpy tells me "// Architecture: AnyCPU (64-bit preferred)".Now, adding NLog as a PackageReference, and building, I get a nlog.dll in my bin directory, and opening it in ILSpy, I see "// Architecture: AnyCPU (64-bit preferred)".
Therefore, I conclude that NLog is not 32bit.
In case you do not find this sufficiently convincing, this is my Program.Main method:
Running this with
dotnet run,dotnet run -r win-x86anddotnet run -r winx64, I never see a crash, two of the three executions tell me the process was 64 bit, and one of them tells me the process is 32-bit. Since I'm using NLog to output that to the console, I'm confident that NLog is working in both instruction set architectures.In fact, building with
dotnet build -r linux-arm, copying the binaries to my Raspberry Pi, I can run this program, including nlog, on an ARM CPU.I don't know how you came to the conclusion that NLog, or other packages, are 32-bit only. I suggest you read StackOverflow's suggestion on how to create minimal, reproducable examples. When I do this, I often find the solution to the problem myself. When I do not find the solution myself, I have a small and simple example that other people can run on their own machines to verify the unexpected behaviour, and can help modify it to answer the question I asked. In any case, I can't reproduce the problem you're experiencing, and I hope my answer has convinced you that .NET libraries (that are compiled for AnyCPU) can work on any instruction set.