Adjust workaround for event source resource stripping (#81528)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 6 Feb 2023 23:54:55 +0000 (08:54 +0900)
committerGitHub <noreply@github.com>
Mon, 6 Feb 2023 23:54:55 +0000 (08:54 +0900)
The used approach only worked in debug builds. `InlineableStringResource` is not one of the nodes that survives from scanning phase to compilation phase. Make the compiler think `GetResourceString` was reflected on instead.

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

index 92b2925..ef0035d 100644 (file)
@@ -147,7 +147,11 @@ namespace ILCompiler.DependencyAnalysis
                                 && InlineableStringsResourceNode.IsInlineableStringsResource(module, resName + ".resources"))
                             {
                                 dependencies ??= new DependencyList();
-                                dependencies.Add(factory.InlineableStringResource(module), "EventSource used resource");
+                                var accessorMethod = module.GetType(
+                                    InlineableStringsResourceNode.ResourceAccessorTypeNamespace,
+                                    InlineableStringsResourceNode.ResourceAccessorTypeName)
+                                    .GetMethod(InlineableStringsResourceNode.ResourceAccessorGetStringMethodName, null);
+                                dependencies.Add(factory.ReflectedMethod(accessorMethod), "EventSource used resource");
                             }
                         }
                     }