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)

Steve Fitzsimons
  • 3,754
  • 7
  • 27
  • 66
  • 1
    I don't think this is possible. Here's another link to a similar question with a chosen answer that states UWP runs in a sandboxed environment and can't access ```GetProcesses()``` https://social.msdn.microsoft.com/Forums/vstudio/en-US/487290bd-bbf1-456c-a599-f909791a198d/uwp-get-process-in-uwp?forum=wpdevelop – Michael Puckett II May 03 '18 at 18:05
  • Yes its not available in UWP but its available in .net standard 2.0 and i can use .net standard libraries in a UWP app – Steve Fitzsimons May 03 '18 at 18:07
  • 1
    The vast majority of functions in the .NET framework aren't available in tablet programs, even if they appear in the framework the "sandbox" environment they run in supresses almost all functions. Use a normal program instead. – Alejandro May 03 '18 at 18:16
  • This is interesting. I'm curious about this myself... I believe the idea is that it just compiles to any environment but you would think that if you used 'Standard' and it was universal that it would yell at you during compiling. – Michael Puckett II May 03 '18 at 20:08
  • That was the approach taken in the previous way to create portable class libraries. The more targets you added to your PCL project, the less code would compile. That did not make anybody happy either. – Hans Passant May 03 '18 at 22:14
  • Maybe I misunderstood from my reading. My understanding was that they added all these old APIs to .NET standard 2.0 and provided you targeted a min Windows version of the Fall creators update then you should be able to use them in any app. Sure what is the point of having a "standard" set of APIs in a portable class library when in fact you cant use them – Steve Fitzsimons May 03 '18 at 22:26

1 Answers1

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.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36