How to launch another app using protocol on .NET Core 3.0 WPF app

This post has been republished via RSS; it originally appeared at: Windows Dev AppConsult articles.

Updated at Apr 22, 2019

Updated to more better workaround written on comments, thank you  .


The body of this article

This article is as of .NET Core 3.0 Preview 3.


If you write a code in .NET Framework WPF app like as below:

Process.Start(""); // Open the URL using default browser

It works fine. However, in .NET Core 3.0, the code occurred following exception:


  Message=The system cannot find the file specified.

The cause of this issue, it is changing default value in UseShellExecute property at ProcessStartInfo class. .NET Framework is true, but .NET Core is false.

So, the workaround is following code:

Process.Start(new ProcessStartInfo("") { UseShellExecute = true });

It works fine.test.jpg


Happy coding!!


Old article

In this case, the workaround is to use Launcher.LaunchUriAsync method that is WinRT APIs.

At first, add following references to your project file.

  <PackageReference Include="System.Runtime.WindowsRuntime" Version="4.3.0" />

  <Reference Include="Windows">
    <HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd</HintPath>

And then, replace Process.Start to Launcher.LanuchUriAsync.

private async void FooButton_Click(object sender, RoutedEventArgs e)
    await Launcher.LaunchUriAsync(new Uri(""));

It works fine.👍




REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.