Linker.Steps\MarkStep.cs (149)
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);
263_typeMapHandler.Initialize(Context, this);
274var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
278var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
285Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
288Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
398bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
404foreach (var (assemblyName, action) in Context.Actions)
409var assembly = Context.GetLoadedAssembly(assemblyName);
428var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
520Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
567bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
593foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
651MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
723if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
747if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
754Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
780=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
826TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
840bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
853var resolvedAttributeType = Context.Resolve(ca.AttributeType);
914if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
933assembly = Context.TryResolve(dynamicDependency.AssemblyName);
936Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
949type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
952Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
960type = Context.TryResolve(typeReference);
963Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
969type = Context.TryResolve(context.DeclaringType);
972Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
980members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
983Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
990members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
993Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1036Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1038if (!DynamicDependency.ShouldProcess(Context, ca))
1045assembly = Context.TryResolve(assemblyName);
1048Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1061td = Context.TryResolve(assemblyDef, typeName);
1065Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1110Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1185TypeDefinition? type = Context.Resolve(constructor_type);
1200if (Context.KeepUsedAttributeTypesOnly)
1220TypeDefinition? type = Context.Resolve(attr_type);
1233if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1296TypeDefinition? type = Context.Resolve(security_type);
1328var scanner = new AttributeDataFlow(Context, this, origin);
1342type = Context.TryResolve(type.BaseType);
1367var scanner = new AttributeDataFlow(Context, this, origin);
1381type = Context.TryResolve(type.BaseType);
1396type = Context.TryResolve(type.BaseType);
1410var resolvedConstructor = Context.TryResolve(ca.Constructor);
1413var scanner = new AttributeDataFlow(Context, this, origin);
1469EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1475if (Context.StripSecurity)
1476RemoveSecurity.ProcessAssembly(assembly, Context);
1478MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1484!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1607var resolved = Context.Resolve(customAttribute.Constructor);
1667var resolved = Context.Resolve(customAttribute.Constructor);
1703FieldDefinition? field = Context.Resolve(reference);
1763ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1776Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1813Context.LogWarning(origin, id, type.GetDisplayName(),
1823Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1873typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1913ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1924Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1935AssemblyDefinition? assembly = Context.Resolve(scope);
1959if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
1994if (Context.Resolve(method) is MethodDefinition methodDefinition)
2096TypeDefinition? type = Context.Resolve(reference);
2128Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2155if (Context.TryResolve(type.BaseType) is TypeDefinition baseType &&
2162Context.LogWarning(typeOrigin, DiagnosticId.RequiresUnreferencedCodeOnBaseClass, type.GetDisplayName(), type.BaseType.GetDisplayName(), arg1, arg2);
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);
2934var scanner = new GenericArgumentDataFlow(Context, this, instanceMemberOrigin);
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))
3850while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember(owningMethod, out var owner))
3870ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3901var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
3918=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3921=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3953ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
3994if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4003if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4006TypeDefinition? type = Context.Resolve(operand);
4068if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4076requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), origin);
4082requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), origin);
4094var scanner = new ReflectionMethodBodyScanner(Context, this, origin);