Synchronize SR.cs (#35830)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Tue, 5 May 2020 13:34:14 +0000 (15:34 +0200)
committerGitHub <noreply@github.com>
Tue, 5 May 2020 13:34:14 +0000 (06:34 -0700)
Ports .NET Native change https://github.com/dotnet/corert/commit/0ac83cb8d6f9ab10df616a608fcf6fdfa6eabe2b to the Runtime repo.

src/libraries/System.Private.CoreLib/src/System/SR.cs

index fff60a9..e70d618 100644 (file)
@@ -15,6 +15,10 @@ namespace System
     {
         // This method is used to decide if we need to append the exception message parameters to the message when calling SR.Format.
         // by default it returns false.
+        // Native code generators can replace the value this returns based on user input at the time of native code generation.
+        // Marked as NoInlining because if this is used in an AoT compiled app that is not compiled into a single file, the user
+        // could compile each module with a different setting for this. We want to make sure there's a consistent behavior
+        // that doesn't depend on which native module this method got inlined into.
         [MethodImpl(MethodImplOptions.NoInlining)]
         private static bool UsingResourceKeys()
         {
@@ -29,6 +33,9 @@ namespace System
 
         internal static string GetResourceString(string resourceKey, string? defaultString)
         {
+            if (UsingResourceKeys())
+                return defaultString ?? resourceKey;
+
             string? resourceString = null;
             try { resourceString = InternalGetResourceString(resourceKey); }
             catch (MissingManifestResourceException) { }