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);
1803ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1816Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1853Context.LogWarning(origin, id, type.GetDisplayName(),
1863Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1913typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1956ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1967Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1978AssemblyDefinition? assembly = Context.Resolve(scope);
2002if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
2037if (Context.Resolve(method) is MethodDefinition methodDefinition)
2050GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, methodDefinition.ReturnType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2054GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2076if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2088GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, fieldDefinition.FieldType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2168TypeDefinition? type = Context.Resolve(reference);
2200Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2239if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2351return Context.TryResolve((TypeReference)property.Argument.Value);
2356return Context.TryResolve(asm, targetTypeName);
2371var resolvedAttributeType = Context.Resolve(attrType);
2392case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2433if (Context.KeepMembersForDebugger)
2511if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2521if (Context.KeepMembersForDebugger)
2541if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2641if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2644if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2652if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2845var tdef = Context.Resolve(iface_type);
2856} while ((type = Context.TryResolve(type.BaseType)) != null);
2867var body = Context.GetMethodIL(method);
2917Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2994return Context.TryResolve(method.ElementMethod);
2997return Context.TryResolve(type.ElementType);
3022Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
3026Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3145foreach (var ins in Context.GetMethodIL(body).Instructions)
3191if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3207MethodDefinition? method = Context.Resolve(reference);
3270return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3406Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3408Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3432var assembly = Context.Resolve(method.DeclaringType.Scope);
3441Context.Resolve(@base) is MethodDefinition baseDefinition
3579if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3590if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3606var baseType = Context.Resolve(method.DeclaringType.BaseType);
3622if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3625var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3632Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3635var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3642Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3648if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3651var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3659Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3694if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3696Context.PInvokes.Add(new PInvokeInfo(
3705TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3732TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3751(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3764AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3822var processedMethodBody = Context.GetMethodIL(body);
3824if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3850if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3863if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3885if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3905while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember(owningMethod, out var owner))
3925ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3956var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
3975=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3988=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
4021ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4050ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4068if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4077if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4080TypeDefinition? type = Context.Resolve(operand);
4123GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
4149if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4159requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4168requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4181var scanner = new ReflectionMethodBodyScanner(Context, this, origin);