Linker.Steps\MarkStep.cs (157)
237public AnnotationStore Annotations => Context.Annotations;
238public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
239public Tracer Tracer => Context.Tracer;
240public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
256Context.Pipeline.InitializeMarkHandlers(Context, MarkContext);
260if (Context.TypeMapEntryAssembly is not null)
262var assemblyName = AssemblyNameReference.Parse(Context.TypeMapEntryAssembly);
263startingAssembly = Context.TryResolve(assemblyName);
268_typeMapHandler.Initialize(Context, this, startingAssembly);
278var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
282var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
289Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
292Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
402bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
408foreach (var (assemblyName, action) in Context.Actions)
413var assembly = Context.GetLoadedAssembly(assemblyName);
432var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
524Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
571bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
597foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
655MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
727if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
751if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
758Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
784=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
830TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
844bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
857var resolvedAttributeType = Context.Resolve(ca.AttributeType);
918if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
937assembly = Context.TryResolve(dynamicDependency.AssemblyName);
940Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
953type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
956Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
964type = Context.TryResolve(typeReference);
967Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
973type = Context.TryResolve(context.DeclaringType);
976Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
984members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
987Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
994members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
997Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1040Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1042if (!DynamicDependency.ShouldProcess(Context, ca))
1049assembly = Context.TryResolve(assemblyName);
1052Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1065td = Context.TryResolve(assemblyDef, typeName);
1069Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1114Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1189TypeDefinition? type = Context.Resolve(constructor_type);
1204if (Context.KeepUsedAttributeTypesOnly)
1224TypeDefinition? type = Context.Resolve(attr_type);
1237if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1300TypeDefinition? type = Context.Resolve(security_type);
1332var scanner = new AttributeDataFlow(Context, this, origin);
1346type = Context.TryResolve(type.BaseType);
1371var scanner = new AttributeDataFlow(Context, this, origin);
1385type = Context.TryResolve(type.BaseType);
1400type = Context.TryResolve(type.BaseType);
1414var resolvedConstructor = Context.TryResolve(ca.Constructor);
1417var scanner = new AttributeDataFlow(Context, this, origin);
1473EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1479if (Context.StripSecurity)
1480RemoveSecurity.ProcessAssembly(assembly, Context);
1482MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1488!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1611var resolved = Context.Resolve(customAttribute.Constructor);
1671var resolved = Context.Resolve(customAttribute.Constructor);
1707FieldDefinition? field = Context.Resolve(reference);
1767ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1780Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1817Context.LogWarning(origin, id, type.GetDisplayName(),
1827Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1877typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1917ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1928Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1939AssemblyDefinition? assembly = Context.Resolve(scope);
1963if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
1998if (Context.Resolve(method) is MethodDefinition methodDefinition)
2006GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, methodDefinition.ReturnType);
2010GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType);
2032if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2037GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, fieldDefinition.FieldType);
2117TypeDefinition? type = Context.Resolve(reference);
2149Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2165GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in typeOrigin, this, Context, type.BaseType);
2189if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2301return Context.TryResolve((TypeReference)property.Argument.Value);
2306return Context.TryResolve(asm, targetTypeName);
2321var resolvedAttributeType = Context.Resolve(attrType);
2342case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2383if (Context.KeepMembersForDebugger)
2461if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2471if (Context.KeepMembersForDebugger)
2491if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2591if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2594if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2602if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2795var tdef = Context.Resolve(iface_type);
2806} while ((type = Context.TryResolve(type.BaseType)) != null);
2817var body = Context.GetMethodIL(method);
2867Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2951return Context.TryResolve(method.ElementMethod);
2954return Context.TryResolve(type.ElementType);
2979Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
2983Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3102foreach (var ins in Context.GetMethodIL(body).Instructions)
3148if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3164MethodDefinition? method = Context.Resolve(reference);
3238return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3374Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3376Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3400var assembly = Context.Resolve(method.DeclaringType.Scope);
3409Context.Resolve(@base) is MethodDefinition baseDefinition
3547if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3558if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3574var baseType = Context.Resolve(method.DeclaringType.BaseType);
3590if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3593var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3600Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3603var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3610Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3616if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3619var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3627Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3662if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3664Context.PInvokes.Add(new PInvokeInfo(
3673TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3700TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3719(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3732AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3790var processedMethodBody = Context.GetMethodIL(body);
3792if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3818if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3831if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3853if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3873while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember(owningMethod, out var owner))
3893ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3924var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
3943=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3956=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
3989ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4018ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4036if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4045if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4048TypeDefinition? type = Context.Resolve(operand);
4085GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType);
4111if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4121requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4130requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4143var scanner = new ReflectionMethodBodyScanner(Context, this, origin);