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

Remove usage of FormatterServices.GetUninitializedObject as it is obsolete in .NET9 #3003

Open
mo-russo opened this issue Dec 3, 2024 · 0 comments

Comments

@mo-russo
Copy link

mo-russo commented Dec 3, 2024

https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0050#workaround

From the page above, we should update the JsonObjectContract.GetUninitializedObject() function to use the following code:

internal object GetUninitializedObject()
{
    // we should never get here if the environment is not fully trusted, check just in case
    if (!JsonTypeReflector.FullyTrusted)
    {
        throw new JsonException("Insufficient permissions. Creating an uninitialized '{0}' type requires full trust.".FormatWith(CultureInfo.InvariantCulture, NonNullableUnderlyingType));
    }

#if NET5_0_OR_GREATER
    return System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(NonNullableUnderlyingType);
#else
    return System.Runtime.Serialization.FormatterServices.GetUninitializedObject(NonNullableUnderlyingType);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant