Linker.Steps\MarkStep.cs (154)
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);
257_typeMapHandler.Initialize(Context, this, Annotations.GetEntryPointAssembly());
267var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
271var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
278Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
281Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
391bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
397foreach (var (assemblyName, action) in Context.Actions)
402var assembly = Context.GetLoadedAssembly(assemblyName);
421var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
513Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
560bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
586foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
644MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
716if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
740if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
747Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
773=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
819TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
833bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
846var resolvedAttributeType = Context.Resolve(ca.AttributeType);
907if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
926assembly = Context.TryResolve(dynamicDependency.AssemblyName);
929Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
942type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
945Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
953type = Context.TryResolve(typeReference);
956Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
962type = Context.TryResolve(context.DeclaringType);
965Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
973members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
976Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
983members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
986Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1029Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1031if (!DynamicDependency.ShouldProcess(Context, ca))
1038assembly = Context.TryResolve(assemblyName);
1041Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1054td = Context.TryResolve(assemblyDef, typeName);
1058Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1103Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1178TypeDefinition? type = Context.Resolve(constructor_type);
1193if (Context.KeepUsedAttributeTypesOnly)
1213TypeDefinition? type = Context.Resolve(attr_type);
1226if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1289TypeDefinition? type = Context.Resolve(security_type);
1321var scanner = new AttributeDataFlow(Context, this, origin);
1335type = Context.TryResolve(type.BaseType);
1360var scanner = new AttributeDataFlow(Context, this, origin);
1374type = Context.TryResolve(type.BaseType);
1389type = Context.TryResolve(type.BaseType);
1403var resolvedConstructor = Context.TryResolve(ca.Constructor);
1406var scanner = new AttributeDataFlow(Context, this, origin);
1462EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1468if (Context.StripSecurity)
1469RemoveSecurity.ProcessAssembly(assembly, Context);
1471MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1477!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1600var resolved = Context.Resolve(customAttribute.Constructor);
1660var resolved = Context.Resolve(customAttribute.Constructor);
1696FieldDefinition? field = Context.Resolve(reference);
1756ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1769Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1806Context.LogWarning(origin, id, type.GetDisplayName(),
1816Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1866typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1906ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1917Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1928AssemblyDefinition? assembly = Context.Resolve(scope);
1952if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
1987if (Context.Resolve(method) is MethodDefinition methodDefinition)
1995GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, methodDefinition.ReturnType);
1999GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType);
2021if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2026GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, fieldDefinition.FieldType);
2106TypeDefinition? type = Context.Resolve(reference);
2138Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2154GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in typeOrigin, this, Context, type.BaseType);
2178if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2290return Context.TryResolve((TypeReference)property.Argument.Value);
2295return Context.TryResolve(asm, targetTypeName);
2310var resolvedAttributeType = Context.Resolve(attrType);
2331case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2372if (Context.KeepMembersForDebugger)
2450if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2460if (Context.KeepMembersForDebugger)
2480if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2580if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2583if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2591if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2784var tdef = Context.Resolve(iface_type);
2795} while ((type = Context.TryResolve(type.BaseType)) != null);
2806var body = Context.GetMethodIL(method);
2856Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2940return Context.TryResolve(method.ElementMethod);
2943return Context.TryResolve(type.ElementType);
2968Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
2972Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3091foreach (var ins in Context.GetMethodIL(body).Instructions)
3137if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3153MethodDefinition? method = Context.Resolve(reference);
3227return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3363Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3365Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3389var assembly = Context.Resolve(method.DeclaringType.Scope);
3398Context.Resolve(@base) is MethodDefinition baseDefinition
3536if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3547if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3563var baseType = Context.Resolve(method.DeclaringType.BaseType);
3579if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3582var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3589Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3592var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3599Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3605if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3608var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3616Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3651if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3653Context.PInvokes.Add(new PInvokeInfo(
3662TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3689TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3708(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3721AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3779var processedMethodBody = Context.GetMethodIL(body);
3781if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3807if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3820if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3842if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3862while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember(owningMethod, out var owner))
3882ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3913var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
3932=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3945=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
3978ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4007ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4025if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4034if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4037TypeDefinition? type = Context.Resolve(operand);
4074GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType);
4100if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4110requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4119requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4132var scanner = new ReflectionMethodBodyScanner(Context, this, origin);