Skip to content

Usage in .NET Core console applications #6

Open

Description

@abrasat

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.

Activity

  1. acrigney commented on May 6, 2020

    @acrigney

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

  2. DZFLUX commented on May 8, 2020

    @DZFLUX

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

  3. geeky-krish commented on Jul 24, 2022

    @geeky-krish

    I see the same issue in .Net6

  4. cvizzini commented on Oct 25, 2022

    @cvizzini
    Contributor

    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") 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions