deng0 / DirectXTexNet

A .NET wrapper for the DirectXTex library.
Other
25 stars 10 forks source link

DirectXTexNetImpl won't load when publishing as a single file #7

Closed Wildenhaus closed 2 years ago

Wildenhaus commented 2 years ago

It seems that DirectXTexNet.cs is written in such a way that it's always expecting the DLL to be loaded from a file. However, when publishing an app and using the "Produce single file" option, it appears that DirectXTexNetImpl.dll is being included in the single file (Ijwhost.dll is not).

I tried to rectify this by just including the DLL in the same directory, but then something odd started happening. Consider this code:

  var path = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "DirectXTexNetImpl.dll" );
  var exists = File.Exists( path ); // Evaluates to True
  Activator.CreateInstance( Assembly.LoadFile( path ).GetType( "DirectXTexNet.TexHelperImpl" ) );

The file exists, but Assembly.LoadFile() is throwing a FileNotFoundException. Not sure what the deal is, but I thought I'd report it.

deng0 commented 2 years ago

Haven't really used single file publishes before.

But I think the best solution is to set IncludeAllContentForSelfExtract when doing the publish. That way the required native/mixed DLLs should be included.

You can set it in your csproj or in your PublishProfile like this: <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>

Alternatively setting it in the CLI like this should also work: dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true

Let me know if this solve your problem.

Wildenhaus commented 2 years ago

That appears to have resolved the issue. Thank you!

mgpreston commented 2 years ago

For anyone else running into this, there's an issue tracking it here: https://github.com/dotnet/runtime/issues/45084