diff --git a/src/Foundation/NSTimer.cs b/src/Foundation/NSTimer.cs index 8f624f2db963..fddd5b1b5fff 100644 --- a/src/Foundation/NSTimer.cs +++ b/src/Foundation/NSTimer.cs @@ -20,8 +20,10 @@ // // Copyright 2011-2014 Xamarin Inc. // + using System.Reflection; using System.Collections; +using System.Diagnostics.CodeAnalysis; namespace Foundation { @@ -120,5 +122,18 @@ public NSTimer (NSDate date, TimeSpan when, Action action, System.Boole : this (date, when.TotalSeconds, new NSTimerActionDispatcher (action), NSTimerActionDispatcher.Selector, null, repeats) { } + + // The dependency attribute is required because: + // * We inject a call to Invalidate in the generated Dispose method + // * We optimize Dispose methods to not touch fields that aren't otherwise used, which we do by + // removing the contents of the Dispose method before the linker runs, then after the linker runs + // we determine which fields the Dispose method touches have been linked away and remove any such code. + // We won't remove the call to Invalidate, but the linker may have trimmed away the Invalidate method + /// itself (because we temporarly removed the call to it). So make sure the linker doesn't remove it. + [DynamicDependency ("Invalidate()")] + static NSTimer () + { + GC.KeepAlive (null); + } } } diff --git a/src/Resources.Designer.cs b/src/Resources.Designer.cs index 0a6148d9d50c..5cd19312d3ee 100644 --- a/src/Resources.Designer.cs +++ b/src/Resources.Designer.cs @@ -1185,5 +1185,14 @@ internal static string BI1123 { return ResourceManager.GetString("BI1123", resourceCulture); } } + + /// + /// Looks up a localized string similar to Found a [Preserve] attribute on {0}: [Preserve] is deprecated; use [DynamicDependency] instead.. + /// + internal static string BI1124 { + get { + return ResourceManager.GetString("BI1124", resourceCulture); + } + } } } diff --git a/src/Resources.resx b/src/Resources.resx index 69d1e75e41d2..acd9d535c624 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -637,4 +637,7 @@ The type {0} has a [Protocol] and a [BaseType] attribute, but no [Model] attribute. This is likely incorrect; either remove the [BaseType] attribute, or add a [Model] attribute. + + Found a [Preserve] attribute on {0}: [Preserve] is deprecated; use [DynamicDependency] instead. + diff --git a/src/bgen/Generator.cs b/src/bgen/Generator.cs index fab82debf331..d3626e9af266 100644 --- a/src/bgen/Generator.cs +++ b/src/bgen/Generator.cs @@ -1595,11 +1595,6 @@ void GenerateTrampolinesForQueue (TrampolineInfo [] queue) print ("//\n// This class bridges native block invocations that call into C#\n//"); PrintExperimentalAttribute (ti.Type); print ("static internal class {0} {{", ti.StaticName); indent++; - // it can't be conditional without fixing https://github.com/mono/linker/issues/516 - // but we have a workaround in place because we can't fix old, binary bindings so... - // print ("[Preserve (Conditional=true)]"); - // For .NET we fix it using the DynamicDependency attribute below - print ("[Preserve (Conditional = true)]"); print ("[UnmanagedCallersOnly]"); print ("[UserDelegateType (typeof ({0}))]", ti.UserDelegate); print ("internal static unsafe {0} Invoke ({1}) {{", ti.ReturnType, ti.Parameters); @@ -1672,7 +1667,12 @@ void GenerateTrampolinesForQueue (TrampolineInfo [] queue) print ("invoker = block->GetDelegateForBlock<{0}> ();", ti.DelegateName); indent--; print ("}"); print (""); - print ("[Preserve (Conditional=true)]"); + print ("[DynamicDependency (nameof (Create))]"); + print ($"static {ti.NativeInvokerName} ()"); + print ("{"); + print ("\tGC.KeepAlive (null);"); // need to do _something_ (doesn't seem to matter what), otherwise the static cctor (and the DynamicDependency attributes) are trimmed away. + print ("}"); + print (""); print_generated_code (); print ("public unsafe static {0}? Create (IntPtr block)\n{{", ti.UserDelegate); indent++; print ("if (block == IntPtr.Zero)"); indent++; @@ -1900,13 +1900,11 @@ void GenerateStrongDictionaryTypes () if (BindingTouch.SupportsXmlDocumentation) { print ($"/// Creates a new with default (empty) values."); } - print ("[Preserve (Conditional = true)]"); print ("public {0} () : base (new NSMutableDictionary ()) {{}}\n", typeName); if (BindingTouch.SupportsXmlDocumentation) { print ($"/// Creates a new from the values that are specified in ."); print ($"/// The dictionary to use to populate the properties of this type."); } - print ("[Preserve (Conditional = true)]"); print ("public {0} (NSDictionary? dictionary) : base (dictionary) {{}}\n", typeName); foreach (var pi in dictType.GatherProperties (this)) { @@ -5107,6 +5105,7 @@ void GenerateProtocolTypes (Type type, string class_visibility, string TypeName, } } + var dynamicDependencies = new List (); if (instanceMethods.Any () || instanceProperties.Any ()) { // Tell the trimmer to not remove any instance method/property if the interface itself isn't trimmed away. // These members are required for the registrar to determine if a particular implementing method @@ -5117,10 +5116,14 @@ void GenerateProtocolTypes (Type type, string class_visibility, string TypeName, var docIds = instanceMethods .Select (mi => DocumentationManager.GetDocId (mi, includeDeclaringType: false, alwaysIncludeParenthesis: true)) .Concat (instanceProperties.Select (v => v.Name)) - .OrderBy (name => name); - foreach (var docId in docIds) { - print ($"[DynamicDependencyAttribute (\"{docId}\")]"); - } + .Select (v => $"\"{v}\""); + dynamicDependencies.AddRange (docIds); + } + // Tell the trimmer to not remove the wrapper type if the interface itself isn't trimmed away + dynamicDependencies.Add ($"DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors, typeof ({TypeName}Wrapper)"); + if (dynamicDependencies.Count > 0) { + foreach (var dd in dynamicDependencies.OrderBy (v => v)) + print ($"[DynamicDependencyAttribute ({dd})]"); print ("[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]"); print ($"static I{TypeName} ()"); print ("{"); @@ -5233,12 +5236,19 @@ void GenerateProtocolTypes (Type type, string class_visibility, string TypeName, indent++; // ctor (IntPtr, bool) PrintExperimentalAttribute (type); - print ("[Preserve (Conditional = true)]"); print ("public {0}Wrapper ({1} handle, bool owns)", TypeName, NativeHandleType); print ("\t: base (handle, owns)"); print ("{"); print ("}"); print (""); + + print ($"[DynamicDependencyAttribute (DynamicallyAccessedMemberTypes.PublicConstructors, typeof ({TypeName}Wrapper))]"); + print ($"static {TypeName}Wrapper ()"); + print ("{"); + print ("\tGC.KeepAlive (null);"); // need to do _something_ (doesn't seem to matter what), otherwise the static cctor (and the DynamicDependency attribute) is trimmed away. + print ("}"); + print (""); + // Methods // First find duplicates and select the best one. We use the selector to determine what's a duplicate. var methodData = requiredInstanceMethods.Select ((v) => { @@ -5451,6 +5461,9 @@ public void PrintPreserveAttribute (ICustomAttributeProvider mi) if (p is null) return; + if (!BindThirdPartyLibrary) + exceptions.Add (ErrorHelper.CreateError (1124 /* Found a [Preserve] attribute on {0}: [Preserve] is deprecated; use [DynamicDependency] instead. */, FormatProvider (mi))); + if (p.AllMembers) print ("[Preserve (AllMembers = true)]"); else if (p.Conditional) @@ -6743,7 +6756,6 @@ public void Generate (Type type) } else print ("internal {0}? {1};", Nomenclator.GetDelegateName (mi), miname); - print ("[Preserve (Conditional = true)]"); if (isProtocolEventBacked) print ("[Export (\"{0}\")]", FindSelector (dtype, mi)); @@ -6850,7 +6862,6 @@ public void Generate (Type type) selRespondsToSelector = "selRespondsToSelector"; } - print ("[Preserve (Conditional = true)]"); print ("public override bool RespondsToSelector (Selector? sel)"); print ("{"); ++indent; diff --git a/src/foundation.cs b/src/foundation.cs index 67bf5dfabfbc..c693ecc91e62 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -7378,8 +7378,6 @@ interface NSTimer { [Export ("fireDate", ArgumentSemantic.Copy)] NSDate FireDate { get; set; } - // Note: preserving this member allows us to re-enable the `Optimizable` binding flag - [Preserve (Conditional = true)] [Export ("invalidate")] void Invalidate (); diff --git a/tests/cecil-tests/ApiTest.KnownFailures.cs b/tests/cecil-tests/ApiTest.KnownFailures.cs index 94b9d47f5e9c..3ae8b2374012 100644 --- a/tests/cecil-tests/ApiTest.KnownFailures.cs +++ b/tests/cecil-tests/ApiTest.KnownFailures.cs @@ -318,5 +318,331 @@ public partial class ApiTest { "The type 'Foundation.NSURLRequestAttribution' has an invalid term 'URL'. Replace with: 'Url'.", "The type 'NetworkExtension.NSMutableURLRequest_NEHotspotHelper' has an invalid term 'URL'. Replace with: 'Url'.", }; + + static HashSet knownFailuresBannedAttributes = new HashSet { + "AddressBook.ABAddressBook..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBook.ABGroup..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBook.ABMultiValue`1..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBook.ABMutableMultiValue`1..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBook.ABPerson..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBook.ABRecord..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBook.ABSource..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AddressBookUI.InternalABNewPersonViewControllerDelegate.DidCompleteWithNewPerson(AddressBookUI.ABNewPersonViewController, AddressBook.ABPerson)", + "AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.Cancelled(AddressBookUI.ABPeoplePickerNavigationController)", + "AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.DidSelectPerson(AddressBookUI.ABPeoplePickerNavigationController, AddressBook.ABPerson, System.Int32, System.Int32)", + "AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.DidSelectPerson(AddressBookUI.ABPeoplePickerNavigationController, AddressBook.ABPerson)", + "AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.RespondsToSelector(ObjCRuntime.Selector)", + "AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.ShouldContinue(AddressBookUI.ABPeoplePickerNavigationController, AddressBook.ABPerson, System.Int32, System.Int32)", + "AddressBookUI.InternalABPeoplePickerNavigationControllerDelegate.ShouldContinue(AddressBookUI.ABPeoplePickerNavigationController, AddressBook.ABPerson)", + "AddressBookUI.InternalABPersonViewControllerDelegate.ShouldPerformDefaultActionForPerson(AddressBookUI.ABPersonViewController, AddressBook.ABPerson, System.Int32, System.Int32)", + "AddressBookUI.InternalABUnknownPersonViewControllerDelegate.DidResolveToPerson(AddressBookUI.ABUnknownPersonViewController, AddressBook.ABPerson)", + "AddressBookUI.InternalABUnknownPersonViewControllerDelegate.ShouldPerformDefaultActionForPerson(AddressBookUI.ABUnknownPersonViewController, AddressBook.ABPerson, System.Int32, System.Int32)", + "AppKit.ActionDispatcher.OnActivated(Foundation.NSObject)", + "AppKit.ActionDispatcher.OnActivated2(Foundation.NSObject)", + "AppKit.NSAlertDidEndDispatcher.OnAlertDidEnd(AppKit.NSAlert, System.IntPtr, System.IntPtr)", + "AppKit.NSApplication.Init()", + "AppKit.NSClickGestureRecognizer/Callback", + "AppKit.NSClickGestureRecognizer/Callback.Activated(AppKit.NSClickGestureRecognizer)", + "AppKit.NSGestureRecognizer/ParameterlessDispatch", + "AppKit.NSGestureRecognizer/ParameterlessDispatch.Activated()", + "AppKit.NSGestureRecognizer/ParametrizedDispatch", + "AppKit.NSGestureRecognizer/ParametrizedDispatch.Activated(AppKit.NSGestureRecognizer)", + "AppKit.NSGestureRecognizer/Token", + "AppKit.NSMagnificationGestureRecognizer/Callback", + "AppKit.NSMagnificationGestureRecognizer/Callback.Activated(AppKit.NSMagnificationGestureRecognizer)", + "AppKit.NSPanGestureRecognizer/Callback", + "AppKit.NSPanGestureRecognizer/Callback.Activated(AppKit.NSPanGestureRecognizer)", + "AppKit.NSPressGestureRecognizer/Callback", + "AppKit.NSPressGestureRecognizer/Callback.Activated(AppKit.NSPressGestureRecognizer)", + "AppKit.NSRotationGestureRecognizer/Callback", + "AppKit.NSRotationGestureRecognizer/Callback.Activated(AppKit.NSRotationGestureRecognizer)", + "AudioToolbox.AudioConverter..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioToolbox.AudioFile..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioToolbox.MusicPlayer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioToolbox.MusicSequence..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioUnit.AudioComponent..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioUnit.AudioUnit..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioUnit.AUGraph..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AudioUnit.AURenderEventEnumerator..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "AVFoundation.InternalAVAudioPlayerDelegate.BeginInterruption(AVFoundation.AVAudioPlayer)", + "AVFoundation.InternalAVAudioPlayerDelegate.DecoderError(AVFoundation.AVAudioPlayer, Foundation.NSError)", + "AVFoundation.InternalAVAudioPlayerDelegate.EndInterruption(AVFoundation.AVAudioPlayer)", + "AVFoundation.InternalAVAudioPlayerDelegate.FinishedPlaying(AVFoundation.AVAudioPlayer, System.Boolean)", + "AVFoundation.InternalAVAudioRecorderDelegate.BeginInterruption(AVFoundation.AVAudioRecorder)", + "AVFoundation.InternalAVAudioRecorderDelegate.EncoderError(AVFoundation.AVAudioRecorder, Foundation.NSError)", + "AVFoundation.InternalAVAudioRecorderDelegate.EndInterruption(AVFoundation.AVAudioRecorder)", + "AVFoundation.InternalAVAudioRecorderDelegate.FinishedRecording(AVFoundation.AVAudioRecorder, System.Boolean)", + "AVFoundation.InternalAVAudioSessionDelegate..ctor(AVFoundation.AVAudioSession)", + "AVFoundation.InternalAVAudioSessionDelegate.BeginInterruption()", + "AVFoundation.InternalAVAudioSessionDelegate.EndInterruption()", + "AVFoundation.InternalAVAudioSessionDelegate.InputIsAvailableChanged(System.Boolean)", + "CFNetwork.CFHost..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CFNetwork.CFHTTPAuthentication..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CFNetwork.CFHTTPMessage..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CFNetwork.CFHTTPStream..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreAnimation.CALayer.OnDispose()", + "CoreFoundation.CFAllocator..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFArray..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFBoolean..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFBundle..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFData..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFDictionary..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFMachPort..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFMessagePort..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFMutableString..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFNotificationCenter..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFPropertyList..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFReadStream..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFRunLoop..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFRunLoopSource..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFStream..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFString..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFType..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFUrl..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.CFWriteStream..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchBlock..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchData..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchGroup..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchIO..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchObject..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchQueue..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.DispatchSource..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreFoundation.OSLog..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGBitmapContext..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGColor..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGColorConversionInfo..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGColorSpace..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGContext..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGDataConsumer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGDataProvider..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGEvent..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGEventSource..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGFont..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGFunction..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGGradient..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGImage..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGLayer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPath..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPattern..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPDFContentStream..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPDFDocument..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPDFOperatorTable..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPDFPage..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPDFScanner..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGPointDictionary..ctor()", + "CoreGraphics.CGPointDictionary..ctor(Foundation.NSDictionary)", + "CoreGraphics.CGRectDictionary..ctor()", + "CoreGraphics.CGRectDictionary..ctor(Foundation.NSDictionary)", + "CoreGraphics.CGRenderingBufferProvider..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGShading..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreGraphics.CGSizeDictionary..ctor()", + "CoreGraphics.CGSizeDictionary..ctor(Foundation.NSDictionary)", + "CoreMedia.CMAudioFormatDescription..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMBlockBuffer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMClock..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMClockOrTimebase..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMFormatDescription..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMSampleBuffer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMTagCollection..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMTaggedBufferGroup..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMTimebase..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreMedia.CMVideoFormatDescription..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTFont..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTFontCollection..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTFontDescriptor..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTFrame..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTFramesetter..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTGlyphInfo..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTLine..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTParagraphStyle..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTRun..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTRunDelegate..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTTextTab..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreText.CTTypesetter..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVBuffer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVDisplayLink..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVImageBuffer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVMetalBuffer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVMetalBufferCache..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVMetalTexture..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVMetalTextureCache..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVOpenGLESTexture..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVOpenGLESTextureCache..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVPixelBuffer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "CoreVideo.CVPixelBufferPool..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Darwin.Message..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Darwin.SystemLog..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Foundation.InternalNSNotificationHandler.Post(Foundation.NSNotification)", + "Foundation.NSDispatcher.Apply()", + "Foundation.NSError Foundation.NSUrlSessionHandler/WrappedNSInputStream::Error()", + "Foundation.NSError System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream::Error()", + "Foundation.NSObject.ConformsToProtocol(ObjCRuntime.NativeHandle)", + "Foundation.NSObject.InvokeConformsToProtocol(ObjCRuntime.NativeHandle)", + "Foundation.NSObject/NSObject_Disposer", + "Foundation.NSObject/Observer.ObserveValue(Foundation.NSString, Foundation.NSObject, Foundation.NSDictionary, System.IntPtr)", + "Foundation.NSStreamStatus Foundation.NSUrlSessionHandler/WrappedNSInputStream::Status()", + "Foundation.NSStreamStatus System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream::Status()", + "Foundation.NSTimerActionDispatcher.Fire(Foundation.NSTimer)", + "Foundation.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidCompleteWithError(Foundation.NSUrlSession, Foundation.NSUrlSessionTask, Foundation.NSError)", + "Foundation.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidReceiveChallenge(Foundation.NSUrlSession, Foundation.NSUrlSessionTask, Foundation.NSUrlAuthenticationChallenge, System.Action`2)", + "Foundation.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidReceiveData(Foundation.NSUrlSession, Foundation.NSUrlSessionDataTask, Foundation.NSData)", + "Foundation.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidReceiveResponse(Foundation.NSUrlSession, Foundation.NSUrlSessionDataTask, Foundation.NSUrlResponse, System.Action`1)", + "Foundation.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.WillCacheResponse(Foundation.NSUrlSession, Foundation.NSUrlSessionDataTask, Foundation.NSCachedUrlResponse, System.Action`1)", + "Foundation.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.WillPerformHttpRedirection(Foundation.NSUrlSession, Foundation.NSUrlSessionTask, Foundation.NSHttpUrlResponse, Foundation.NSUrlRequest, System.Action`1)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.Close()", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.GetBuffer(out System.IntPtr&, out System.UIntPtr&)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.GetProperty(Foundation.NSString)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.HasBytesAvailable()", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.Open()", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.Read(System.IntPtr, System.UIntPtr)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.Schedule(Foundation.NSRunLoop, Foundation.NSString)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.SetCFClientFlags(CoreFoundation.CFStreamEventType, System.IntPtr, System.IntPtr)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.SetProperty(Foundation.NSObject, Foundation.NSString)", + "Foundation.NSUrlSessionHandler/WrappedNSInputStream.Unschedule(Foundation.NSRunLoop, Foundation.NSString)", + "Foundation.NSZone..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "GameKit.GKSession/ReceiverObject.Receive(Foundation.NSData, System.String, GameKit.GKSession, System.IntPtr)", + "GameKit.Mono_GKSessionDelegate.FailedWithError(GameKit.GKSession, Foundation.NSError)", + "GameKit.Mono_GKSessionDelegate.PeerChangedState(GameKit.GKSession, System.String, GameKit.GKPeerConnectionState)", + "GameKit.Mono_GKSessionDelegate.PeerConnectionFailed(GameKit.GKSession, System.String, Foundation.NSError)", + "GameKit.Mono_GKSessionDelegate.PeerConnectionRequest(GameKit.GKSession, System.String)", + "GameplayKit.GKObstacleGraph`1..ctor(ObjCRuntime.NativeHandle)", + "ImageIO.CGImageDestination..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "ImageIO.CGImageMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "ImageIO.CGImageMetadataTag..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "ImageIO.CGImageSource..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "MessageUI.Mono_MFMailComposeViewControllerDelegate.Finished(MessageUI.MFMailComposeViewController, MessageUI.MFMailComposeResult, Foundation.NSError)", + "MessageUI.Mono_MFMessageComposeViewControllerDelegate.Finished(MessageUI.MFMessageComposeViewController, MessageUI.MessageComposeResult)", + "Metal.MTLIOCompressionContext..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Microsoft.iOS, Version=26.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065", + "Microsoft.MacCatalyst, Version=26.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065", + "Microsoft.macOS, Version=26.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065", + "Microsoft.tvOS, Version=26.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065", + "Network.NSProtocolFramerOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWAdvertiseDescriptor..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWBrowser..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWBrowserDescriptor..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWBrowseResult..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWConnection..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWConnectionGroup..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWContentContext..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWDataTransferReport..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWEndpoint..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWError..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWEstablishmentReport..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWEthernetChannel..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWFramer..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWFramerMessage..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWInterface..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWIPMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWListener..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWMulticastGroup..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWMultiplexGroup..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWParameters..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWPath..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWPathMonitor..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWPrivacyContext..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolDefinition..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolIPOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolQuicOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolStack..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolTcpOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolTlsOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProtocolUdpOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWProxyConfig..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWQuicMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWRelayHop..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWResolutionReport..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWResolverConfig..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWTcpMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWTlsMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWTxtRecord..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWUdpMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWWebSocketMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWWebSocketOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWWebSocketRequest..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Network.NWWebSocketResponse..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "ObjCRuntime.Class..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "ObjCRuntime.Protocol..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "ObjCRuntime.Runtime.Initialize(ObjCRuntime.Runtime/InitializationOptions*)", + "ObjCRuntime.Runtime.SafeInitialize(ObjCRuntime.Runtime/InitializationOptions*, System.IntPtr*)", + "ObjCRuntime.Runtime/ClassHandles.SetHandle(System.Int32, ObjCRuntime.NativeHandle*, System.IntPtr*)", + "ObjCRuntime.Selector..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "OpenGL.CGLContext..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "OpenGL.CGLPixelFormat..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "PrintCore.PMPageFormat..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "PrintCore.PMPaper..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "PrintCore.PMPrintCoreBase..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "PrintCore.PMPrinter..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "PrintCore.PMPrintSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "PrintCore.PMPrintSettings..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "SearchKit.SKDocument..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "SearchKit.SKIndex..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "SearchKit.SKSearch..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "SearchKit.SKSummary..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.Authorization..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecAccessControl..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecCertificate..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecCertificate2..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecIdentity..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecIdentity2..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecKey..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecPolicy..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecProtocolMetadata..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecProtocolOptions..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecTrust..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "Security.SecTrust2..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "System.Boolean AppKit.ActionDispatcher::WorksWhenModal()", + "System.Net.Http.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidCompleteWithError(Foundation.NSUrlSession, Foundation.NSUrlSessionTask, Foundation.NSError)", + "System.Net.Http.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidReceiveChallenge(Foundation.NSUrlSession, Foundation.NSUrlSessionTask, Foundation.NSUrlAuthenticationChallenge, System.Action`2)", + "System.Net.Http.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidReceiveData(Foundation.NSUrlSession, Foundation.NSUrlSessionDataTask, Foundation.NSData)", + "System.Net.Http.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.DidReceiveResponse(Foundation.NSUrlSession, Foundation.NSUrlSessionDataTask, Foundation.NSUrlResponse, System.Action`1)", + "System.Net.Http.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.WillCacheResponse(Foundation.NSUrlSession, Foundation.NSUrlSessionDataTask, Foundation.NSCachedUrlResponse, System.Action`1)", + "System.Net.Http.NSUrlSessionHandler/NSUrlSessionHandlerDelegate.WillPerformHttpRedirection(Foundation.NSUrlSession, Foundation.NSUrlSessionTask, Foundation.NSHttpUrlResponse, Foundation.NSUrlRequest, System.Action`1)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Close()", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.GetBuffer(out System.IntPtr&, out System.UIntPtr&)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.GetProperty(Foundation.NSString)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.HasBytesAvailable()", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Open()", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Read(System.IntPtr, System.UIntPtr)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Schedule(Foundation.NSRunLoop, Foundation.NSString)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.SetCFClientFlags(CoreFoundation.CFStreamEventType, System.IntPtr, System.IntPtr)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.SetProperty(Foundation.NSObject, Foundation.NSString)", + "System.Net.Http.NSUrlSessionHandler/WrappedNSInputStream.Unschedule(Foundation.NSRunLoop, Foundation.NSString)", + "UIKit.NIDUICellAccessoryPosition.Create(System.IntPtr)", + "UIKit.NIDUIConfigurationColorTransformerHandler.Create(System.IntPtr)", + "UIKit.UIAccessibilityCustomAction/FuncBoolDispatcher.Probe(UIKit.UIAccessibilityCustomAction)", + "UIKit.UIControlEventProxy.Activated()", + "UIKit.UIGestureRecognizer.OnDispose()", + "UIKit.UIGestureRecognizer/Callback`1.Activated(T)", + "UIKit.UIGestureRecognizer/ParameterlessDispatch.Activated()", + "UIKit.UIGestureRecognizer/ParametrizedDispatch.Activated(UIKit.UIGestureRecognizer)", + "UIKit.UIImageStatusDispatcher.Callback(UIKit.UIImage, Foundation.NSError, System.IntPtr)", + "UIKit.UISearchController/__Xamarin_UISearchResultsUpdating.UpdateSearchResultsForSearchController(UIKit.UISearchController)", + "UIKit.UITextField/_UITextFieldDelegate.DidChangeSelection(UIKit.UITextField)", + "UIKit.UITextField/_UITextFieldDelegate.EditingEnded(UIKit.UITextField, UIKit.UITextFieldDidEndEditingReason)", + "UIKit.UITextField/_UITextFieldDelegate.EditingEnded(UIKit.UITextField)", + "UIKit.UITextField/_UITextFieldDelegate.EditingStarted(UIKit.UITextField)", + "UIKit.UITextField/_UITextFieldDelegate.ShouldBeginEditing(UIKit.UITextField)", + "UIKit.UITextField/_UITextFieldDelegate.ShouldChangeCharacters(UIKit.UITextField, Foundation.NSRange, System.String)", + "UIKit.UITextField/_UITextFieldDelegate.ShouldChangeCharacters(UIKit.UITextField, Foundation.NSValue[], System.String)", + "UIKit.UITextField/_UITextFieldDelegate.ShouldClear(UIKit.UITextField)", + "UIKit.UITextField/_UITextFieldDelegate.ShouldEndEditing(UIKit.UITextField)", + "UIKit.UITextField/_UITextFieldDelegate.ShouldReturn(UIKit.UITextField)", + "UIKit.UIVideoStatusDispatcher.Callback(System.String, Foundation.NSError, System.IntPtr)", + "UIKit.UIView/_UIViewStaticCallback.OnEnd()", + "UIKit.UIView/_UIViewStaticCallback.OnStart()", + "VideoToolbox.VTCompressionSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTDecompressionSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTFrameSilo..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTHdrPerFrameMetadataGenerationSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTMotionEstimationSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTMultiPassStorage..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTPixelRotationSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTPixelTransferSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTRawProcessingSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + "VideoToolbox.VTSession..ctor(ObjCRuntime.NativeHandle, System.Boolean)", + }; } } diff --git a/tests/cecil-tests/ApiTest.cs b/tests/cecil-tests/ApiTest.cs index a415684f9881..457a3382ad40 100644 --- a/tests/cecil-tests/ApiTest.cs +++ b/tests/cecil-tests/ApiTest.cs @@ -158,5 +158,36 @@ public void InvalidStrings () Helper.AssertFailures (failures, knownFailuresInvalidStrings, nameof (knownFailuresInvalidStrings), "In the file tests/cecil-tests/ApiTest.cs, read the guide carefully.", (v) => $"{v.Location}: {v.Message}"); } + + [Test] + public void BannedAttributes () + { + Configuration.IgnoreIfAnyIgnoredPlatforms (); + + var bannedAttributeTypes = new [] { + new { Namespace = "Foundation", Name = "PreserveAttribute" }, + }; + + var failures = new Dictionary (); + foreach (var info in Helper.NetPlatformImplementationAssemblyDefinitions) { + foreach (var ap in info.Assembly.EnumerateAttributeProviders ()) { + if (!ap.HasCustomAttributes) + continue; + + foreach (var ca in ap.CustomAttributes) { + foreach (var tp in bannedAttributeTypes) { + if (!ca.AttributeType.Is (tp.Namespace, tp.Name)) + continue; + + var fullname = ap.AsFullName (); + failures [fullname] = (Message: $"'{fullname}' has a [Preserve] attribute", Location: ap.RenderLocation (), Provider: ap); + break; + } + } + } + } + + Helper.AssertFailures (failures, knownFailuresBannedAttributes, nameof (knownFailuresBannedAttributes), "APIs with [Preserve] - alternative solutions must be found!", (v) => $"{v.Location}: {v.Message}"); + } } } diff --git a/tests/cecil-tests/ConstructorTest.cs b/tests/cecil-tests/ConstructorTest.cs index 6dba05a3b517..e8e13fc18598 100644 --- a/tests/cecil-tests/ConstructorTest.cs +++ b/tests/cecil-tests/ConstructorTest.cs @@ -407,8 +407,43 @@ public void INativeObjectIntPtrConstructorDoesNotOwnHandle (ApplePlatform platfo Assert.That (failures, Is.Empty, "No failures"); } + bool IsPreservedByDynamicDependencyAttributeOnStaticCctor (MethodDefinition ctor) + { + var type = ctor.DeclaringType; + var cctor = type.Methods.SingleOrDefault (m => m.IsStatic && m.IsConstructor); + if (cctor is null) + return false; + + if (!cctor.HasCustomAttributes) + return false; + + foreach (var ca in cctor.CustomAttributes) { + if (ca.AttributeType.Name != "DynamicDependencyAttribute") + continue; + switch (ca.ConstructorArguments.Count) { + case 2: + var memberTypes = (DynamicallyAccessedMemberTypes) (int) ca.ConstructorArguments [0].Value; + var targetType = ca.ConstructorArguments [1].Value as TypeReference; + if (targetType is null) + continue; + if (targetType.FullName != type.FullName) + continue; + if ((memberTypes & DynamicallyAccessedMemberTypes.PublicConstructors) == DynamicallyAccessedMemberTypes.PublicConstructors && ctor.IsPublic) + return true; + if ((memberTypes & DynamicallyAccessedMemberTypes.NonPublicConstructors) == DynamicallyAccessedMemberTypes.NonPublicConstructors && !ctor.IsPublic) + return true; + break; + } + } + + return false; + } + bool IsConditionallyPreserved (MethodDefinition ctor) { + if (IsPreservedByDynamicDependencyAttributeOnStaticCctor (ctor)) + return true; + if (!ctor.HasCustomAttributes) return false; diff --git a/tests/common/shared-dotnet.csproj b/tests/common/shared-dotnet.csproj index ff111b201a70..f23ab78e6de9 100644 --- a/tests/common/shared-dotnet.csproj +++ b/tests/common/shared-dotnet.csproj @@ -120,6 +120,14 @@ + + + + $(DefineConstants);NATIVEAOT + + false + +