UWP build crashes when calling OpenURL, though the web page is loaded in the browser successfully. I can’t see any debugging info showing why this happens. Not specific to the URL: https://www.google.com triggers it as well.
Do you have a stacktrace for the crash? Can you report a bug?
I’m not the OP, but I have the same problem. Pretty simple, just an “Application.OpenURL(url)” call and it will open the browser, but it does then crash the game completely without a stack trace being sent through to the Unity logger (nothing in the UnityPlayer.log). I ran it through Visual Studio, and I am getting this as output when it crashes on my Windows 10 Pro development machine with OS build 19041.804. Project was built with Unity 2021.1.4f1
onecoreuap\drivers\mobilepc\sensors\convergence\api\winrt\public\internal\viewpositiontrackerinternal.cpp(269)\Windows.Devices.Sensors.dll!00007FFC1F852DC9: (caller: 00007FFC1F853347) Exception(3) tid(9b64) 80070490 Element not found.
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000CFBDEFD410.
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFCA7C6D759 (KernelBase.dll) in GameName.exe: WinRT originate error - 0x8001010E : 'The application called an interface that was marshalled for a different thread.'.
'GameName.exe' (Win32): Loaded 'C:\Windows\System32\userenv.dll'. Symbol loading disabled by Include/Exclude setting.
'GameName.exe' (Win32): Loaded 'C:\Windows\System32\profext.dll'. Symbol loading disabled by Include/Exclude setting.
onecoreuap\drivers\mobilepc\sensors\convergence\api\winrt\public\internal\viewpositiontrackerinternal.cpp(143)\Windows.Devices.Sensors.dll!00007FFC1F8543D0: (caller: 00007FFC1F853C8B) Exception(4) tid(9b64) 8001010E The application called an interface that was marshalled for a different thread.
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000CFBDEFD410.
The thread 0x8f34 has exited with code 0 (0x0).
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecoreuap\drivers\mobilepc\sensors\convergence\api\winrt\public\internal\sensor.cpp(184)\Windows.Devices.Sensors.dll!00007FFC1F7B37FD: (caller: 00007FFC1F7B3FCD) Exception(5) tid(9b64) 80070490 Element not found.
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: wil::ResultException at memory location 0x000000CFBDEFD7D0.
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
onecoreuap\drivers\mobilepc\sensors\convergence\api\winrt\public\internal\sensorserver.cpp(74)\Windows.Devices.Sensors.dll!00007FFC1F7B2E23: (caller: 00007FFC1F7FDA61) ReturnHr(3) tid(9b64) 80070490 Element not found.
Exception thrown at 0x00007FFCA7C6D759 in GameName.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x000000CFBDEFE7A0.
The thread 0x87ec has exited with code 0 (0x0).
The thread 0x85ec has exited with code 0 (0x0).
The thread 0x8ff4 has exited with code 0 (0x0).
The thread 0x97d4 has exited with code 0 (0x0).
Exception thrown at 0x00007FFCAA25052A (ntdll.dll) in GameName.exe: 0xC0000008: An invalid handle was specified.
Exception thrown at 0x00007FFCAA25052A (ntdll.dll) in GameName.exe: 0xC0000008: An invalid handle was specified.
Exception thrown at 0x00007FFCAA25052A (ntdll.dll) in GameName.exe: 0xC0000008: An invalid handle was specified.
Exception thrown at 0x00007FFCAA25052A (ntdll.dll) in GameName.exe: 0xC0000008: An invalid handle was specified.
onecore\com\combase\dcomrem\preventrundownbias.cpp(1310)\combase.dll!00007FFCA937219C: (caller: 00007FFCA9371FC9) LogHr(1) tid(97cc) 80070005 Access is denied.
The thread 0x89dc has exited with code 0 (0x0).
The thread 0x3a0 has exited with code 0 (0x0).
The thread 0x8558 has exited with code 0 (0x0).
'GameName.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Energy.dll'. Symbol loading disabled by Include/Exclude setting.
The thread 0x9a70 has exited with code 0 (0x0).
'GameName.exe' (Win32): Loaded 'C:\Windows\System32\Windows.System.Launcher.dll'. Symbol loading disabled by Include/Exclude setting.
'GameName.exe' (Win32): Loaded 'C:\Windows\System32\msvcp110_win.dll'. Symbol loading disabled by Include/Exclude setting.
Exception thrown at 0x00007FFC19F0BE64 (UnityPlayer.dll) in GameName.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
FWIW, since I already was using the WSANative package, I switched to using “WSANativeLauncher.LaunchUri(url);” for UWP, and that works great with no problems at all. Clearly there is a bug in Unity causing this crash, which seems to be around trying to release an invalid reference.
Does this repro with any URL? Say Application.OpenURL(“https://google.com”)?
Yes, last time I was testing it. Could submit as a bug but tbh not had the time. Just make a simple app with a button calling OpenURL. Crashes every time, no matter what the URL.
I’m running into this as well. Any info when it will be resolved?
I don’t think we ever received a bug report. Can you report one?
I tried to make a test project, but it doesn’t seem to crash there.
I am also experiencing this error when testing on a TOUGHPAD. The app will take me to the link, but then crashes when I try to return to the application. I’m on Unity v2020.3.15f1.
(Case 1382236) - Application.OpenURL(url) causes crash on UWP opened up as we are also getting this
Thanks we’ll take a look!
What could be another possible workaround with this?? System.Diagnostics.Process.Start() doesnt seem to work either…
You could use Windows.System.Launcher.LaunchUriAsync. Application.OpenURL on UWP is just a wrapper around it.
Okok. I’m trying with this:
#if (ENABLE_WINMD_SUPPORT || UNITY_WSA || UNITY_WSA_10_0)
using System;
using System.Threading.Tasks;
using UnityEngine;
namespace Util
{
public static class UWPStartUriProcess
{
public static async Task Start(string URL)
{
try
{
var options = new Windows.System.LauncherOptions();
options.TreatAsUntrusted = true;
var success = await Windows.System.Launcher.LaunchUriAsync(URL, options);
if (success)
{
Debug.LogError("Opened - " + URL);
}
else
{
Debug.LogError("Failed to open - " + URL);
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError("Failed to open URL: " + e);
}
}
}
}
#endif
I get the following error when building UWP: Assets\Scripts\Utils\UWPStartUriProcess.cs(14,72): error CS1503: Argument 1: cannot convert from ‘string’ to ‘System.Uri’
Do you know what could be going on?
Can I ask from where did you get that WSANative package?
You need to construct the URI using “new Uri(URL)” and pass that to the Windows API.
@AlfEspinosaN I think he’s referring to this asset