Fixes race condition where finalized objects are resurrected by the finalizer and for a brief moment `Runtime.TryGetNSObject`/`Runtime.GetNSObject` would return them even though a new instance is supposed to be used. In multi-threaded scenarios this would result in reused objects (same native handle) to suddenly become invalid when the UI thread processes the delayed finalization.
Fixes#13921
Implement the UIResponderStandardEditActions protocol, move the
corresponding API from UIResponder there, and make sure UIResponder implements
the new UIResponderStandardEditActions protocol (which should make this move a
non-breaking change, since the protocol is inlined in UIResponder).
Include all files in the project's Resources subdirectory as BundleResource
items (except .DS_Store files, which are pretty omnipresent on macOS).
Also, contrary to the other default includes, add a condition so files are
only included if we have a resource prefix (typically "Resources"), otherwise
the entire hard drive might be included, and that's not really what we want.
Fixes https://github.com/xamarin/xamarin-macios/issues/13808.
When exception marshalling was originally implemented, for backwards
compatibility concerns it was only turned on by default for platforms that
really needed it (watchOS).
However, exception marshalling is by far the safest option, so in .NET we're
enabling it by default for all platforms (it's still possible to disable it
for those who wants to).
Ref: https://docs.microsoft.com/en-us/xamarin/ios/platform/exception-marshaling
We have a problem that's shown up a few times, where we're given an instance
of a native type, where the closest bound managed type is a type declared as
[Abstract] in the api definition. In this case, we want to create an instance
of the [Abstract] type to wrap the native instance, but that hasn't been
possible because the managed type is abstract.
Note: this is totally fine from the OS perspective: it might have created an
instance of a private subclass we haven't bound (or it might even be a public
subclass we just haven't bound yet).
The fix is to:
* Stop making [Abstract] classes in the api definition abstract classes in the generated code.
* Make the default constructor default to "protected" visibility for [Abstract] classes.
This way we can still create instances of these types at runtime when we need
them, but they must be subclassed in order to create a managed instance of
them.
Additionally I also had to make abstract members virtual for such types
(because otherwise the type would have to be abstract as well), and instead
throw a "You_Should_Not_Call_base_In_This_MethodException" in the
corresponding method implementations.
Fixes https://github.com/xamarin/xamarin-macios/issues/4969.
This makes diagnosing what happens much easier in some cases.
Exhibit A, pre fix:
*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Failed to lookup the required marshalling information.
Additional information:
Selector: conformsToProtocol:
Type: ViewController
Exhibit B, post fix:
*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Failed to lookup the required marshalling information.
Additional information:
Selector: conformsToProtocol:
Type: ViewController
(ObjCRuntime.RuntimeException)
Failed to get the 'this' instance in a method call to templ.ViewController.InvokeConformsToProtocol. (ObjCRuntime.RuntimeException)
at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject(Type type, IntPtr selector, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
at ObjCRuntime.Runtime.GetMethodAndObjectForSelector(IntPtr klass, IntPtr sel, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
at ObjCRuntime.Runtime.get_method_and_object_for_selector(IntPtr cls, IntPtr sel, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc, IntPtr& exception_gchandle)
Failed to marshal the Objective-C object 0x7f813fd2f470 (type: ViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'templ.ViewController' does not have a constructor that takes one NativeHandle argument). (ObjCRuntime.RuntimeException)
at ObjCRuntime.Runtime.MissingCtor(IntPtr ptr, IntPtr klass, Type type, MissingCtorResolution resolution)
at ObjCRuntime.Runtime.ConstructNSObject[T](IntPtr ptr, Type type, MissingCtorResolution missingCtorResolution)
at ObjCRuntime.Runtime.ConstructNSObject(IntPtr ptr, IntPtr klass, MissingCtorResolution missingCtorResolution)
at ObjCRuntime.Runtime.GetNSObject(IntPtr ptr, MissingCtorResolution missingCtorResolution, Boolean evenInFinalizerQueue)
at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject(Type type, IntPtr selector, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
* A lot of obsolete/deprecated removal.
* Remove the NSDraggingInfo model, which required numerous other changes.
* Remove the NSPasteboardReading/NSPasteboardWriting models, which required more
numerous changes.
* Update the tests accordingly.
* Use 'ObjCException' instead of 'MonoTouchException' as the managed exception
type wrapping an NSException for all platforms in .NET (that was already the
case for macOS, so no change there).
* Make the ObjCException class behave like the MonoTouchException class does.
* Move the ObjCException type to the ObjCRuntime namespace in .NET.
Fixes https://github.com/xamarin/xamarin-macios/issues/13855.
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
Also make the (NativeHandle) constructor protected instead of public, to make
it clearer that it's not for public consumption.
And modify the template tests to execute the template if we can.
Fixes https://github.com/xamarin/xamarin-macios/issues/13979.
This turned out a bit complex, because numerous ModelIO APIs were initially bound
with wrong matrix types, and had to be rebound later (our matrix type was transposed
with regards to the native matrix type). The new versions often had to use worse
names, so that's being fixed now. This means that numerous tests had to be updated,
because the original API now returns non-transposed matrices.
* [CHIP] Updates for Xcode13.2 beta 1
* Update based on feedback
* Update based on feedback and intro test failure
* Update xtro .todo files
* Fix some breaking API changes
* Delete silly typos
This hopefully solves a few problems on M1, where we'd want to execute with
.NET 5 (last stable .NET release), but that version only supports x86_64, and
then if an ARM64 version of .NET 6 was also installed, things would break in
mysterious ways.
This way we have full control over what happens, and also a consistent
environment across all machines.
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
* Mostly just removal of obsolete/deprecated API.
* Modified CAScrollLayer.ScrollMode to use the good name
(CAScrollLayer.ScrollMode) for the strongly typed enum, and then have a
WeakScrollMode property for the NSString version (like we do elsewhere).
* Use `is` instead of `==` for null checks
* Use `ThrowHelper` to throw common exceptions
* Use faster `CFString` API (over the slower `NSString` variants)
* [tests] Adjust UTTypeTest.cs to build for net profile
* Use the native `NSStringFrom*` API so we can, eventually, use the
native code to parse them from `NSString` and also ensure increased
compatibility with any code that expects the native string representation
* Add unit tests for `ToString` methods
Also use [`System.HashCode`](https://docs.microsoft.com/en-us/dotnet/api/system.hashcode?view=net-6.0) to generate the hash code
* Update dependencies from https://github.com/dotnet/runtime build 20220117.8
Microsoft.NETCore.App.Ref
From Version 6.0.2-mauipre.1.22054.8 -> To Version 6.0.2-mauipre.1.22067.8
* [tests] Adjust according to BCL changes.
* Update dependencies from https://github.com/dotnet/runtime build 20220118.10
Microsoft.NETCore.App.Ref
From Version 6.0.2-mauipre.1.22054.8 -> To Version 6.0.2-mauipre.1.22068.10
* Update dependencies from https://github.com/dotnet/runtime build 20220119.5
Microsoft.NETCore.App.Ref
From Version 6.0.2-mauipre.1.22054.8 -> To Version 6.0.2-mauipre.1.22069.5
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
* Improve the API for both legacy Xamarin and .NET.
* Obsolete the old API in legacy Xamarin and point to the new API.
* Remove the old API in .NET.
* Add nullability.
This is mostly removing obsolete/removed API, except for
SKProduct.ContentVersion, where the XAMCORE_4_0 annotations were wrong and the
property is still alive and kicking.
This means removing numerous obsolete/deprecated methods where better/more
correct alternatives already exist.
Also fix one obsolete message and adjust the tests.
These types come from the CFNetwork.framework, but for some reason they were bound inside CoreServices many years ago.
This resolves a potential issue where we might end up linking with the
CoreServices framework instead of CFNetwork framework (because we use the
namespace of types to determine which framework they belong to).
- Disable check "[FAIL] Both '{t}' and '{m}' are marked with `{s}`." type and member on that type in NET
- Due to the behavior of NET6 style attributes, we are forced to duplicate availability attributes in many cases
- See https://github.com/xamarin/xamarin-macios/issues/10170 for details
This makes it easier to figure out problems in consuming code, since it makes
it easier to identify where things start to go wrong.
Fixes https://github.com/xamarin/maccore/issues/2539.
In .NET, all files that should be published (put into the final .app bundle) are put into the @(ResolvedFileToPublish) item group, and at the end of the build process, .NET will publish all the files in that item group. Which files are in this item group, and how they're put in there, is out of our control (it's just how the build process works in .NET), so we'll have to cope.
Additionally, publishing an app for Apple platforms is different than publishing other .NET apps, because we can't just put all the files in the a directory like .NET usually does, we have a fairly strict directory structure we need to follow, and it also differs between platforms (the structure is different between macOS and iOS for instance).
This means that for every file in the `ResolvedFileToPublish` item group, we have to figure out:
* Should it be put into the app bundle in the first place?
* If so, in which subdirectory (if any)?
This PR implements these changes. The exact details are explained in a document in the PR, but the general logic is:
* We make an educated guess for some types of files we know about (assemblies, unmanaged libraries, images, etc).
* We provide a way to set metadata on each item specifying which type of item it is (assembly, unmanaged library, image, etc), and we'll treat the item as such. This method can also be used to override the guess we made (for files that shouldn't be published for instance).
* We warn if we run into files we're not educated enough to be able to guess about, and for which there's no custom metadata set.
Fixes https://github.com/xamarin/xamarin-macios/issues/12572.
Rename the public fields in CGAffineTransform to:
* Follow our naming convention (public API should always start with an
upper-case letter).
* Use the same names as Apple's version to ease porting Swift/Objective-C
code.
Fixes https://github.com/xamarin/xamarin-macios/issues/13494.
* Remove obsolete API from .NET.
* Change API marked with XAMCORE_4_0 due to naming problems to be in .NET.
* Change API marked with XAMCORE_4_0 due to using non-generic NSDictionary to be
in XAMCORE_5_0 instead (yay!). This is because of #13704, which can make using
generic NSDictionary in API buggy, and I feel it's a bit too risky to change this
for .NET with the time we have available (no time to fix#13704). Additionally,
moving this to XAMCORE_5_0 makes it possible to keep grepping for XAMCORE_4_0 to
see what's left. Update all the CoreData API to be better as defined by our XAMCORE_4_0
define. Mostly using generic NSSet/NSDictionary types instead of the non-generic
ones, and other misc naming improvements.
* Change API marked with XAMCORE_4_0 due to both of the above to do both of the
above - add a version of the naming issue fixed for .NET + a version with the generic
dictionary for XAMCORE_5_0.
* Implement a column-major version of SCNMatrix4 in .NET to match native code.
* This was done by copying the existing SCMatrix4 implementation, and modify it
as required (doing it with conditional compilation in the same file turned out
to be quite messy, so I opted for using different files for legacy Xamarin and
.NET).
* There was one major change: the matrix inversion algorithm is new (copied from
.NET instead), because the legacy Xamarin version showed strange results with
some test values.
* Add setters for SCNMatrix4.Column[0-3] for legacy Xamarin to match the .NET API.
* Add CreateFromColumns methods for legacy Xamarin to match the .NET API.
* Add tests for all the new API.
Fixes https://github.com/xamarin/xamarin-macios/issues/4652.
It's our own enum, and all the API using it have been obsoleted/removed.
There doesn't seem to be any other usage of it on GitHub either (only our own
source code and documentation).
Also remove the Unscaled field, it's removed from the headers, and it was
deprecated before the earliest macOS version we support.
Also also fix a few xtro issues.
* Fix `CGColorConversionInfoTriple` name (missing initial `C`)
* Rename `RectangleFExtensions` to `CGRectExtensions` since the former
name has not been around for a while
* Remove API naming mistakes (already under XAMCORE_4_0)
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Public fields shouldn't start with a lower-cased letter.
Also provide public properties in legacy Xamarin so that we can write
identical code for both, and obsolete the lower-cased fields.
AudioUnit needs a GCHandle in the input callback, which means we have to create it
when SetInputCallback is called (like we already do for SetRenderCallback).
Fixes https://github.com/xamarin/xamarin-macios/issues/13637.
* First version cecil test
* Add missing net6 platform assemblies
* Make it work for Catalyst
* Add namespace switch and clean up code
* Update based on feedback
* Update based on feedback
* Update based on feedback
* Make test pass by default
* Fix bgen tests by fixing GetRefNuGetName
* Update based on feedback
Co-authored-by: Chris Hamons <chris.hamons@xamarin.com>
* [ObjCRuntime] Fix the DisposableObject.Owns property to return the correct value. Fixes#13646.
Ops...
Also add tests to avoid more oopses.
Fixes https://github.com/xamarin/xamarin-macios/issues/13646.
* Update tests/monotouch-test/AudioToolbox/AudioConverterTest.cs
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
* [Xcode13.2] Bump to Xcode 13.2 RC (#13497)
* [Xcode13.2] Bump to Xcode 13.2 Beta 2
Breaking changes addressed for legacy
* HomeKit
* CallKit
* CoreLocation
* [xcode13.2] Bump to Xcode 13.2 RC and apply feedback
* [AppKit] Fix missing Notifications
* Fix xtro
* [xcode13.2] Bump versions and use stable Xcode 13.2
* [monotouch-tests] Make TestAddingByComponents work on the last day of the year
Happy New Year!!
* NO BOM PLZ!
AutoGeneratedName was a toggle to implement a certain (correct) behavior,
while at the same time not cause breaking changes.
Now that we can do breaking changes in .NET, we can remove the toggle (i.e.
the property), and just always do the right thing (that is: automatically
generate a _unique_ Objective-C name for Model classes, unless a name is
specified manually).
Ref: https://github.com/xamarin/xamarin-macios/issues/5107
We're copying files differently to the bundle now, and we end up doing less
when not building on a Mac, which is why we're not copying Xamarin.iOS.dll
anymore.
Once upon a long time ago we decided to mark the properties in the
UITextInputTraits protocol as required in our API definition, because that way
we'd inline these properties in any class that implemented the
UITextInputTraits protocol, which made calling these properties much easier.
At a later point, we implemented better support for protocols, and now we
automatically generate extension methods for such properties (a corresponding
Get/Set method for the get/set property accessors), so we don't need these
inlined properties anymore.
However, removing them would be a breaking change, so we were stuck with these
redundant inlined properties, until .NET came along.
Ref: 0e80570863
Fixes https://github.com/xamarin/xamarin-macios/issues/5831.
Take into account any Bind attributes on optional property getters and setters
on protocols when generating the Get* and Set* extension methods, so that we
use the right selector.
Fixes https://github.com/xamarin/xamarin-macios/issues/12727.
Don't add FileNativeReferences to the main libraries to link with, because we
pass that list of main libraries to the LinkNativeCodeTask, and we're already
passing the FileNativeReferences for a different task parameter.
This means that we end up adding the file native reference twice to the linker
arguments, and that's wasteful. It can also cause problems if those linker
arguments aren't always computed in the same way (once as a relative path,
once as an absolute path for instance).
Fixes https://github.com/xamarin/xamarin-macios/issues/13503.
Once upon a time there was a single VTCompressionSession.Create method, which
was [driving users insane][1] - they had to manually call CFRetain to avoid
crashes! What an abomination!!
Insane users are clearly not happy users, and we wanted happy users, so time
and effort went into creating a solution: a new Create overload was devised
and [implemented][1], taking extreme care to not break our brave and insane
existing users who had to manually call CFRetain. Because the fix would break
existing users - the now extraneous CFRetain would mean that their apps would
leak memory. *A lot* of it! That's bad, so we decided to make sure that didn't
happen.
Of course, dear old Murhpy wanted a say, so the new Create overload didn't do
as intended. In fact, it had the same insane behavior the old Create overload
had! Ops.
But Murphy decided to have even more fun: the changes were so buggy, that they
in fact fixed the old Create overload! Which from now on wouldn't require the
horrendous manual CFRetain calls... and effectively introducing the leak the
fix was trying so hard to not introduce.
Oh dear Murphy.
Of course he had another trick up his sleeve: in our extreme efforts to help
our users, we added an Obsolete attribute that would tell people to use the
new Create overload.
Let that sink in for a moment: we had an Obsolete attribute on a function that
was (now) perfectly fine, telling users to use a function that was broken.
To get the correct behavior, users would now have to to remove their manual
CFRetain calls, and ignore the obsolete warning on the old (and correct)
Create overload which told users to use the new (and buggy) Create overload.
In other words: still insanity, just a slightly different flavor.
Murphy had a field day!
Time went by, and eventually a sane enough user [reported the insanity to
us][2]. Even better: the user actually provided a fix! Truly, we have some
amazing users.
Unfortunately, the user didn't have access to our code history, and thus was
obviously not able to see the whole picture, and the fix ended up being
incorrect.
Unrelated lesson learned: don't forget your history, otherwise you'll end up
repeating mistakes from the past.
So now came the problem: how to fix all the APIs? In a way that didn't make
our users' existing apps just suddenly start crashing or leaking?
There really was no way, so nothing really happened for quite a while.
Then, an opportunity presented itself: we'd be able to do [widespread breaking
changes][3].
So, hoping that Murphy stays away this sunny winter day, I'm changing both the
new and the old Create overloads to do the right thing. But only in .NET,
where we can do breaking changes! Or at least that's my intention. I've tried
to stave off our dear old friend by adding his arch enemy: unit tests. Which,
of course, Murphy couldn't stay away from, but it seems adding a few
Thread.Sleep calls makes him bored enough to stay away. Hopefully for good...
[1]: 66c50b9a17
[2]: https://github.com/xamarin/xamarin-macios/pull/2070
[3]: https://github.com/xamarin/xamarin-macios/issues/13087
* Capture evaluation output, and write it all to the terminal when something
goes wrong. This way we can see the entire output next to the failure (often
there's a lot of stuff written to the terminal from different threads, and
this way we get all that matters written together).
* Only evaluate one project at a time, to avoid overloading the machine.
* Only execute `git ls-files` once at a time, to avoid overloading the machine.
* Bump evaluation timeout to 5 minutes.
* Also increase the time for git to list files in a directory to 60 seconds.
Hopefully this will fix errors like this:
* `Unable to evaluate the property OutputPath, build failed with exit code 0. Timed out: True`
* `System.Exception: Failed to list the files in the directory /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/tmp-test-dir/monotouch-test3403 (TimedOut: True ExitCode: 0)`
This fixes a problem where we'd build the same project reference from
dotnet-shared.csproj in parallel, and each build would stomp on eachother
(because we'll now clone the project references in dotnet-shared.csproj).
This als required updating project files to use MSBuildThisFileDirectory
instead of MSBuildProjectDirectory, which makes it easier for xharness to
inline/process these files, because MSBuildThisFileDirectory is easy to know
when processing a file, while MSBuildProjectDirectory depends on the calling
project, which complicates matters significantly.
A fix in MonoTouch.Dialog was also required.
New commits in migueldeicaza/MonoTouch.Dialog:
* migueldeicaza/MonoTouch.Dialog@59fbf5b [dotnet] Shared project files don't need the DefaultTargets/ToolsVersion/xmlns attributes.
Diff: 4d0e0a9a5f..59fbf5bb1b
Fixes https://github.com/xamarin/maccore/issues/2527.
If NSFunctionKey isn't in Mac Catalyst in legacy Xamarin, it shouldn't be in
.NET either, so adjust the conditional logic accordingly.
Also make the NSFunctionKey enum a non-native enum in .NET, like it's in the
headers.
Remove Runtime.Arch and ObjCRuntime.Arch from Mac Catalyst, because they don't
apply for a Mac Catalyst app (which is neither a simulator environment, nor a
device environment).
This means that code using these APIs will have to be re-evaluated to
determine what's the correct behavior for Mac Catalyst.
Also update our tests accordingly.
Fixes https://github.com/xamarin/xamarin-macios/issues/10312.
* Change dotnet-linker to only care about whether we're actually trimming anything or not.
* Allow LinkMde/MtouchLink to not be set if TrimMode is set.
* Detect if any assemblies are linked or not by checking the global TrimMode
property + any TrimMode properties on assemblies.
Fixes https://github.com/xamarin/xamarin-macios/issues/13518.
named 'Info.plist', and assume that's the app manifest.
That doesn't quite work when we end up with multiple 'Info.plist' entries in any
of those item groups (one example being a framework as a BundleResource - all frameworks
have an Info.plist, and there's no good way to distinguish what the developer's intention
was).
So:
1. Implement a 'AppManifestDetectionEnabled' property to disable automatic app manifest
detection.
2. Add a public 'AppBundleManifest' property that specifies the app manifest
(this is just a renamed version of our previously private '_AppManifest' property).
This makes it possible for app developers to:
* Disable automatic app manifest detection.
* Still have an app manifest by specifying it manually.
* Disable automatic app manifest detection, but also not specify an app manifest
manually (so no custom app manifest at all).
Also:
* Rename '_AppBundleManifest' to '_AppBundleManifestPath' to make it less confusing
with the new 'AppBundleManifest' property.
Symlinks to directories are treated the same as other symlinks (as files), not
as directories. This way we don't end up re-creating a directory hierarchy
when we only have to create a symlink.
* Change all XAMCORE_4_0 conditions to NET conditions.
* Add numerous Release attributes that xtro started complaining about.
* Misc other minor API changes/updates.
We are in a situation where:
1. .NET MAUI is still in preview
2. We need dotnet/runtime fixes for MAUI, but we don't necessarily want all fixes to go into the .NET 6 service release.
The solution is to simplify use different builds/packs from dotnet/runtime.
Ref: https://github.com/xamarin/xamarin-android/pull/6542
* [tools] Unify Application.link_flags and Application.gcc_flags from mtouch and mmp into Application.CustomLinkFlags.
* [tests] Update mtouch tests according to mtouch changes.
* [ObjCRuntime] Remove deprecated availability attribute API from .NET.
They're quite useful for binding code though, so instead of removing them completely,
make them binding-only attributes (like numerous other binding attributes we have)
for .NET.
* [src] Remove removed attributes from the list of attributes that should be removed by the linker.
* [tests] Update tests to not use the old attributes for .NET.
There can't be any files in the root directory of the app bundle for macOS and
Mac Catalyst, otherwise code signing will fail. The problem is that Mono will
create a crash report in the current directory if the process crashes, and the
current directory is the root directory of the app bundle, which means that if
running an app crashes, the next build will likely fail because of the crash
report.
We had logic to detect this and remove any crash reports, but our crash report
detection pattern wasn't good enough and let some files through. This PR
updates that pattern, and also improves the code to report warnings for any
other files in the app bundle's root directory.
* Remove System.nint and System.nuint from .NET
* Add support for C#'s nint/nuint types to the generator.
* Accept IntPtr/UIntPtr as target types for BindAs attributes for NSNumber conversions.
* Fix a few APIs to take/return NativeHandle instead of IntPtr.
Fixes https://github.com/xamarin/xamarin-macios/issues/10508.
* [monotouch-test] Ignore a few tests in non-ARM64 simulators.
Some tests fail when running on an M1, but in a x64_86 mode, so just ignore
those unless we're running on ARM64 (this will currently exclude them on
x86_64 hardware too, but that'll eventually not be a problem anymore when
there's no more x86_64 hardware, and just checking for ARM64 is easier than
checking for x86_64 mode on an ARM64 CPU).
* Make more legacy projects unsafe.
* [Foundation] Make numerous CFArray and NSArray APIs take/return NativeHandle instead of IntPtr.
* [src] Fix a lot of other cases of IntPtr -> NativeHandle.
This is just fallout from the CFArray/NSArray in the previous commit.
Check for the x64 version of .NET to see if it's installed if the default
dotnet location doesn't exist (the x64 version will exist on an ARM64 mac when
installing the x64 version of .NET).
Also allow the .NET unit tests to be executed using any recentish version of
.NET.
Add a new struct, ObjCRuntime.NativeHandle, which will be used to represent
native handles for .NET (instead of using IntPtr). The main purpose is to be
able to use 'nint' as a number in API while not being prevented from using
native handles as well.
One example is NSMutableString, which has a constructor that takes a single
'nint capacity' parameter. With this change, we'll also be able to have a
constructor that takes a native handle in .NET - otherwise we'd have two
constructors with the same signature, because a C# 'nint' is just an 'IntPtr'.
This change required numerous changes pretty much everywhere. The work is
split up in commits as well as I was able to, and each commit explains what it
does.
Fixes https://github.com/xamarin/xamarin-macios/issues/13126.
* Make the .NET project files for BundleResources and EmbeddedResources follow
the pattern of all the other test projects.
* Move the LangVersion and AllowUnsafeBlocks propertieso to the shared project
file.
Change the logic to detect if an API is available to:
* First check if there are any applicable UnavailableOSPlatform attributes,
and only if an applicable attribute is found, then state that the API is
unavailable (we can't ascertain that an API is available from an
UnavailableOSPlatform attribute, only that it's unavailable).
* Once we know there are no applicable UnavailableOSPlatform attributes, we go
on to check for applicable SupportedOSPlatform attributes, and if one is
found, then we can say whether the API is available or not.
* If neither attributes were found, and we're building for Mac Catalyst, then
repeat the two above checks for iOS instead.
* If still nothing, then assume the API is available (while incorrect, it's
how our attributes are currently implemented).
This fixes introspection showing numerous test failures on older OS versions,
because we were detecting availability wrong - we were assuming that if
there's an UnavailableOSPlatform attribute whose version didn't match the OS
version, that the API was available (test case that proves this logic is
incorrect: OS version = 1.0, API introduced in 2.0, API unavailable in 3.0
- we'd detect that OS version 1.0 < unavailable in 3.0, and say "yay, we're
not unavailable, so we must be available!").
This turned out a bit complicated, because we're lipo'ing together both the simulator
and device slices, and that doesn't work anymore when ARM64 is both a simulator and
a device architecture. The solution is a custom lipo logic that doesn't include the
simulator version of the ARM64 architecture in the final binary.