9

I am using .Net Core 3.1 Framework in WPF Application. I have a button event in which I am trying to redirect to Instagram url on click. but its giving me the following error.

Exception thrown: 'System.ComponentModel.Win32Exception' in System.Diagnostics.Process.dll.

private void Insta_Click(object sender, RoutedEventArgs e)
{
    try
    {
        string targetURL = "https://www.instagram.com/xyz/";
        Process.Start(targetURL);
    }
    catch
    {
    }
}
1
  • What is the exception message?
    – nalka
    Jan 13, 2020 at 12:43

1 Answer 1

25

You have to change you code per follows

var targetURL = "https://www.instagram.com/xyz/";
var psi = new ProcessStartInfo
{
    FileName = targetURL,
    UseShellExecute = true
};
Process.Start(psi);

UseShellExecute property is set to false in .NET Core by default, to open https:// link you have to set it to true, because it isn't an executable file

1
  • 2
    Thanks that solved my issue. I was missing UseShellExecute = true which I did not know about.
    – user11646025
    Jan 13, 2020 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy