Linker.Steps\MarkStep.cs (147)
226 public AnnotationStore Annotations => Context.Annotations;
227 public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
228 public Tracer Tracer => Context.Tracer;
229 public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
245 Context.Pipeline.InitializeMarkHandlers (Context, MarkContext);
256 var coreLib = Context.TryResolve (PlatformAssemblies.CoreLib);
260 var xmlInfo = EmbeddedXmlInfo.ProcessAttributes (coreLib, Context);
267 Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes (provider, annotations);
270 Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add (ca, origin);
371 bool scanReferences = IsFullyPreservedAction (Context.TrimAction) || IsFullyPreservedAction (Context.DefaultAction);
376 foreach (var (assemblyName, action) in Context.Actions) {
380 var assembly = Context.GetLoadedAssembly (assemblyName);
398 var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies ().ToArray () : Context.GetAssemblies ();
484 Context.LogMessage ($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName ()}' method.");
528 bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type);
550 foreach (var assembly in Context.GetReferencedAssemblies ().ToArray ()) {
601 MarkType (type, new DependencyInfo (DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin (Context.TryResolve (iface.InterfaceType)));
666 if (!Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override))
690 if (Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated (overrideInformation.Override.DeclaringType)) {
694 Debug.Assert (!Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
719 => IsInterfaceImplementationMarkedRecursively (type, interfaceType, Context);
762 TypeDefinition? type = Context.Resolve (marshaler.ManagedType);
774 bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
785 var resolvedAttributeType = Context.Resolve (ca.AttributeType);
843 if (Context.CanApplyOptimization (CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly)) {
858 assembly = Context.TryResolve (dynamicDependency.AssemblyName);
860 Context.LogWarning (origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
870 type = DocumentationSignatureParser.GetTypeByDocumentationSignature (assembly, typeName, Context);
872 Context.LogWarning (origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
878 type = Context.TryResolve (typeReference);
880 Context.LogWarning (origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName ());
884 type = Context.TryResolve (context.DeclaringType);
886 Context.LogWarning (context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName ());
893 members = DocumentationSignatureParser.GetMembersByDocumentationSignature (type, memberSignature, Context, acceptName: true);
895 Context.LogWarning (origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName ());
900 members = type.GetDynamicallyAccessedMembers (Context, memberTypes);
902 Context.LogWarning (origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString (), type.GetDisplayName ());
943 Context.LogWarning (context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
945 if (!DynamicDependency.ShouldProcess (Context, ca))
951 assembly = Context.TryResolve (assemblyName);
953 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
963 td = Context.TryResolve (assemblyDef, typeName);
966 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1003 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName ());
1070 TypeDefinition? type = Context.Resolve (constructor_type);
1084 if (Context.KeepUsedAttributeTypesOnly) {
1102 TypeDefinition? type = Context.Resolve (attr_type);
1115 if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled (CodeOptimizations.BeforeFieldInit, type))
1176 TypeDefinition? type = Context.Resolve (security_type);
1206 var scanner = new AttributeDataFlow (Context, this, origin);
1219 type = Context.TryResolve (type.BaseType);
1243 var scanner = new AttributeDataFlow (Context, this, origin);
1256 type = Context.TryResolve (type.BaseType);
1270 type = Context.TryResolve (type.BaseType);
1284 var resolvedConstructor = Context.TryResolve (ca.Constructor);
1286 var scanner = new AttributeDataFlow (Context, this, origin);
1339 EmbeddedXmlInfo.ProcessDescriptors (assembly, Context);
1345 if (Context.StripSecurity)
1346 RemoveSecurity.ProcessAssembly (assembly, Context);
1348 MarkExportedTypesTarget.ProcessAssembly (assembly, Context);
1353 !Context.TryGetCustomData ("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1469 var resolved = Context.Resolve (customAttribute.Constructor);
1523 var resolved = Context.Resolve (customAttribute.Constructor);
1556 FieldDefinition? field = Context.Resolve (reference);
1602 ReportRequiresUnreferencedCode (method.GetDisplayName (), requiresUnreferencedCode!, new DiagnosticContext (origin, diagnosticsEnabled: true, Context));
1613 Context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName ());
1648 Context.LogWarning (origin, id, type.GetDisplayName (),
1657 Context.LogWarning (origin, id, type.GetDisplayName (), ((MemberReference) member).GetDisplayName ());
1702 typeWithFields = Context.TryResolve (typeWithFields.BaseType);
1744 ReportRequiresUnreferencedCode (field.GetDisplayName (), requiresUnreferencedCodeAttribute!, new DiagnosticContext (origin, diagnosticsEnabled: true, Context));
1754 Context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName ());
1765 AssemblyDefinition? assembly = Context.Resolve (scope);
1786 if (Context.GetTargetRuntimeVersion () > TargetRuntimeVersion.NET5)
1813 if (Context.Resolve (method) is MethodDefinition methodDefinition) {
1911 TypeDefinition? type = Context.Resolve (reference);
1938 Context.LogWarning (origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName ());
1964 if (Context.TryResolve (type.BaseType) is TypeDefinition baseType &&
1970 Context.LogWarning (typeOrigin, DiagnosticId.RequiresUnreferencedCodeOnBaseClass, type.GetDisplayName (), type.BaseType.GetDisplayName (), arg1, arg2);
1985 if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation (type, Context)) {
2084 return Context.TryResolve ((TypeReference) property.Argument.Value);
2088 return Context.TryResolve (asm, targetTypeName);
2102 var resolvedAttributeType = Context.Resolve (attrType);
2121 case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6):
2159 if (Context.KeepMembersForDebugger) {
2224 if (Context.TryResolve (type.BaseType) is not TypeDefinition baseType)
2234 if (Context.KeepMembersForDebugger) {
2250 if (Context.TryResolve (proxyTypeReference) is TypeDefinition proxyType) {
2345 if (!Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type))
2348 if (Context.Resolve (ifaceType) is not TypeDefinition resolvedInterfaceType)
2356 if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2541 var tdef = Context.Resolve (iface_type);
2551 } while ((type = Context.TryResolve (type.BaseType)) != null);
2562 var body = Context.GetMethodIL (method);
2608 Debug.Assert (Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2679 var scanner = new GenericArgumentDataFlow (Context, this, instanceMemberOrigin);
2696 return Context.TryResolve (method.ElementMethod);
2699 return Context.TryResolve (type.ElementType);
2722 Context.LogWarning (type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName ());
2726 Context.LogWarning (type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName ());
2832 foreach (var ins in Context.GetMethodIL (body).Instructions) {
2875 if (reference.Name == ".ctor" && Context.TryResolve (arrayType) is TypeDefinition typeDefinition) {
2889 MethodDefinition? method = Context.Resolve (reference);
2959 return CheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (method));
3090 Context.LogWarning (methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName ());
3109 var assembly = Context.Resolve (method.DeclaringType.Scope);
3117 Context.Resolve (@base) is MethodDefinition baseDefinition
3243 if (Context.Resolve (ov) is not MethodDefinition resolvedOverride)
3253 if (TypeReferenceEqualityComparer.AreEqual (iface.InterfaceType, interfaceToBeImplemented, Context)) {
3267 var baseType = Context.Resolve (method.DeclaringType.BaseType);
3283 if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3286 var nse = BCL.FindPredefinedType (WellKnownType.System_NotSupportedException, Context);
3293 Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3296 var objectType = BCL.FindPredefinedType (WellKnownType.System_Object, Context);
3303 Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3309 if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3312 var disablePrivateReflection = BCL.FindPredefinedType (WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3320 Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3352 if (!string.IsNullOrEmpty (Context.PInvokesListFile)) {
3353 Context.PInvokes.Add (new PInvokeInfo (
3362 TypeDefinition? returnTypeDefinition = Context.TryResolve (method.ReturnType);
3384 TypeDefinition? paramTypeDefinition = Context.TryResolve (paramTypeReference);
3400 (new UnsafeAccessorMarker (Context, this)).ProcessUnsafeAccessorMethod (method);
3412 AssemblyDefinition? assembly = Context.Resolve (method.DeclaringType.Scope);
3469 var processedMethodBody = Context.GetMethodIL (body);
3471 if (Context.IsOptimizationEnabled (CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody (processedMethodBody)) {
3496 if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method))
3507 if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite (Context, (MethodReference) instruction.Operand))
3525 while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember (owningMethod, out var owner))
3545 ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method);
3576 var implementations = new InterfacesOnStackScanner (Context).GetReferencedInterfaces (methodIL);
3592 => ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess (Context, (FieldReference) instruction.Operand),
3595 => ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess (Context, (FieldReference) instruction.Operand),
3624 ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite (Context, methodReference);
3655 if (Context.TryResolve (operand) is TypeDefinition typeDefinition) {
3663 if (!Context.CanApplyOptimization (CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
3666 TypeDefinition? type = Context.Resolve (operand);
3724 if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod (methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees)) {
3729 requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (nestedBody), origin);
3734 requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (stateMachineBody), origin);
3746 var scanner = new ReflectionMethodBodyScanner (Context, this, origin);