Can't run a registered-protocol-process from .net core, but can from .net framework

Viewed 45

The following code successfully starts a Teams meeting on .net framework, but throws a System.ComponentModel.Win32Exception (The system cannot find the file specified.) when ran on .net core:

using System;

namespace TryToRunMsteams
{
    class Program
    {
        static void Main(string[] args)
        {
            var msg = "msteams://teams.microsoft.com/l/meetup-join/19%3ameeting_NTIyYmU4ZG...";
            System.Diagnostics.Process.Start(msg);
        }
    }
}

Why is that? it's the same user in both (checked with Environment.UserName).

How can I run a registered-protocol process in .net core?

1 Answers

Can't run a registered-protocol-process from .net core, but can from .net framework

The main reason for this is because you're targeting multiple platforms, not just .NET framework. When targeting the .NET framework the standard Process.Start will work as you've seen.

 var msg = "msteams://teams.microsoft.com/l/meetup-join/19%3ameeting_NTIyYmU4ZG...";
 System.Diagnostics.Process.Start(msg);

To address starting a process in .NET Core please see below syntax for this.

 var msg = "msteams://teams.microsoft.com/l/meetup-join/19%3ameeting_NTIyYmU4ZG...";
 System.Diagnostics.Process.Start("cmd", $"/C start {msg}");

Another option you do have (wont fix your issue) is checking the platform in which you are running from. Could be useful if needed to perform specific operations based on platform. *Please note this requires System.Runtime.InteropServices namespace.

 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 {
    // Do something for Windows
 }
Related