Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure to create GrpcChannel under Wine compatibility layer (including Steam Proton and Apple Game Porting Toolkit) #2496

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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