0

I'm really interested in using .NET Core 2.x to write multiplatform programs in C#. I'm already into an experiment where I monitor and control processes using System.Diagnostics.Process.

That said, I believe I'm already working on a critical use-case, since it may be easy to require system-specific procedures that .NET Core still can't expose to the developer. It is still a concern without any practical case, but I'm thinking of tasks like:

  • Getting the number of physical+logical processors (on Windows, one should use WMI, that I don't believe it is available in .NET Core to do the same on MacOS/Linux).
  • Creating the memory dump of a crashed Process (OS-specific calls may be needed?)
  • In general anything that it is usually accomplished by C++ calls that are native to a specific OS

So I'm wondering how to approach these "future" issues. Is .NET Core / C# still a valid solution for my needs? Or is there a way to invoke OS-specific calls on a .NET Core 2.x project?

Note: for external reasons, I'm currently limited to use .NET Core 2.x branch, not 3.x.

TheUnexpected
  • 3,077
  • 6
  • 32
  • 62
  • 1
    The reason to use c# is the protection that is added by using managed features to prevent the computer from going Blue Screen. So the managed code is limited in the way memory is accessed. C++ allow much more access to memory. The best way of solving your issue is to write c++ wrappers (a custom dll) to perform the method you cannot access from core and then have your c# methods call the c++ wrappers. – jdweng Nov 11 '19 at 11:18
  • 1
    Thanks, is [P/Invoke](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke) the right way to do that from .NET Core? – TheUnexpected Nov 11 '19 at 11:23
  • 1
    The pinvoke are Windows dll that are standard interfaces independent of the operating system. So each version of Windows will have the same dll name but the code is different depending on the version of windows. So if you code is going to run on different operating systems using pinvoke will work. It most cases the Net Library are just wrappers calling the Windows dlls. So if CORE does not provide the methods using pinvoke is a good way of going. – jdweng Nov 11 '19 at 11:34

1 Answers1

1

Until you won't plan to use any MS GUI frameworks (Windows Forms, WPF, UWP), .NET Core can be a flexible and viable option on platforms other than Windows too.

One can use p/invoke to gain access to native methods, that should be working with .NET Core running on Unix-like systems too, although only the system-specific libraries will be available on each OS.

The RuntimeInformation.IsOSPlatform method and the conditional compilation symbols also can be used to branch the code for specific OSes.

Others already have an answer on how to get a dump from a .NET Core application.

Laszlo Lukacs
  • 61
  • 1
  • 5
  • 1
    Many thanks. For the record, I'm also looking for GUI frameworks and I've found [Avalonia](https://avaloniaui.net/) very promising. – TheUnexpected Nov 11 '19 at 11:36