PLplotNet icon indicating copy to clipboard operation
PLplotNet copied to clipboard

Usage in .NET Core console applications

Open abrasat opened this issue 7 years ago • 4 comments

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.

abrasat avatar Oct 08 '19 12:10 abrasat

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

acrigney avatar May 06 '20 03:05 acrigney

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

DZFLUX avatar May 08 '20 20:05 DZFLUX

I see the same issue in .Net6

CODER-KRISH avatar Jul 24 '22 14:07 CODER-KRISH

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") 

cvizzini avatar Oct 25 '22 07:10 cvizzini