Linker.Steps\MarkStep.cs (148)
226 public AnnotationStore Annotations => Context.Annotations;
227 public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
228 public Tracer Tracer => Context.Tracer;
229 public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
245 Context.Pipeline.InitializeMarkHandlers (Context, MarkContext);
256 var coreLib = Context.TryResolve (PlatformAssemblies.CoreLib);
260 var xmlInfo = EmbeddedXmlInfo.ProcessAttributes (coreLib, Context);
267 Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes (provider, annotations);
270 Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add (ca, origin);
371 bool scanReferences = IsFullyPreservedAction (Context.TrimAction) || IsFullyPreservedAction (Context.DefaultAction);
376 foreach (var (assemblyName, action) in Context.Actions) {
380 var assembly = Context.GetLoadedAssembly (assemblyName);
398 var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies ().ToArray () : Context.GetAssemblies ();
484 Context.LogMessage ($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName ()}' method.");
528 bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type);
550 foreach (var assembly in Context.GetReferencedAssemblies ().ToArray ()) {
601 MarkType (type, new DependencyInfo (DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin (Context.TryResolve (iface.InterfaceType)));
666 if (!Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override))
690 if (Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated (overrideInformation.Override.DeclaringType)) {
694 Debug.Assert (!Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
719 => IsInterfaceImplementationMarkedRecursively (type, interfaceType, Context);
762 TypeDefinition? type = Context.Resolve (marshaler.ManagedType);
774 bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
785 var resolvedAttributeType = Context.Resolve (ca.AttributeType);
843 if (Context.CanApplyOptimization (CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly)) {
858 assembly = Context.TryResolve (dynamicDependency.AssemblyName);
860 Context.LogWarning (origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
870 type = DocumentationSignatureParser.GetTypeByDocumentationSignature (assembly, typeName, Context);
872 Context.LogWarning (origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
878 type = Context.TryResolve (typeReference);
880 Context.LogWarning (origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName ());
884 type = Context.TryResolve (context.DeclaringType);
886 Context.LogWarning (context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName ());
893 members = DocumentationSignatureParser.GetMembersByDocumentationSignature (type, memberSignature, Context, acceptName: true);
895 Context.LogWarning (origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName ());
900 members = type.GetDynamicallyAccessedMembers (Context, memberTypes);
902 Context.LogWarning (origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString (), type.GetDisplayName ());
943 Context.LogWarning (context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
945 if (!DynamicDependency.ShouldProcess (Context, ca))
951 assembly = Context.TryResolve (assemblyName);
953 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
963 td = Context.TryResolve (assemblyDef, typeName);
966 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1003 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName ());
1070 TypeDefinition? type = Context.Resolve (constructor_type);
1084 if (Context.KeepUsedAttributeTypesOnly) {
1102 TypeDefinition? type = Context.Resolve (attr_type);
1115 if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled (CodeOptimizations.BeforeFieldInit, type))
1176 TypeDefinition? type = Context.Resolve (security_type);
1206 var scanner = new AttributeDataFlow (Context, this, origin);
1219 type = Context.TryResolve (type.BaseType);
1243 var scanner = new AttributeDataFlow (Context, this, origin);
1256 type = Context.TryResolve (type.BaseType);
1270 type = Context.TryResolve (type.BaseType);
1284 var resolvedConstructor = Context.TryResolve (ca.Constructor);
1286 var scanner = new AttributeDataFlow (Context, this, origin);
1339 EmbeddedXmlInfo.ProcessDescriptors (assembly, Context);
1345 if (Context.StripSecurity)
1346 RemoveSecurity.ProcessAssembly (assembly, Context);
1348 MarkExportedTypesTarget.ProcessAssembly (assembly, Context);
1353 !Context.TryGetCustomData ("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1469 var resolved = Context.Resolve (customAttribute.Constructor);
1523 var resolved = Context.Resolve (customAttribute.Constructor);
1556 FieldDefinition? field = Context.Resolve (reference);
1602 ReportRequiresUnreferencedCode (method.GetDisplayName (), requiresUnreferencedCode!, new DiagnosticContext (origin, diagnosticsEnabled: true, Context));
1613 Context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName ());
1648 Context.LogWarning (origin, id, type.GetDisplayName (),
1657 Context.LogWarning (origin, id, type.GetDisplayName (), ((MemberReference) member).GetDisplayName ());
1702 typeWithFields = Context.TryResolve (typeWithFields.BaseType);
1744 ReportRequiresUnreferencedCode (field.GetDisplayName (), requiresUnreferencedCodeAttribute!, new DiagnosticContext (origin, diagnosticsEnabled: true, Context));
1754 Context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName ());
1765 AssemblyDefinition? assembly = Context.Resolve (scope);
1786 if (Context.GetTargetRuntimeVersion () > TargetRuntimeVersion.NET5)
1813 if (Context.Resolve (method) is MethodDefinition methodDefinition) {
1911 TypeDefinition? type = Context.Resolve (reference);
1938 Context.LogWarning (origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName ());
1964 if (Context.TryResolve (type.BaseType) is TypeDefinition baseType &&
1970 Context.LogWarning (typeOrigin, DiagnosticId.RequiresUnreferencedCodeOnBaseClass, type.GetDisplayName (), type.BaseType.GetDisplayName (), arg1, arg2);
1985 if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation (type, Context)) {
2084 return Context.TryResolve ((TypeReference) property.Argument.Value);
2088 return Context.TryResolve (asm, targetTypeName);
2102 var resolvedAttributeType = Context.Resolve (attrType);
2121 case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6):
2159 if (Context.KeepMembersForDebugger) {
2224 if (Context.TryResolve (type.BaseType) is not TypeDefinition baseType)
2234 if (Context.KeepMembersForDebugger) {
2250 if (Context.TryResolve (proxyTypeReference) is TypeDefinition proxyType) {
2345 if (!Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type))
2348 if (Context.Resolve (ifaceType) is not TypeDefinition resolvedInterfaceType)
2356 if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2541 var tdef = Context.Resolve (iface_type);
2551 } while ((type = Context.TryResolve (type.BaseType)) != null);
2562 var body = Context.GetMethodIL (method);
2609 Debug.Assert (Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2680 var scanner = new GenericArgumentDataFlow (Context, this, instanceMemberOrigin);
2697 return Context.TryResolve (method.ElementMethod);
2700 return Context.TryResolve (type.ElementType);
2723 Context.LogWarning (type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName ());
2727 Context.LogWarning (type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName ());
2833 foreach (var ins in Context.GetMethodIL (body).Instructions) {
2876 if (reference.Name == ".ctor" && Context.TryResolve (arrayType) is TypeDefinition typeDefinition) {
2890 MethodDefinition? method = Context.Resolve (reference);
2960 return CheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (method));
3091 Context.LogWarning (methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName ());
3093 Context.LogWarning (methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName ());
3112 var assembly = Context.Resolve (method.DeclaringType.Scope);
3120 Context.Resolve (@base) is MethodDefinition baseDefinition
3246 if (Context.Resolve (ov) is not MethodDefinition resolvedOverride)
3256 if (TypeReferenceEqualityComparer.AreEqual (iface.InterfaceType, interfaceToBeImplemented, Context)) {
3270 var baseType = Context.Resolve (method.DeclaringType.BaseType);
3286 if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3289 var nse = BCL.FindPredefinedType (WellKnownType.System_NotSupportedException, Context);
3296 Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3299 var objectType = BCL.FindPredefinedType (WellKnownType.System_Object, Context);
3306 Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3312 if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3315 var disablePrivateReflection = BCL.FindPredefinedType (WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3323 Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3355 if (!string.IsNullOrEmpty (Context.PInvokesListFile)) {
3356 Context.PInvokes.Add (new PInvokeInfo (
3365 TypeDefinition? returnTypeDefinition = Context.TryResolve (method.ReturnType);
3387 TypeDefinition? paramTypeDefinition = Context.TryResolve (paramTypeReference);
3403 (new UnsafeAccessorMarker (Context, this)).ProcessUnsafeAccessorMethod (method);
3415 AssemblyDefinition? assembly = Context.Resolve (method.DeclaringType.Scope);
3472 var processedMethodBody = Context.GetMethodIL (body);
3474 if (Context.IsOptimizationEnabled (CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody (processedMethodBody)) {
3499 if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method))
3510 if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite (Context, (MethodReference) instruction.Operand))
3528 while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember (owningMethod, out var owner))
3548 ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method);
3579 var implementations = new InterfacesOnStackScanner (Context).GetReferencedInterfaces (methodIL);
3595 => ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess (Context, (FieldReference) instruction.Operand),
3598 => ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess (Context, (FieldReference) instruction.Operand),
3627 ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite (Context, methodReference);
3658 if (Context.TryResolve (operand) is TypeDefinition typeDefinition) {
3666 if (!Context.CanApplyOptimization (CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
3669 TypeDefinition? type = Context.Resolve (operand);
3727 if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod (methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees)) {
3732 requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (nestedBody), origin);
3737 requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (stateMachineBody), origin);
3749 var scanner = new ReflectionMethodBodyScanner (Context, this, origin);