surban / PLplotNet

PLplot bindings for .Net
https://surban.github.io/PLplotNet
Other
35 stars 12 forks source link

Usage in .NET Core console applications #6

Open abrasat opened 5 years ago

abrasat commented 5 years ago

The PLStream constructor throws an exception when called from a .NET Core 3.0 console application.

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'PLplot.Native' threw an exception. Source=PLplotNet StackTrace: at PLplot.Native.mkstrm(Int32& p_strm) at PLplot.PLStream..ctor() in C:...\PLStream.cs:line 24 at SineWaves.Program.Main(String[] args) in C:...\Program.cs:line 56

Inner Exception 1: InvalidOperationException: Cannot find support PLplot support files in System.String[].

If called from a .NET Core 2.0 console application it works fine. I tested with the SineWaves console application from the c# samples.

acrigney commented 4 years ago

I get the same problem with .net core 3.1 and with .net 2.0

DZFLUX commented 4 years ago

I see the same issue on 3.x and works fine 2.2 for me.

Coder-Krish commented 2 years ago

I see the same issue in .Net6

cvizzini commented 2 years ago

I experienced the same issue It seems like plplot dlls and fonts are not being loaded correctly in the NativeHelper.cs:

    // The NuGet package ships with the PLplot DLLs and supporting font and
    // color map files. These files get installed into the directory "plplot", 
    // either relative to the application main executable (if published),
    // or are located in the "runtimes/win-x64/native" folder of the NuGet package.
    // For PLplot to find its support files, the environment variable 
    // PLPLOT_LIB must be set accordingly.                
    string[] supPaths = {
        Path.Combine(libDir, "plplot"), 
        Path.Combine(libDir, "..", "..", "runtimes", "win-x64", "native", "plplot") 
    };
    string supPath = supPaths.FirstOrDefault(p => Directory.Exists(p));
    if (supPath != null) {                   
        _putenv_s("PLPLOT_LIB", supPath);
    } else {
        throw new InvalidOperationException($"Cannot find support PLplot support files in {supPaths}.");
    }

This was looking in the directories: {NugetPath}\plplot and {NugetPath}\..\..\runtimes\win-x64\native\plplot

Or when compiling locally {ProjectPathBinDirectory}\plplot and {ProjectPathBinDirectory}\..\..\runtimes\win-x64\native\plplot

supPath would always be null and therefore throw exception.

To resolve it locally, I changed the second supPath location to

    Path.Combine(libDir, "runtimes", "win-x64", "native", "plplot")