Calling Process.GetProcesses() inside a .NET Standard library from a UWP app

0

I have a .NET standard library which is below:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace process_library
{
    public class ProcessHandler
    {
        public ProcessHandler()
        {

        }

        [MTAThread]
        public Process[] GetProcesses()
        {
            return Process.GetProcesses();
        }
    }
}

I then have a Template10 project with all the .net core stuff updated to the latest version (required to get it to build) and referenced my library. This all works so far.

Inside my main view-model I instantiate my library class

ProcessHandler p = new ProcessHandler();

This is also successfull.

My problem is when I call my get process method it pukes and throws an error GenericParameterAttributes = '((System.RuntimeType)type).GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException'

Is there any way I can get this to work?

UPDATE Removed all the Template10 stuff as it tends to mask the real errors and tried a blank UWP app. Get this exception

System.PlatformNotSupportedException
  HResult=0x80131539
  Message=Retrieving information about local processes is not supported on this platform.

What is the point of including it in .net standard (Which is supposed to contain a standard set of apis you can use) if you cant even use it

I should also note I'm targeting the very latest update (Spring 2018)

c#
uwp
.net-core
.net-standard-2.0
asked on Stack Overflow May 3, 2018 by Steve Fitzsimons • edited May 3, 2018 by Steve Fitzsimons

1 Answer

0

Form official document, when you target a framework in an app or library, you're specifying the set of APIs that you'd like to make available to the app or library. You specify the target framework in your project file using Target Framework Monikers (TFMs).

When you specify multiple target frameworks, you may conditionally reference assemblies for each target framework. In your code, you can conditionally compile against those assemblies by using preprocessor symbols with if-then-else logic

public class MyClass
{
    static void Main()
    {
#if NET40
        Console.WriteLine("Target framework: .NET Framework 4.0");
#elif NET45  
        Console.WriteLine("Target framework: .NET Framework 4.5");
#else
        Console.WriteLine("Target framework: .NET Standard 1.4");
#endif
    }
}

ProcessHandler does not support in the UWP. In summary,the apis must be available to platform.

answered on Stack Overflow May 4, 2018 by Nico Zhu - MSFT

User contributions licensed under CC BY-SA 3.0