Linker.Steps\MarkStep.cs (158)
239public AnnotationStore Annotations => Context.Annotations;
240public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
241public Tracer Tracer => Context.Tracer;
242public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
258Context.Pipeline.InitializeMarkHandlers(Context, MarkContext);
262if (Context.TypeMapEntryAssembly is not null)
264var assemblyName = AssemblyNameReference.Parse(Context.TypeMapEntryAssembly);
265startingAssembly = Context.TryResolve(assemblyName);
270_typeMapHandler.Initialize(Context, this, startingAssembly);
280var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
284var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
291Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
294Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
404bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
410foreach (var (assemblyName, action) in Context.Actions)
415var assembly = Context.GetLoadedAssembly(assemblyName);
434var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
544Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
591bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
617foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
675MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
747if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
771if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
778Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
804=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
850TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
864bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
877var resolvedAttributeType = Context.Resolve(ca.AttributeType);
938if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
957assembly = Context.TryResolve(dynamicDependency.AssemblyName);
960Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
973type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
976Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
984type = Context.TryResolve(typeReference);
987Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
993type = Context.TryResolve(context.DeclaringType);
996Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
1004members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
1007Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
1014members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
1017Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1060Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1062if (!DynamicDependency.ShouldProcess(Context, ca))
1069assembly = Context.TryResolve(assemblyName);
1072Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1085td = Context.TryResolve(assemblyDef, typeName);
1089Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1134Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1209if (GenericArgumentDataFlow.RequiresGenericArgumentDataFlow(Context.Annotations.FlowAnnotations, constructor_type))
1210GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, constructor_type);
1212TypeDefinition? type = Context.Resolve(constructor_type);
1227if (Context.KeepUsedAttributeTypesOnly)
1247TypeDefinition? type = Context.Resolve(attr_type);
1260if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1323TypeDefinition? type = Context.Resolve(security_type);
1355var scanner = new AttributeDataFlow(Context, this, origin);
1369type = Context.TryResolve(type.BaseType);
1394var scanner = new AttributeDataFlow(Context, this, origin);
1408type = Context.TryResolve(type.BaseType);
1423type = Context.TryResolve(type.BaseType);
1437var resolvedConstructor = Context.TryResolve(ca.Constructor);
1440var scanner = new AttributeDataFlow(Context, this, origin);
1499EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1505if (Context.StripSecurity)
1506RemoveSecurity.ProcessAssembly(assembly, Context);
1508MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1514!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1644var resolved = Context.Resolve(customAttribute.Constructor);
1704var resolved = Context.Resolve(customAttribute.Constructor);
1740FieldDefinition? field = Context.Resolve(reference);
1800ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1813Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1850Context.LogWarning(origin, id, type.GetDisplayName(),
1860Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1910typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1950ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1961Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1972AssemblyDefinition? assembly = Context.Resolve(scope);
1996if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
2031if (Context.Resolve(method) is MethodDefinition methodDefinition)
2044GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, methodDefinition.ReturnType);
2048GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType);
2070if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2082GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, fieldDefinition.FieldType);
2162TypeDefinition? type = Context.Resolve(reference);
2194Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2233if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2345return Context.TryResolve((TypeReference)property.Argument.Value);
2350return Context.TryResolve(asm, targetTypeName);
2365var resolvedAttributeType = Context.Resolve(attrType);
2386case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2427if (Context.KeepMembersForDebugger)
2505if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2515if (Context.KeepMembersForDebugger)
2535if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2635if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2638if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2646if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2839var tdef = Context.Resolve(iface_type);
2850} while ((type = Context.TryResolve(type.BaseType)) != null);
2861var body = Context.GetMethodIL(method);
2911Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2988return Context.TryResolve(method.ElementMethod);
2991return Context.TryResolve(type.ElementType);
3016Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
3020Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3139foreach (var ins in Context.GetMethodIL(body).Instructions)
3185if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3201MethodDefinition? method = Context.Resolve(reference);
3264return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3400Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3402Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3426var assembly = Context.Resolve(method.DeclaringType.Scope);
3435Context.Resolve(@base) is MethodDefinition baseDefinition
3573if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3584if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3600var baseType = Context.Resolve(method.DeclaringType.BaseType);
3616if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3619var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3626Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3629var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3636Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3642if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3645var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3653Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3688if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3690Context.PInvokes.Add(new PInvokeInfo(
3699TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3726TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3745(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3758AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3816var processedMethodBody = Context.GetMethodIL(body);
3818if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3844if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3857if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3879if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3899while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember(owningMethod, out var owner))
3919ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3950var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
3969=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3982=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
4015ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4044ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4062if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4071if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4074TypeDefinition? type = Context.Resolve(operand);
4111GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType);
4137if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4147requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4156requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4169var scanner = new ReflectionMethodBodyScanner(Context, this, origin);