You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the following code, with .NET SDK 6.0.100-preview.5.21302.13:
using System;using System.Collections.Generic;using System.Diagnostics.CodeAnalysis;using System.Reflection;namespaceDemoTrimmedApp{classProgram{staticvoidMain(){foreach(var type in SuperHandyReflectionUtil.GetTypeNames()){
Console.WriteLine(type);}}}classEligibleForTrimming{}classAlsoEligibleForTrimming{}[RequiresUnreferencedCode("pretending for a moment that we do something more dynamic")]classSuperHandyReflectionUtil{publicstaticIEnumerable<string>GetTypeNames(){foreach(var type in Assembly.GetCallingAssembly().GetTypes()){yieldreturn type.Name;}}}}
I would expect that there would be no warnings from within SuperHandyReflectionUtil about using reflection, and a warning in Program.Main that I am calling code that has the RequiresUnreferencedCode attribute.
Instead, I get the following singular warning, which is the exact same warning I get when RequiresUnreferencedCode is not present at all (i.e when deleted or commented out):
warning IL2026: Using method 'System.Reflection.Assembly.GetTypes()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed.
It would appear that even though the attribute has AttributeTargets.Class, it only has an effect when applied to every individual method or constructor within said class that requires it.
The text was updated successfully, but these errors were encountered:
Given the following code, with .NET SDK 6.0.100-preview.5.21302.13:
and given this simple project file:
I would expect that there would be no warnings from within
SuperHandyReflectionUtil
about using reflection, and a warning inProgram.Main
that I am calling code that has theRequiresUnreferencedCode
attribute.Instead, I get the following singular warning, which is the exact same warning I get when
RequiresUnreferencedCode
is not present at all (i.e when deleted or commented out):It would appear that even though the attribute has
AttributeTargets.Class
, it only has an effect when applied to every individual method or constructor within said class that requires it.The text was updated successfully, but these errors were encountered: