weixin_39669202
weixin_39669202
2021-01-11 10:30

System.Diagnostic.Process.Start(...) does not Support mailto: protocoll

Porting a .Net Framework App to .Net Core 3.0, I was not able to invoke the default mail client with the mailto: protocoll using System.Diagnostics.Process.Start(...).

.Net Core 3.0.100-preview5-011568
Windows 10 1809
Outlook 2016

Sampe code to reproduce

c#
var body = "This is a body of a message";
var recipients = String.Join(",", "to.com", "alsoTo.com");
string mailto = $"mailto:{recipients}?Subject={"Subject of message"}&Body={body}";
mailto = Uri.EscapeUriString(mailto);
System.Diagnostics.Process.Start(mailto);

The Exception that occures: System.ComponentModel.Win32Exception: 'Das System kann die angegebene Datei nicht finden.' (Translated System can not find the file not sure if that is the actuall english error message)

该提问来源于开源项目:dotnet/runtime

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39818727 weixin_39818727 4月前

    In .NET Core the useshellexecute is set to false while in .NET Framework it's set to true. This is an undocumented breaking change. When porting .NET Framework to .NET Core you have to explicitly use ProcessStartInfo

    System.Diagnostics.Process.Start(new ProcessStartInfo(mailto) { UseShellExecute = true });

    点赞 评论 复制链接分享
  • weixin_39681644 weixin_39681644 4月前

    undocumented

    https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute

    "The default is true on .NET Framework apps and false on .NET Core apps."

    点赞 评论 复制链接分享
  • weixin_39818727 weixin_39818727 4月前

    undocumented

    https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.useshellexecute

    "The default is true on .NET Framework apps and false on .NET Core apps."

    Undocumented in terms of "not mentioned in the 'how to port your framework app to dot net core'" blog posts. In terms of "no red banner in the Process.Start docs". The sentence you quote is not highlighted and only exists in the docs of UseShellExecute.

    So yes, its documented. But also yes that it's pretty much unclear for most .NET Framework developers when porting their apps until they experience the issue and hopefully use the search function to figure it out. This is not the first "issue" about it and it will likely not be the last.

    点赞 评论 复制链接分享
  • weixin_39827850 weixin_39827850 4月前

    Closing, since this seems to be by design.

    点赞 评论 复制链接分享

相关推荐