Do not strip resource messages if EventSource would use it (#81466)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Wed, 1 Feb 2023 21:28:43 +0000 (06:28 +0900)
committerGitHub <noreply@github.com>
Wed, 1 Feb 2023 21:28:43 +0000 (06:28 +0900)
Works around #81459.

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CustomAttributeBasedDependencyAlgorithm.cs

index 77b41a5..92b2925 100644 (file)
@@ -137,6 +137,21 @@ namespace ILCompiler.DependencyAnalysis
                         dependencies.AddRange(caDependencies);
                         dependencies.Add(factory.CustomAttributeMetadata(new ReflectableCustomAttribute(module, caHandle)), "Attribute metadata");
                     }
+
+                    // Works around https://github.com/dotnet/runtime/issues/81459
+                    if (constructor.OwningType is MetadataType { Name: "EventSourceAttribute" } eventSourceAttributeType)
+                    {
+                        foreach (var namedArg in decodedValue.NamedArguments)
+                        {
+                            if (namedArg.Name == "LocalizationResources" && namedArg.Value is string resName
+                                && InlineableStringsResourceNode.IsInlineableStringsResource(module, resName + ".resources"))
+                            {
+                                dependencies ??= new DependencyList();
+                                dependencies.Add(factory.InlineableStringResource(module), "EventSource used resource");
+                            }
+                        }
+                    }
+                    // End of workaround for https://github.com/dotnet/runtime/issues/81459
                 }
                 catch (TypeSystemException)
                 {