Skip to content

[dotnet] Throw an exception if the developer tries to use server garbage collection. Fixes #16853. #20569

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

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,12 @@
<Error Condition="'$(_IsValidRuntimeIdentifier)' != 'true'" Text="The RuntimeIdentifier '$(RuntimeIdentifier)' is invalid." />
</Target>

<Target Name="_ValidateGarbageCollector"
Condition="'$(ServerGarbageCollection)' == 'true'"
BeforeTargets="Build;ResolvedFrameworkReference;ResolveRuntimePackAssets">
<Error Text=".NET for $(_PlatformName) does not support server garbage collection. Please don't set the 'ServerGarbageCollection' property." />
</Target>

<!-- This target can be removed in .NET 9 (when we stop supporting the compat logic to make the invalid TPV just a warning instead of an error) -->
<Target Name="_XamarinValidateTargetPlatformVersion"
BeforeTargets="Build;ResolvedFrameworkReference;ResolveRuntimePackAssets"
Expand Down
22 changes: 22 additions & 0 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ internal unsafe struct MTRegistrationMap {
}
#pragma warning restore 649

#if __TVOS__
internal const string PlatformName = "tvOS";
#elif __WATCHOS__
internal const string PlatformName = "watchOS";
#elif __MACCATALYST__
internal const string PlatformName = "Mac Catalyst";
#elif __IOS__
internal const string PlatformName = "iOS";
#elif __MACOS__
internal const string PlatformName = "macOS";
#else
#error Undetermined platform name
#endif

[Flags]
internal enum MTTypeFlags : uint {
None = 0,
Expand Down Expand Up @@ -359,6 +373,14 @@ unsafe static void Initialize (InitializationOptions* options)
throw ErrorHelper.CreateError (8010, msg);
}

#if NET
if (System.Runtime.GCSettings.IsServerGC) {
var msg = $".NET for {PlatformName} does not support server garbage collection.";
NSLog (msg);
throw ErrorHelper.CreateError (8057, msg);
}
#endif

#if NET
if (options->RegistrationMap is not null && options->RegistrationMap->classHandles is not null) {
ClassHandles.InitializeClassHandles (options->RegistrationMap->classHandles);
Expand Down
9 changes: 9 additions & 0 deletions tools/mtouch/Errors.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tools/mtouch/Errors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2266,4 +2266,9 @@
<data name="MX8056" xml:space="preserve">
<value>Failed to marshal the Objective-C object 0x{0} (type: {1}). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance of generic type {2}.</value>
</data>

<data name="MX8057" xml:space="preserve">
<value>.NET for {0} does not support server garbage collection.</value>
<comment>{0}: the platform (iOS, macOS, etc.)</comment>
</data>
</root>
Loading