DirectXTexNet
DirectXTexNet copied to clipboard
System.TypeInitializationException
Hello,
maybe I am missing something, but creating a new console app project (net5.0) in VS, and adding DirectXTexNet as nuget, TexHelper throws that execption:
BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
I double checked, it identifies the correct runtime (x64) and gets the correct file (runtimes\win-x64\native\DirectXTexNetImpl.dll).
What could be the problem? Thanks
When using the latest version of the nuget package (1.0.2), which is compiled as a .NET 5 mixed assembly, you also need to make sure the Ijwhost.dll file is found not just the DirectXTexNetImpl.dll. Might that be your problem?
But normally this should work without any special adjustments needed. I've attached a simple test project: ConsoleApp12.zip Does this work on your system? If it does, you can compare it with your project.
When using the latest version of the nuget package (1.0.2), which is compiled as a .NET 5 mixed assembly, you also need to make sure the Ijwhost.dll file is found not just the DirectXTexNetImpl.dll. Might that be your problem?
But normally this should work without any special adjustments needed. I've attached a simple test project: ConsoleApp12.zip Does this work on your system? If it does, you can compare it with your project.
Hello, thanks for the quick reply. I just tested it and it throws the same error as my test sln (which is pretty much identical to yours anyway). I tested it on AnyCPU, x64. and also with dotent publish on release and debug. same results each time.
hmm... that's very strange. I get the same error message when I delete the Ijwhost.dll Is this file copied to output on your system? Is your Visual Studio up-to-date and do you have current vc redist version installed?
I've created a publish version of the test project. Please let me know if that works. publish.zip
I guess you mean run the exe in the publish.zip? that gives the same error...
I don't know if that could be the case, but I recently installed VS 2022. That's the only thing I can think of in relation to VS (I have the most recent version VS2019 16.10.3)
Is this file copied to output on your system?
yes, it's present in the /runtimes folders...
sadly I have no clue what's going on.
Try downgrading to version 1.0.1 of the DirectXTexNet nuget package which still uses a .NET Framework mixed assembly (no Ijwhost.dll) but it works on .NET 5.0 as well.
Here is the test publish with 1.0.1: publish2.zip
same error :(
well thank you for your testing. This is quite annoying. I will try debugging some more. I just don't understand why the BadImage Exception is thrown, there clearly is no runtime or architecture problem...
Thanks again, If I find anything I'll post it here.
I think the whole system with .NET 5 and mixed assemblies might still be a bit wonky. Perhaps check if it works when you use .NET Framework instead. Here is a publish for .NET Framework: publish3.zip
I think the whole system with .NET 5 and mixed assemblies might still be a bit wonky. Perhaps check if it works when you use .NET Framework instead. Here is a publish for .NET Framework: publish3.zip
hmm, different error,
System.TypeInitializationException: The type initializer for 'DirectXTexNet.TexHelper' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'DirectXTexNetImpl.dll' or one of its dependencies. The specified module could not be found.
not sure if it's a problem with the published app or my system. Filenotfound is different though
try compiling that test project yourself. Here is the code: ConsoleApp12b.zip Perhaps you get any hints from VS. If that doesn't help you might use ILSpy https://github.com/icsharpcode/ILSpy/releases/download/v7.1/ILSpy_binaries_7.1.0.6543.zip to have a look at the DirectXTexNetImpl.dll
As a last resort you can also try building DirectXTexNet yourself, perhaps that produces any insight.