Linker.Steps\MarkStep.cs (157)
240public AnnotationStore Annotations => Context.Annotations;
241public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
242public Tracer Tracer => Context.Tracer;
243public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
259Context.Pipeline.InitializeMarkHandlers(Context, MarkContext);
263if (Context.TypeMapEntryAssembly is not null)
265var assemblyName = LinkContext.TryParseAssemblyName(Context.TypeMapEntryAssembly);
266startingAssembly = assemblyName is null ? null : Context.TryResolve(assemblyName);
271_typeMapHandler.Initialize(Context, this, startingAssembly);
281var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
285var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
292Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
295Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
405bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
411foreach (var (assemblyName, action) in Context.Actions)
416var assembly = Context.GetLoadedAssembly(assemblyName);
435var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
545Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
592bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
618foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
676MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
748if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
772if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
779Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
805=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
851TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
865bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
878var resolvedAttributeType = Context.Resolve(ca.AttributeType);
939if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
958assembly = Context.TryResolve(dynamicDependency.AssemblyName);
961Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
974type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
977Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
985type = Context.TryResolve(typeReference);
988Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
994type = Context.TryResolve(context.DeclaringType);
997Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
1005members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
1008Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
1015members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
1018Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1061Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1063if (!DynamicDependency.ShouldProcess(Context, ca))
1070assembly = Context.TryResolve(assemblyName);
1073Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1086td = Context.TryResolve(assemblyDef, typeName);
1090Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1135Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1210if (GenericArgumentDataFlow.RequiresGenericArgumentDataFlow(Context.Annotations.FlowAnnotations, constructor_type))
1211GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, constructor_type);
1213TypeDefinition? type = Context.Resolve(constructor_type);
1228if (Context.KeepUsedAttributeTypesOnly)
1248TypeDefinition? type = Context.Resolve(attr_type);
1261if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1324TypeDefinition? type = Context.Resolve(security_type);
1356var scanner = new AttributeDataFlow(Context, this, origin);
1370type = Context.TryResolve(type.BaseType);
1395var scanner = new AttributeDataFlow(Context, this, origin);
1409type = Context.TryResolve(type.BaseType);
1424type = Context.TryResolve(type.BaseType);
1438var resolvedConstructor = Context.TryResolve(ca.Constructor);
1441var scanner = new AttributeDataFlow(Context, this, origin);
1500EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1506if (Context.StripSecurity)
1507RemoveSecurity.ProcessAssembly(assembly, Context);
1509MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1515!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1645var resolved = Context.Resolve(customAttribute.Constructor);
1705var resolved = Context.Resolve(customAttribute.Constructor);
1741FieldDefinition? field = Context.Resolve(reference);
1804ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1817Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1854Context.LogWarning(origin, id, type.GetDisplayName(),
1864Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1914typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1957ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1968Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1979AssemblyDefinition? assembly = Context.Resolve(scope);
2003if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
2038if (Context.Resolve(method) is MethodDefinition methodDefinition)
2063GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, method.ReturnType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2067GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2094if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2118GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, field.FieldType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2203TypeDefinition? type = Context.Resolve(reference);
2235Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2274if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2386return Context.TryResolve((TypeReference)property.Argument.Value);
2391return Context.TryResolve(asm, targetTypeName);
2406var resolvedAttributeType = Context.Resolve(attrType);
2427case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2468if (Context.KeepMembersForDebugger)
2546if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2556if (Context.KeepMembersForDebugger)
2576if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2676if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2679if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2687if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2880var tdef = Context.Resolve(iface_type);
2891} while ((type = Context.TryResolve(type.BaseType)) != null);
2902var body = Context.GetMethodIL(method);
2952Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
3029return Context.TryResolve(method.ElementMethod);
3032return Context.TryResolve(type.ElementType);
3057Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
3061Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3180foreach (var ins in Context.GetMethodIL(body).Instructions)
3226if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3242MethodDefinition? method = Context.Resolve(reference);
3305return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3441Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3443Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3467var assembly = Context.Resolve(method.DeclaringType.Scope);
3476Context.Resolve(@base) is MethodDefinition baseDefinition
3614if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3625if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3641var baseType = Context.Resolve(method.DeclaringType.BaseType);
3657if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3660var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3667Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3670var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3677Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3683if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3686var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3694Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3729if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3731Context.PInvokes.Add(new PInvokeInfo(
3740TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3767TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3786(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3799AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3857var processedMethodBody = Context.GetMethodIL(body);
3859if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3885if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3898if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3920if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3960ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3991var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
4010=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
4023=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
4056ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4085ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4103if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4112if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4115TypeDefinition? type = Context.Resolve(operand);
4158GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
4184if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4194requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4203requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4216var scanner = new ReflectionMethodBodyScanner(Context, this, origin);