4

I am trying to start an URL with an Unicode symbol using Process.Start() but it gives mit a Win32Exception:

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll

Additional information: Das System kann die angegebene Datei nicht finden 

(English: "The system can not find the file specified")

The URL I am trying to call is http://.la (this is a valid url, at least for Firefox 38)

After @Codo 's Suggestion I altered my code to this:

string link = "http://.la";
try
{
    Process.Start(link);
}
catch (System.ComponentModel.Win32Exception)
{
    Process.Start("IExplore.exe", link);
}
Florian-Rh
  • 777
  • 8
  • 26
  • Have you tried URL escape format? %F0%9F%92%A9 (http://graphemica.com/%F0%9F%92%A9) – joppiesaus Sep 14 '15 at 11:54
  • You could have chosen less "offending" characters for your example ;-) but anyway. You could always use [punycode](https://en.wikipedia.org/wiki/Punycode) and feed that into APIs you call. – Christian.K Sep 14 '15 at 11:54
  • Process.Start("http://.la"); works just fine. You are doing it wrong, we can't see you doing it wrong. Use capital U to encode unicode codepoints in the upper bit plans. – Hans Passant Sep 14 '15 at 11:56
  • @GuyMontag, Both of the following work fine for me on Windows 8.1 and IE 11 (11.0.9600): `Process.Start("http://xn--ls8h.la/");` or `Process.Start("IExplore.exe", "http://xn--ls8h.la/");`. What is your version of Windows and IE? – Dmytro Shevchenko Sep 15 '15 at 10:09
  • That's Windows 7 Enterprise (64Bit, SP1) and IE 11 – Florian-Rh Sep 15 '15 at 16:15

2 Answers2

4

Don't let Firefox fool you. Unicode characters beyond the ASCII codes and in particular emojis aren't allowed in a URL; they need to be encoded. Firefox is user-friendly, accepts them, displays them but automatically encodes them once it executes the request.

If the Unicode character is in the domain name, it needs to be Punycode encoded. If the Unicode character is after the domain name, it needs to be URL encoded.

The effective URL for your case is: http://xn--ls8h.la/

Codo
  • 75,595
  • 17
  • 168
  • 206
  • Hi, thank you so far, thats good to know. Unfortunately `Process.Start("http://xn--ls8h.la/")` produces the same error (maybe tries to convert punycode and ends up with the same url as before...?) – Florian-Rh Sep 14 '15 at 12:46
  • Can you open any URL at all with your code? Is it really related to emojis? – Codo Sep 14 '15 at 13:00
  • It is related to the emoji, that is for sure. I can provide a code sample but any url works fine (even emoticons in path such as: https://en.wikipedia.org/wiki/). But emoticons in the domain name produce the exception – Florian-Rh Sep 14 '15 at 13:07
  • What version of Windows are you using? And what is your default browser? Other people have similar issues, though not specifically related to emojis. Have you tried http://stackoverflow.com/a/20509782/413337 ? – Codo Sep 14 '15 at 15:20
  • This is Windows 7 Enterprise and the default browser is Firefox. I will try the solution you linked tomorrow. Thanks in advance – Florian-Rh Sep 14 '15 at 18:29
  • All right, when I try `Process.Start("IExplore.exe", link)` (with either punycode-link or emoji), Internet Explorer is started but the default site is displayed. Other Hyperlinks with emojis in the path work fine... – Florian-Rh Sep 15 '15 at 06:56
0

Try these:

http://xn--ls8h.la/ (Punycode)

http://%F0%9F%92%A9.la/ (URL Escape Code)

Take a look at RFC 3986. URLs can only consist of US-ASCII characters.

Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67