Skip to content

Commit

Permalink
Fix failure to create GrpcChannel under Wine compatibility layer (inc…
Browse files Browse the repository at this point in the history
…luding Steam Proton and Apple Game Porting Toolkit) (#2496)
  • Loading branch information
mayuki authored Jul 30, 2024
1 parent b34d553 commit 540e87b
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/Grpc.Net.Client/Internal/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,30 @@ internal static bool IsUwp(string frameworkDescription, Version version)
}
else
{
var bufferSize = 0U;
var result = GetCurrentApplicationUserModelId(ref bufferSize, Array.Empty<byte>());
switch (result)
try
{
case 15703: // APPMODEL_ERROR_NO_APPLICATION
return false;
case 0: // ERROR_SUCCESS
case 122: // ERROR_INSUFFICIENT_BUFFER
// Success is actually insufficient buffer as we're really only looking for
// not NO_APPLICATION and we're not actually giving a buffer here. The
// API will always return NO_APPLICATION if we're not running under a
// WinRT process, no matter what size the buffer is.
return true;
default:
throw new InvalidOperationException($"Failed to get AppModelId, result was {result}.");
var bufferSize = 0U;
var result = GetCurrentApplicationUserModelId(ref bufferSize, Array.Empty<byte>());
switch (result)
{
case 15703: // APPMODEL_ERROR_NO_APPLICATION
return false;
case 0: // ERROR_SUCCESS
case 122: // ERROR_INSUFFICIENT_BUFFER
// Success is actually insufficient buffer as we're really only looking for
// not NO_APPLICATION and we're not actually giving a buffer here. The
// API will always return NO_APPLICATION if we're not running under a
// WinRT process, no matter what size the buffer is.
return true;
default:
throw new InvalidOperationException($"Failed to get AppModelId, result was {result}.");
}
}
catch (EntryPointNotFoundException)
{
// Wine compatibility layers such as Steam Deck/Steam OS Proton and the Apple Game Porting Toolkit
// return Windows 8 or later as the OS version, but does not implement the GetCurrentApplicationUserModelId API.
return false;
}
}
}
Expand Down

0 comments on commit 540e87b

Please sign in to comment.