Граф коммитов

6345 Коммитов

Автор SHA1 Сообщение Дата
Alex Soto 46eaabc17d [xcode14.3] Update bindings to Xcode 14.3 2023-03-29 14:37:51 -04:00
Rolf Bjarne Kvinge d5ad7db296
[tests] Improve the Blittable P/Invoke test to report signatures with MarshalAs attributes. (#17879)
Also augment the test to use existing helper methods to compare actual
failures with known failures.
2023-03-28 12:44:55 +02:00
Manuel de la Pena cc695a8196
[Generator] Clean the attribute work. (#17570)
Some changes:

1. Move all the static attr related methods to the attr factory.
2. Make it simpler to see the diff between NET and not by using a
partial class.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-03-23 16:54:08 -04:00
Haritha Mohan 3dff232920
[dotnet] Enable generation of runtime configuration file (#17840)
Set the GenerateRuntimeConfigurationFiles (GRCF) property to true 
to avoid warnings at build time + add test for change.

Diving deeper into the fix...
- This warning only occurs with .NET apps which is why GRCF
is only updated in the dotnet directory and not msbuild (legacy)
- After examining the binlog (see issue), it was found that the GRCF 
was contingent upon the HasRuntimeOutput property, which is only 
defined for executable projects. And in this case, the user's project
output type is library thus both the RuntimeOutput and consequently 
GRCF properties were not enabled.
- By setting the GRCF to true we can address the original warning of 
concern while ensuring the rest of the projects's behavior is not
altered
in mysterious ways (i.e. by touching the RuntimeOutput property or the 
project output type instead, these changes could have extraneous
effects).

Fixes #17543

---------

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2023-03-23 08:10:04 -07:00
Rolf Bjarne Kvinge 6e2ff59b30
[tests] Port Cecil tests to a .NET test project. (#17836) 2023-03-23 08:34:52 +01:00
Rolf Bjarne Kvinge 07198f1224
[tests] Add Windows .NET test that exercises some of our test configuration code. (#17874) 2023-03-22 20:23:26 +01:00
Rolf Bjarne Kvinge 999c5a3e97
[tests] Share code to verify failures. (#17872)
We have some code that verifies a list of failures against a known set of
failures and:

* Fails if any known failure is fixed.
* Fails if there any new (unknown) failures.

Create a helper method that contains this logic, since it's duplicated quite a
few times across various tests.
2023-03-22 11:47:54 +01:00
Rolf Bjarne Kvinge 7ea0044224
[dotnet/msbuild] Copy binding resource packages to output directories together with CopyLocal assemblies. Fixes #13910. (#17806)
With a project structure like this:

* Executable project references a library project.
* The library project references a binding project (or assembly).

The binding project's assembly will be copied to the library project's
output directory during the build. Unless we also make sure any binding
resource packages are copied as well, the executable project won't find those,
and the final app won't contain any native bits from the binding project.

The solution is to add any binding resource packages to the list of
files to be copied to the library's output directory.

Fixes https://github.com/xamarin/xamarin-macios/issues/13910.
2023-03-22 10:49:26 +01:00
Rolf Bjarne Kvinge e86c77a773
[devops] Run .NET tests with the 'Windows' category on Windows (#17796) 2023-03-22 07:49:03 +01:00
Rolf Bjarne Kvinge 6300a6aff7
[tests] Improve NWProtocolIPOptionsTest to not leak exceptions on background threads. (#17824) 2023-03-21 16:16:25 +01:00
Steve Hawley 63470f9b74
add EditorBrowsable to obsolete member (#17854) 2023-03-21 07:41:39 +01:00
Rolf Bjarne Kvinge 38a2442839
[tests] Run the OutOverriddenWithoutOutAttribute test on all platforms on .NET (#17827) 2023-03-17 07:57:59 +01:00
Steve Hawley 61ad2a9dec
CGEventCreate fixed broken call, added tests (#17805)
Fixes https://github.com/xamarin/xamarin-macios/issues/17656
2023-03-16 11:00:12 -04:00
Rolf Bjarne Kvinge c398f333fc
[monotouch-test] Be more accepting in the NSTextInputClient test. (#17795)
It seems we can get different results depending on OS versions, but I had no
success figuring out the conditions that make the results differ, so just
accept all variations we get.
2023-03-15 14:33:44 +01:00
Rolf Bjarne Kvinge 0faf60c2e9
[tests] Add new cecil tests to verify correct block literal usage in our own code. Fixes #15783. (#17794)
This is the final step in our improved block support.

Fixes https://github.com/xamarin/xamarin-macios/issues/15783.

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2023-03-15 14:31:02 +01:00
Rolf Bjarne Kvinge c391695bb1
[AppKit] Add a weakly typed version of NSRulerView.WeakMeasurementUnits. Fixes #17742. (#17779)
There's not a finite list if measurement units, apps can create their own, so
we have to allow weakly typed measurement units (the normal property is bound
using a strong enum to NSRulerViewUnits).

Fixes https://github.com/xamarin/xamarin-macios/issues/17742.
2023-03-15 10:47:11 +01:00
Rolf Bjarne Kvinge 29633a6231
[generator] Make the block callbacks UnmanagedCallersOnly functions in .NET. (#17741)
This also required updating a manual binding since it poked into
generated internals.

Contributes towards https://github.com/xamarin/xamarin-macios/issues/15783.
2023-03-14 10:08:28 +01:00
Alex Soto 91781715a9
[CI] [siminstaller] Bump bots to use the Ventura and make siminstaller more resilient (#17760)
## siminstaller

We are getting a `System.IO.IOException: Resource busy`
when trying to detach with hdiutil on Ventura. When reaching
this spot we are really done with the mounted resource so
let's force detaching and in the event that it fails let's
just log since at this point the simulator is installed.

## CI

Bump bots to use the Ventura images, and Add `macOSName`
parameter to our yaml templates.

`macOSName` maps to the `macOS.Name` capability in our bots, this
way we can set the macOS name we want to use on the bots in bot build and tests.

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2023-03-14 07:27:00 +01:00
Steve Hawley 4c1e5681f1
[dotnet] future proof the test (#17739)
Add documentation in case of future test fails
2023-03-08 12:29:57 -05:00
Rolf Bjarne Kvinge d6d02fa05a
[monotouch-test] Fix bool encoding in tests on ARM64 on Mac Catalyst. (#17695)
Fixes:

    [FAIL] TestTypeEncodings :   #14
        String lengths are both 1. Strings differ at index 0.
        Expected: "B"
        But was:  "c"
        -----------^
2023-03-08 10:43:52 +01:00
Rolf Bjarne Kvinge d1804f5e68
[tests] Use Path.Combine instead of hardcoding '/'. (#17733) 2023-03-08 10:43:24 +01:00
Rolf Bjarne Kvinge a4ae14870f
[generator] Generate block callback signatures using only blittable types. (#17712)
Change the generated block callbacks so that we only use blittable types
(so that the callbacks can become [UnmanagedCallersOnly]).

This involved two changes:

* Use pointer types instead of ref/out types ('int*' instead of 'ref/out int').
* Use 'byte' instead of 'bool'.

Contributes towards https://github.com/xamarin/xamarin-macios/issues/15783.
2023-03-07 17:38:36 +01:00
Rolf Bjarne Kvinge 63e6d9b4e8
[src] Commit some of the response files. (#17718)
We'll soon build and run tests on Windows, and some tests use these response files,
so it makes building these tests on Windows easier if we don't have to re-create
the response files (our generation logic is all written in make, which is not the
easiest on Windows).
2023-03-07 17:32:27 +01:00
Steve Hawley dec6ce3445
[dotnet] final blittable pinvoke (#17723)
test passes now.
2023-03-07 10:16:11 -05:00
Rolf Bjarne Kvinge a39cefa457
[msbuild] Fix nullability issue when compiling for legacy Xamarin. (#17716)
And make sure we don't ignore any such warnings again for a few test projects.
2023-03-07 07:54:21 +01:00
Rolf Bjarne Kvinge 666bd9ae9e
[tests] Fix NSTextInputClient tests on macOS Ventura. (#17713)
Fixes:

    apitest.NSTextInputClient
        [FAIL] NSTextInputClient_ShouldGetBaselineDelta :   NSTextInputClient_ShouldGetBaselineDelta - Returned wrong baseline delta value
            Expected: True
            But was:  False
              at apitest.NSTextInputClient.NSTextInputClient_ShouldGetBaselineDelta () [0x0000e] in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/AppKit/NSTextInputClient.cs:108
        [FAIL] NSTextInputClient_ShouldGetFirstRect :   NSTextInputClient_ShouldGetFirstRect - Returned wrong rect
            Expected: {X=0,Y=0,Width=12,Height=14}
            But was:  {X=0,Y=0,Width=0,Height=14}
              at apitest.NSTextInputClient.NSTextInputClient_ShouldGetFirstRect () [0x00030] in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/AppKit/NSTextInputClient.cs:84
2023-03-07 07:47:39 +01:00
Steve Hawley d87d0cddef
[dotnet] Darwin p/invokes (#17698) 2023-03-06 10:25:41 -05:00
Rolf Bjarne Kvinge fb3df91407
[tests] Adjust EveryFrameworkSmokeTest to not run when every assembly is linked. (#17696)
It expects the executable to be linked will every system framework we've
bound, which doesn't happen when linker is enabled for all assemblies.
2023-03-06 13:38:07 +01:00
Rolf Bjarne Kvinge 3f742de4aa
[monotouch-test] Fix NWBrowserTest to not throw assertions on background threads. (#17697)
Exceptions on background threads will crash the process.
2023-03-06 12:48:39 +01:00
Rolf Bjarne Kvinge 8355cc0600
[tests] Don't use 'notdir' to compute the filename of a path. (#17682)
It doesn't work at all with paths with spaces. Instead call into the shell to
compute the filename.

Also fix a couple of other quoting issues.
2023-03-03 11:10:37 +01:00
Rolf Bjarne Kvinge d75b697ebc
[tests] Adjust UrlSessionTests to ignore more failure scenarios in CI. (#17649)
Should fix random test failures like this:

    MonoTouchFixtures.Foundation.UrlSessionTest
        [FAIL] CreateDataTaskAsync :   CreateDataTask a Exception
            Expected: null
            But was:  <Foundation.NSErrorException: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=57, NSUnderlyingError=0x6000011f4990 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x600003deaa80 [0x7ff865b1f1c0]>{length = 16, capacity = 16, bytes = 0x100201bb6007a9b70000000000000000}, _kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <5E766082-B379-491A-BCB0-EA1B36E54A8B>.<15>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDataTask <5E766082-B379-491A-BCB0-EA1B36E54A8B>.<15>"), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://www.microsoft.com/, NSErrorFailingURLKey=https://www.microsoft.com/, _kCFStreamErrorDomainKey=1}
                at MonoTouchFixtures.Foundation.UrlSessionTest+<>c__DisplayClass1_0.<CreateDataTaskAsync>b__0 () [0x00039] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/monotouch-test/Foundation/UrlSessionTest.cs:64 >
                at MonoTouchFixtures.Foundation.UrlSessionTest.CreateDataTaskAsync () [0x000b7] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/monotouch-test/Foundation/UrlSessionTest.cs:71
2023-03-02 10:38:41 +01:00
Rolf Bjarne Kvinge 8285c08c17
[registrar] Improve support for pointers to value types in exported signatures. (#17608)
This will be required when we make blocks use blittable callbacks, since we'll
have to use pointers in a few cases (because ref/out arguments aren't
blittable).
2023-02-28 11:48:27 +01:00
Steve Hawley aacedd12c7
[dotnet] Remove dead method, add some ignores (#17631)
Removed a flavor of `class_addMethod` that is unused.
Ignored a few cases that are going to be in .NET and/or may break AOT
optimizations

Now all iOS pivots pass, 17 macOS remain.
2023-02-27 17:56:06 -05:00
Steve Hawley 32961d97dd
[dotnet] UIMain changes (#17611)
handling of string array for args
2023-02-27 10:23:39 -05:00
Rolf Bjarne Kvinge aaa79e85ed
[tests] Improve diagnostic output in FSEventStreamTest. (#17614)
Ref: https://github.com/xamarin/maccore/issues/2630
2023-02-27 14:14:05 +01:00
Steve Hawley 1ca9a8fbdf
[dotnet] CGImageMetadata (#17530)
Fixed pinvoke used for CGIMetadata.EnumerateTags
2023-02-23 10:50:58 -05:00
Rolf Bjarne Kvinge c8ca8f401f
[monotouch-test] Fix AUParameterNodeTest to not crash the process in case of asserts on background threads. (#17593) 2023-02-23 14:34:50 +01:00
Rolf Bjarne Kvinge f8f5124a88
[generator] Fix fetching nullability for block properties by checking the property for nullability info. (#17594) 2023-02-23 14:34:20 +01:00
Rolf Bjarne Kvinge ad4af52393
[dotnet] Improve error message when someone tries to disable trimming by setting PublishTrimmed=false. (#17568)
Make it more actionable, by telling users what they can do instead.
2023-02-21 14:54:44 +01:00
Manuel de la Pena b462bfde99
[Generator] Move naming logic to its own class and add tests. (#17562)
Naming could be problematic when generating code, move the logic out of
the generator class to a helper class whose only job is to name classes
and keep track of names.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-02-17 15:33:53 -05:00
Manuel de la Pena 28db48f6ee
[Generator] Refactor method that was forgotten as an extension one. (#17550)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-02-16 08:48:09 -05:00
Manuel de la Pena c744a8bbc7
[Generator] Refactor AsyncMethodInfo, set nullability and add collection extensions. (#17538)
Several changes:

- Refactored AsyncMethodInfo and move the collection extensions out of
the Generator class.
- Added tests for the collection extension methods.
- Fix a mistake/bug in which Last was used instead of LastOrDefault
(funny comment was close to the right reason).

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-02-16 08:47:28 -05:00
Manuel de la Pena be1bee04b4
[Generator] Refactor more string extensions. (#17532)
Move all the string methods that can be an extension to a static class
(re-use the present one) and add tests.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
2023-02-16 08:45:43 -05:00
Manuel de la Pena b0683b90d5
[Generator] Move PlatformName maps out of the generator and add tests. (#17539)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-02-15 12:12:13 -05:00
Manuel de la Pena 498ced1811
[Generator] Remove method that is already present in the reflection API. (#17524)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-02-13 19:17:38 -05:00
dustin-wojciechowski 3eeb7691dc
Add ventura to mac tests configurations (#17349)
Added Ventura machines to macTestConfigurations within both the
build-ci-pipeline and the build-pr-pipelines.

---------

Co-authored-by: Alex Soto <alex@alexsoto.me>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2023-02-13 11:08:18 -05:00
Steve Hawley 309dbe3be0
[DotNet] CoreFoundation Pinvokes (#17505)
Updates the pinvokes in CoreFoundation to have blittable types.
I intentionally did *not* do `CFReadStream` and `CFWriteStream` as the
changes needed for those are may create a breaking API change, so those
should probably be their own PR for closer scrutiny.

Please look closely at CFProxySupport as that was the least
straightforward of the changes.
2023-02-10 19:06:29 -05:00
Rolf Bjarne Kvinge 8e4f22d20e
[msbuild] Add DT* entries to the Info.plist for all platforms. Fixes #13300. (#17499)
Modify the code to add Xcode (DT*) variables to the Info.plist:

* Do it for all platforms, not only mobile platforms. Apple uses these fields to
  determine if an app was built with a prerelease or old version of Xcode, and will
  reject any app submissions if this validation fails.

* Change the behavior to do not distinguish simulator builds, a bit of testing
  in Xcode shows that Xcode always adds these values to the Info.plist, even for
  simulator builds. This is probably something that changed in Xcode a *long* time
  ago, since this code is old (from the initial import of the build logic from MonoDevelop
  around 10 years ago).

* Also bump Xamarin.MacDev to get a related fix:

  New commits in xamarin/Xamarin.MacDev:

  * xamarin/Xamarin.MacDev@74c95ee [Xamarin.MacDev] Always fetch the DTSDKBuild variable.

  Diff: 14d53612d4..74c95ee1c3

Fixes https://github.com/xamarin/xamarin-macios/issues/13300.
2023-02-10 22:58:38 +01:00
Steve Hawley 1a9e9be626
[dotnet] address book pinvokes (#17419) 2023-02-08 12:02:06 -05:00
Rolf Bjarne Kvinge afb6505f8c
[tests] Bump Microsoft.NET.Test.Sdk version to latest stable. (#17462)
The older version of Microsoft.NET.Test.Sdk depends on an older version of
Newtonsoft.Json, which triggers automated security warnings.

Ref: https://devdiv.visualstudio.com/DevDiv/_componentGovernance/113130/alert/7090885?typeId=12169115
2023-02-07 14:52:45 +01:00
Rolf Bjarne Kvinge fd44670214
[ObjCRuntime] Make sure to call 'Release' in all code paths in Runtime.GetINativeObject<T> when owns=true. Fixes #12732. (#17118)
Fixes https://github.com/xamarin/xamarin-macios/issues/12732.
2023-02-07 07:22:35 +01:00
Rolf Bjarne Kvinge 13f51fb583
[tests] Add another failure scenario to random network test failures in CI. (#17439) 2023-02-07 07:22:09 +01:00
Rolf Bjarne Kvinge 367f0a5c13
[src] Fix a few inconsistencies in obsolete attributes. (#17447)
* Add obsolete attributes for all platforms.
* Make sure the same obsolete message is used on all platforms.
* Fix a few typos.

There are many more APIs to fix (as evidenced by the fact that this only
removes a few known failures), but this is how far I've gotten right now.
2023-02-06 08:49:00 +01:00
Haritha Mohan c814120173
[ImageCaptureCore] Add missing binding (#17424)
Deprecated "cameraDevice:didReceiveThumbnailForItem:" for macOS and
macCatalyst platforms and added updated binding for
"cameraDevice:didReceiveThumbnail:forItem:error:" method.

Refs:
[Deprecated
method](https://developer.apple.com/documentation/imagecapturecore/iccameradevicedelegate/1507941-cameradevice?changes=la_5&language=objc)
[Updated
method](https://developer.apple.com/documentation/imagecapturecore/iccameradevicedelegate/3142895-cameradevice?changes=la_5&language=objc)
2023-02-03 17:46:05 -08:00
Rolf Bjarne Kvinge 6d36bf1c1b
[cecil-tests] Add more availability attribute checks. (#17430)
Also fix a few issues:

* Fix an issue with replicating availability attributes with a third digit.

  The third version number is 'Build', not 'Revision' (which is fourth), so
  adjust our code accordingly.

  This fixes an issue where the copy of 'macos10.15.4' would become
  'macos10.15' and we'd lose the third number.

* Fix an issue when generating filter code. We were using the wrong type as
  the target (inlined) type, resulting in the wrong availability attributes
  getting created sometimes.
2023-02-03 16:44:01 +01:00
Andoni Morales Alastruey 97ab14801f
[dotnet] Add support for .so files (#16887)
Autotools-based project using libtool's -module flag generate plugins
with the .so extension that needs to be treated like DynamicLibraries in
terms of deployment location and relocation, except they are not linked
to the app.

This PR adds support for such .so files: they're treated as .dylib files, except
that they're not linked to the app.
2023-02-03 09:16:40 +01:00
Rolf Bjarne Kvinge 3e9e6a39db
[cecil-tests] Fix check for unsupported attribute on API that's present in an assembly. (#17423)
This also required fixing a few issues with the availability attributes.
2023-02-02 07:37:56 +01:00
Rolf Bjarne Kvinge 882db3657d
[tests] Remove workaround for issue #14802. (#17421)
Seems like this is fixed now.
2023-02-02 07:30:16 +01:00
Manuel de la Pena 0f39b2579f
[Tests] Fix some null warnings in the generator tests. (#17420)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-02-01 16:21:51 -05:00
Rolf Bjarne Kvinge 47a387f670
Add support for Visual Basic projects. (#17409)
* Add props and targets files for Visual Basic.
* Add templates for Visual Basic projects.
* Misc other related changes.

This contributes towards https://github.com/xamarin/xamarin-macios/issues/17321.
2023-02-01 21:20:14 +01:00
Rolf Bjarne Kvinge 33bd311736
[xtro] Add ImageCaptureCore to the frameworks we process. (#17417)
Since we already have some ImageCaptureCore bindings.
2023-02-01 21:13:08 +01:00
Manuel de la Pena f02135887b
[Generator] Refactor extension methods and fix bug. (#17406)
Moved the extension methods to their own file and enabled nullable.

Fixed the following underlying bug:

The extension method that creates a valid parameter named does not do
the right thing in the following cases:

1. When the starting illegal char is NOT a number. It will prepend @
fixing nothing. Example " OHOH" to "@ OHOH"
2. When the illegal chars is in the middle of the param name. Example
"OH OH" to "@OH OH"

I have fixed the method to return null in those ocassions (we will need
to enable nullability later in the generator, is too much for this PR).
Tests have been added to ensure we do not have such an issue again.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-01-31 16:05:25 -05:00
Steve Hawley 8266659ddb
[dotnet] audiotoolbox blittable pinvokes with delegates (#17388)
AudioToolbox changes to make the pinvokes blittable.
2023-01-31 10:29:19 -05:00
Rolf Bjarne Kvinge 1350683690
[src/generator] Stop implying Mac Catalyst availability attributes from the iOS attributes. (#17375)
Stop implying Mac Catalyst attributes from the iOS attributes, and instead
treat Mac Catalyst like all the other platforms (not implying anything from
any other platform).

This makes our attribute logic much easier to reason about and understand.

It also required adding numerous Mac Catalyst attributes that were previously
implied. This task was way too big to do manually, so I made some changes to
Chris' mellite tool, and managed to do it quite easily with Roslyn with the
changes in this branch: https://github.com/rolfbjarne/mellite/tree/explicit-maccatalyst-attributes
2023-01-31 14:51:53 +01:00
Rolf Bjarne Kvinge eb7914cfc2 [tests] Update the .NET template tests.
* Make these tests be able to build Visual Basic templates.
* Add the new Visual Basic templates.
2023-01-31 13:01:46 +01:00
Rolf Bjarne Kvinge 1130e1c472 [dotnet] Move templates around a bit to make room for more language-specific project templates. 2023-01-30 17:21:22 +01:00
Manuel de la Pena c201466d78
[Generator] Add support for nullability. Part 1. (#17384)
This is the first part of a 2 or more changes that will allow the APIs
to use ? as a way to mark a nullable field, parameter, property and
return method.

The way it works follows the documentation from the runtime that can be
found here:
https://github.com/dotnet/roslyn/blob/main/docs/features/nullable-metadata.md

The tldr; of the documentation is as follows:

1. If we are looking at a value type, the compiler converts int? into
Nullable<int>. This was already considered in the old code.
2. If we are inspecting a generic type we have to look for the
information in two different attributes added by the compiler: -
NullableAttribute: Each type reference in metadata may have an
associated NullableAttribute with a byte[] where each byte represents
nullability: 0 for oblivious, 1 for not annotated, and 2 for annotated.
- NullableContextAttribute is valid in metadata on type and method
declarations. The byte value represents the implicit NullableAttribute
value for type reference within that scope that do not have an explicit
NullableAttribute and would not otherwise be represented by an empty
byte[].

The API is very similar to that provided by dotnet6 but it allows us to
support classic. The move to the dotnet6 API should not be hard and
probably can be done by an IDE.

Once this API lands we will have to find the old usages of the check for
nullability and combine both. This new API should fix several issues we
have with nullability and nullability + generics.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-01-30 10:34:24 -05:00
Rolf Bjarne Kvinge 50c01fe10c
[generator] Fix an issue where we'd not copy attributes from inlined protocols. (#17381)
Protocols with one set of introduced attributes ([TV (12, 0)]) inlined in
types that were introduced in a different version ([TV (10, 0)]) would always
use the attributes from the type.

This is wrong if the protocol was introduced after the type, in which case we
should instead use the introduced attributes from the protocol.

Fix this by choosing the latest introduced attribute when we have multiple to
choose from.

This required passing a bit more information around so that we always know if
a member is being inlined in another type.

This PR will also print availability attributes on the protocol members themselves:

	[Protocol]
	interface IProtocol
	{
		[TV (12, 0)] // this was not printed before
		[Export ("someProperty")]
		string SomeProperty { get; set; }
	}

Also add and improve some tests.

Contributes towards https://github.com/xamarin/xamarin-macios/issues/14802.
2023-01-30 08:00:06 +01:00
dustin-wojciechowski 51bee958f0
Added GPSLatitudeRef and GPSLongitudeRef to CGImagePropertiesGPS. (#17166)
Fixes #17162

Added GPSLatitudeRef and GPSLongitudeRef to CGImagePropertiesGPS. 
Added new photo to all resources folders that has GPS data. 
Created new test that reads GPS information off a photo and verifies that it is correct.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2023-01-28 09:31:25 -08:00
Rolf Bjarne Kvinge 63abb2d419
[AVFoundation] Add a few missing APIs. Fixes #16954. (#17310)
Fixes https://github.com/xamarin/xamarin-macios/issues/16954.
2023-01-26 08:20:38 +01:00
Rolf Bjarne Kvinge 688fa45856
[tests] Improve the AttributeTest.FindSupportedOnElementsThatDoNotExistInThatAssembly cecil test. (#17367)
* Fix an issue where it would not compute the correct grouping key for each member,
  effectively grouping unrelated members together and coming up with weird and incorrect
  results.
* Make it match failures exactly, which makes it possible to detect (and report,
  which it now does) when a known failure is fixed.
* Ignore any hidden members (EditorBrowsableState.Never), because they're most
  likely mistakes.
* Ignore any members in AppKit and UIKit, because these namespaces have a lot of
  conflicting availability attributes. This is tracked in a separate bug (#17292).

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-01-25 20:55:28 +01:00
Rolf Bjarne Kvinge 98819287cc
[runtime/generator] Add support for BindAs with CMVideoDimensions. (#17308)
This is required for some new iOS 16 APIs.
2023-01-25 15:34:28 +01:00
Rolf Bjarne Kvinge a57695bcf5
[generator] Fix property accessor attributes when one accessor's iOS availability is different than the property itself. (#17298)
This PR handles two scenarios (fixed in separate commits):

Scenario 1:

* The property has different availability attributes than the containing type.
* The property's accessor(s) do not have availability attributes.

We'd generate the wrong availability attributes for the property accessors,
because we'd take the type's availability attributes and add them to the
accessors.

As for the fix: I can't really explain it. This code is rather impenetrable,
and the parameter names don't make much sense, but whatever I did seems to
work?

And it turns out this fix shows up in an existing test as well (the
generator's Bug35176 test), which I had to modify to remove the expectation of
(now redundant) availability attributes that we no longer produce.

Scenario 2:

* Type is available on iOS, tvOS.
* Property in the type is available on iOS (and not tvOS).
* Property accessor has explicit availability attributes for iOS.

Then the property accessor would get the availability attribute for tvOS from
the type, and not the (un)availability attribute from the property.

The fix is to make sure the parent context is the property (and not the type)
when processing availability attributes for the accessor.
2023-01-25 09:27:58 +01:00
Rolf Bjarne Kvinge 40b98b650d
[CoreAnimation] Add missing CAMetalLayer properties. Fixes #17340. (#17345)
Also make CAEdrMetadata available on iOS and add a missing CAEdrMetadata
property.

Fixes https://github.com/xamarin/xamarin-macios/issues/17340.
2023-01-25 08:57:46 +01:00
Rolf Bjarne Kvinge 86ee42a39d [tests] Bump the timeout to 10min for monotouch-test/xammac_tests on older macOS bots. (#17317)
I've started seeing more random network delays on these tests recently - which
the tests themselves handle, but the test run ends up taking much longer, and
we need to give the test run more time to finish.
2023-01-24 14:22:35 +01:00
dustin-wojciechowski 9c0bfd4e42 [src] Added manual binding to prevent issue of AVAudioPlayer FromData() and FromUrl() throwing exceptions. (#17073)
Provided manual binding of AVAudioPlayer::initWithContentsOfURL:error: and AVAudioPlayer::initWithData:error: to prevent an issue where AVAudioPlayer::FromData() and FromUrl() do not throw exceptions when returning null.

Fixes #16229

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-01-24 14:22:34 +01:00
Rolf Bjarne Kvinge 3cbd86aba2 [AVFoundation] Adjust availability attributes according to conditional compilation directives. (#17311)
According to the compilation compilation directives, these APIs are not
available on tvOS nor macOS, so update the availability attributes
accordingly.
2023-01-24 14:22:31 +01:00
Rolf Bjarne Kvinge 137c6a49f1
[tests] Add makefile to run the generator tests in .NET mode. (#17296) 2023-01-19 16:40:42 +01:00
Rolf Bjarne Kvinge 10accc2cd7
[dotnet/msbuild] Only compile entitlements once for universal builds. Fixes #15632. (#17096)
Fixes https://github.com/xamarin/xamarin-macios/issues/15632.
2023-01-19 16:01:34 +01:00
Rolf Bjarne Kvinge b1957c91ce
[generator] Fix an issue with regards to attributes from inlined protocols. Fixes #17268. (#17269)
In the following scenario:

* Type T is not available on a platform (say tvOS).
* Protocol P is available on said platform.
* A member M of P has its own availability attribute for said platform (for
  instance if P is available on tvOS 11.0, and the member is available on tvOS
  12.0).
* The protocol P is inlined into the type T.

We'd include the SupportedOSPlatform attribute from the inlined member on
generated code on other platforms (so the iOS assembly would say that the
inlined member M in T is available on tvOS).

Fixes https://github.com/xamarin/xamarin-macios/issues/17268.
2023-01-18 18:54:15 +01:00
Steve Hawley 74ceecaf3f
[dotnet] last of the strings in pinvokes are gone (#17205)
removed strings from pinvokes in ObjCRuntime
2023-01-18 10:25:52 -05:00
Rolf Bjarne Kvinge 49d13fc0ef
[AppKit] Bind an NSWindow(IntPtr) constructor in the API definition. (#17264)
This simplifies our manual bindings a little bit.
2023-01-18 07:13:58 +01:00
Rolf Bjarne Kvinge dc5d3b2a99
[tests] Hardcode the SupportedOSPlatformVersion for the .NET 6 tests. (#17248)
.NET 6 doesn't define the minimum supported OS version property, which means
we can't use the existing logic to automatically determine the min OS version
to use as the default SupportedOSPlatformVersion in the .NET 6, so hardcode
the value.
2023-01-17 17:09:47 +01:00
Rolf Bjarne Kvinge 6f4774be84
[generator] Don't generate accessors with No* availability attributes on them. (#17249)
Previously API definitions like this:

    string Property {
    	get;
    	[NoiOS]
    	set;
    }

would generate a setter for every platform, even iOS.

This is rather unexpected, so fix the generator to honor No* attributes on
property getters and setters.
2023-01-17 17:05:03 +01:00
Rolf Bjarne Kvinge 6a5176ad50
Bump to MSBuild.StructuredLogger v2.1.758. (#17229)
To get new log format:

> System.NotSupportedException : Unsupported log file format. Latest
supported version is 14, the log file has version 15.
2023-01-16 07:32:45 +01:00
Rolf Bjarne Kvinge 4453d773ce
[tests] Unify code related to how to load test assemblies. (#17111)
Unify a lot of code related to how to load test assemblies.

This resulted in adding a couple of test assemblies to monotouch-test when executed on macOS (this was a bug), and this also required adapting some of those tests to work correctly on macOS.
2023-01-13 22:20:47 +01:00
Rolf Bjarne Kvinge 480a6ed844
[src/runtime] Fix lookup of RID-specific satellite resources. Fixes #16847. (#17117)
If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add an assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes https://github.com/xamarin/xamarin-macios/issues/16847.
2023-01-13 21:58:34 +01:00
Rolf Bjarne Kvinge a02410530a
[tests] NWPathMonitors must be cancelled. (#17178)
Otherwise the process may crash later on:

    apitest.KernelNotificationTest

    =================================================================
    	Native Crash Reporting
    =================================================================
    Got a term while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries
    used by your application.
    =================================================================

    =================================================================
    	Native stacktrace:
    =================================================================
    	0x1050093d6 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : mono_dump_native_crash_info
    	0x104ffcf3e - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : mono_handle_native_crash
    	0x1050106c6 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : mono_crashing_signal_handler
    	0x7ff818795dfd - /usr/lib/system/libsystem_platform.dylib : _sigtramp
    	0x0 - Unknown
    	0x7ff81c88c9f8 - /usr/lib/libnetwork.dylib : nw_path_shared_necp_fd
    	0x7ff81c99e796 - /usr/lib/libnetwork.dylib : -[NWConcrete_nw_path_evaluator dealloc]
    	0x7ff81c9bb93e - /usr/lib/libnetwork.dylib : __nw_dictionary_dispose_block_invoke
    	0x7ff8184bc5a3 - /usr/lib/system/libxpc.dylib : _xpc_dictionary_apply_apply
    	0x7ff8184b97e9 - /usr/lib/system/libxpc.dylib : _xpc_dictionary_apply_node_f
    	0x7ff8184bc4cd - /usr/lib/system/libxpc.dylib : xpc_dictionary_apply
    	0x7ff81c98c7eb - /usr/lib/libnetwork.dylib : -[OS_nw_dictionary dealloc]
    	0x7ff81cfa5ab5 - /usr/lib/libnetwork.dylib : nw_path_release_globals
    	0x7ff81c9edba6 - /usr/lib/libnetwork.dylib : nw_settings_child_has_forked
    	0x7ff818783103 - /usr/lib/system/libsystem_pthread.dylib : _pthread_atfork_child_handlers
    	0x7ff81867482d - /usr/lib/system/libsystem_c.dylib : fork
    	0x1051b37a3 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : process_create
    	0x1051b224a - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal
    	0x1050e4111 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal_raw
    	0x10d4f2437 - Unknown
    	0x10d4f1e4b - Unknown
    	0x10d4f188b - Unknown
    	0x10d4f17b3 - Unknown
    	0x10d4f1363 - Unknown
    	0x10d4f11bb - Unknown
    	0x10d4efc53 - Unknown
    	0x10d4ee121 - Unknown
    	0x105013d23 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : mono_jit_runtime_invoke
    	0x1051483f8 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : mono_runtime_invoke_checked
    	0x1051510cf - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : mono_runtime_try_invoke_array
    	0x1050d7127 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : ves_icall_InternalInvoke
    	0x1050e9b57 - /Users/rolf/work/maccore/msbuild/xamarin-macios/tests/xammac_tests/bin/x86/Debug/xammac_tests.app/Contents/MacOS/xammac_tests : ves_icall_InternalInvoke_raw

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-01-12 14:30:23 +01:00
Rolf Bjarne Kvinge 4ce35769cf
[xtro] Improve assembly resolution to not load incorrect assemblies. (#17177)
Add support to xtro-sharpie for where to look for referenced assemblies, and
adjust assembly resolution to only look in those directories.

This makes sure xtro-sharpie loads the expected references, and fixes a
problem where the (broken) assembly resolution wouldn't find a .NET assembly
because it doesn't exist in legacy Xamarin (where it would look by default).

Fixes this problem that showed up in a different PR (due to new .NET API
referencing the System.Runtime.Loader assembly, which doesn't exist in legacy
Xamarin):

    mono64 --debug bin/Debug/xtro-sharpie.exe --output-directory api-annotations-dotnet appletvos16.1-arm64.pch ../../_build/Microsoft.tvOS.Runtime.tvos-arm64/runtimes/tvos-arm64/lib/net7.0/Microsoft.tvOS.dll
    Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Runtime.Loader, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
      at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x000ff] in C:\src\cecil\Mono.Cecil\BaseAssemblyResolver.cs:172
      at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in C:\src\cecil\Mono.Cecil\BaseAssemblyResolver.cs:117
      at Mono.Cecil.DefaultAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x0001d] in C:\src\cecil\Mono.Cecil\DefaultAssemblyResolver.cs:33
      at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x0003a] in C:\src\cecil\Mono.Cecil\MetadataResolver.cs:110
      at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00000] in C:\src\cecil\Mono.Cecil\ModuleDefinition.cs:748
      at Mono.Cecil.TypeReference.Resolve () [0x0000f] in C:\src\cecil\Mono.Cecil\TypeReference.cs:280
      at Extrospection.Helpers.GetName (Mono.Cecil.MethodDefinition self) [0x00051] in /Users/rolf/work/maccore/whatever/xamarin-macios/tests/xtro-sharpie/Helpers.cs:332
      at Extrospection.DesignatedInitializerCheck.VisitManagedMethod (Mono.Cecil.MethodDefinition method) [0x00001] in /Users/rolf/work/maccore/whatever/xamarin-macios/tests/xtro-sharpie/DesignatedInitializerCheck.cs:43
      at Extrospection.AssemblyReader.ProcessType (Extrospection.BaseVisitor v, Mono.Cecil.TypeDefinition type) [0x0002b] in /Users/rolf/work/maccore/whatever/xamarin-macios/tests/xtro-sharpie/Runner.cs:104
      at Extrospection.AssemblyReader.Process () [0x0008e] in /Users/rolf/work/maccore/whatever/xamarin-macios/tests/xtro-sharpie/Runner.cs:93
      at Extrospection.Runner.Execute (System.String pchFile, System.Collections.Generic.IEnumerable`1[T] assemblyNames, System.String outputDirectory) [0x001af] in /Users/rolf/work/maccore/whatever/xamarin-macios/tests/xtro-sharpie/Runner.cs:52
      at Extrospection.MainClass.Main (System.String[] arguments) [0x0008f] in /Users/rolf/work/maccore/whatever/xamarin-macios/tests/xtro-sharpie/Program.cs:28
    make: *** [.stamp-dotnet-classify-tvOS] Error 1

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2023-01-11 17:59:47 +01:00
Rolf Bjarne Kvinge 74d7337dcc
[dotnet] Create an MSBuild property for the current min OS version. (#17034)
Create an MSBuild property for the minimum OS version
(`SupportedOSPlatformVersion`) we support for a given platform (named
`[platform]MinSupportedOSPlatformVersion`), and use it in most tests instead
of hardcoding the min OS version (which would otherwise have to be updated
every time we bump the min OS version).
2023-01-10 21:18:39 +01:00
Rolf Bjarne Kvinge 8e98350e0a
[XKit] Fix creating NSTextLists with custom formats in .NET. Fixes #15766. (#17123)
In .NET, we changed the API for creating a NSTextList with a specified
NSTextListMarkerFormats, making NSTextListMarkerFormats a strongly typed enum,
and not allowing any other value except those in NSTextListMarkerFormats.

This was a mistake, because NSTextList can be created with other format values
than those available in NSTextListMarkerFormats.

So fix this by:

* Adding another NSTextListMarkerFormats enum value that specifies that the
  actual format is a custom one (NSTextListMarkerFormats.CustomString).
* Resurface an 'NSTextListMarkerFormats(string)' constructor that can be used
  to create an NSTextListMarkerFormats with a custom string.
* Add a NSTextListMarkerFormats.CustomMarkerFormat property that always
  retrieves the underlying string value for the format.
* Add a NSTextListOptions.None enum value, which means no options (since
  NSTextListOptions is a set of flags, it should be possible to specify no
  flags).
* Add two convenience constructors that don't take a NSTextListOptions value,
  defaulting to NSTextListOptions.None.
* Add tests!

Fixes https://github.com/xamarin/xamarin-macios/issues/15766.
2023-01-10 08:28:47 +01:00
Rolf Bjarne Kvinge 5e72799e28
[Foundation] Add missing fields in NSAttributedStringDocumentReadingOptionKey. (#17112) 2023-01-09 11:38:19 +01:00
Rolf Bjarne Kvinge d1aaf8e1c0
[tests] Make the helper makefiles for .NET tests more helpful. (#17122)
Make the helper makefiles for .NET tests more helpful by adding support for
universal apps, and also document the most relevant targets.
2023-01-09 10:43:45 +01:00
Rolf Bjarne Kvinge ab0294169f
[xharness] Bump the timeout for the .NET tests. (#17110)
We keep adding more and more tests...
2023-01-09 10:42:09 +01:00
Rolf Bjarne Kvinge a26e3c57f4
[tests] Enable some of the asserts in the Cecil.Tests.ApiAvailabilityTest.AttributeConsistency test. (#17113)
They're passing now.
2023-01-09 10:40:57 +01:00
Rolf Bjarne Kvinge 491c5c979c
[src/tests] Fix consistency between ObsoletedOSPlatform and UnsupportedOSPlatform attributes. (#17104)
* If there's both an UnsupportedOSPlatform and ObsoletedOSPlatform attribute with
  the same version, then remove the UnsupportedOSPlatform attribute. This is because
  in the past we used [UnsupportedOSPlatform] + [Obsolete] to indicate that an API
  is obsolete, but then the [ObsoletedOSPlatform] attribute was added, and we replaced
  the [Obsolete] attributes with [ObsoletedOSPlatform] attributes, which makes the
  [UnsupportedOSPlatform] attributes redundant/incorrect.
* If there's [UnsupportedOSPlatform] with a version or [ObsoletedOSPlatform] with
  a version, then also add [SupportedOSPlatform] in a few cases.
* If there's an [UnsupportedOSPlatform] with a version for API that's obsolete/non-working,
  then remove the version.
2022-12-22 12:40:04 +01:00
Timothé Larivière 3b73bb658b
Add an additional F# template for Microsoft.iOS.iOSApp (#16823)
Closes #16822 

This PR adds an F# template to the basic Microsoft.iOS.iOSApp template.
This should allow being able to do either:

```
dotnet new ios -lang C# -n MyApp
dotnet new ios -lang F# -n MyApp
```

I had to move the C# template into a `csharp` folder.
Also added the `groupIdentity` `Microsoft.iOS.iOSApp` and set the identity for both C# and F# respectively to `Microsoft.iOS.iOSApp.CSharp` and `Microsoft.iOS.iOSApp.FSharp`

Co-authored-by: Timothé LARIVIERE <timothe.lariviere@fundourselves.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-12-22 12:04:36 +01:00
Andoni Morales Alastruey efad190de9
[msbuild] Validate OutputType property (#16871)
Fixes #16865

```
➜  test dotnet build  -bl:msbuild.binlog
MSBuild version 17.3.2+561848881 for .NET
/usr/local/share/dotnet/sdk/6.0.403/MSBuild.dll -bl:msbuild.binlog -consoleloggerparameters:Summary -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/local/share/dotnet/sdk/6.0.403/dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,/usr/local/share/dotnet/sdk/6.0.403/dotnet.dll -maxcpucount -restore -verbosity:m ./test.csproj
  Determining projects to restore...
  All projects are up-to-date for restore.
/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/12.3.471/targets/Xamarin.Shared.Sdk.targets(284,3): error : WinExe is not a valid output type for macOS [/Users/andoni/Downloads/test/test.csproj]

Build FAILED.

/usr/local/share/dotnet/packs/Microsoft.macOS.Sdk/12.3.471/targets/Xamarin.Shared.Sdk.targets(284,3): error : WinExe is not a valid output type for macOS [/Users/andoni/Downloads/test/test.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.14
```

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-12-22 07:36:04 +01:00
dustin-wojciechowski b94f1c3de5
[tests] Created Test to find Getters that throw Exceptions directly. (#16923)
Added GetterExceptionTest, which examines IL of Property Getters for exceptions.

Fixes #16669

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-12-21 09:34:13 -08:00
Rolf Bjarne Kvinge 67607853aa
[src/tests] Improve the cecil test checking for obsolete API. (#17091)
* Hide all obsolete API using the EditorBrowsable atribute.
* Iterate over everything with availability attributes in the test.
2022-12-21 18:15:43 +01:00
Rolf Bjarne Kvinge 834bb92cb0
[tests] Update .NET tests to cope with updated min OS version and no more 32-bit iOS support. (#17088) 2022-12-21 18:15:28 +01:00
Rolf Bjarne Kvinge 37594bd8b9
[tests] Remove duplicated Import to fix build warning. (#17100)
Fixes:

    xamarin-macios/tests/framework-test/dotnet/shared.csproj(43,3): warning MSB4011: "xamarin-macios/tests/nunit.framework.targets" cannot be imported again. It was already imported at "xamarin-macios/tests/common/shared-dotnet.csproj (69,2)". This is most likely a build authoring error. This subsequent import will be ignored.
2022-12-21 18:15:02 +01:00
Rolf Bjarne Kvinge b765cf90a3
[tests] Update MTouch tests to cope with potentially higher min OS version and no 32-bit iOS support. (#17087) 2022-12-21 18:14:46 +01:00
Rolf Bjarne Kvinge 6c04f7621a
[tools] Update SdkVersions.cs after the latest Xcode 14.2 bump. (#17101)
* Update `SdkVersions.cs` after the latest Xcode 14.2 bump.
* Rename `[SdkVersions|ProductConstants].cs.in` to `[SdkVersions|ProductConstants].in.cs`.
  This way the autoformatter makes sure it's formatted correctly.
2022-12-21 17:44:27 +01:00
Rolf Bjarne Kvinge e99c71ad36
[tests] Fix a few nullability issues in cecil-tests and the .NET tests. (#17095)
Also make any nullability warnings show up as errors.
2022-12-21 10:19:13 +01:00
Alex Soto a7502b2b8d
[main] Bump bindings to Xcode 14.2 (#17037) 2022-12-21 08:39:03 +01:00
Rolf Bjarne Kvinge 43170cb37e
[tests] Add cecil-test to verify that the obsolete messages are identical between platforms for a given API. (#17089) 2022-12-21 07:44:15 +01:00
Rolf Bjarne Kvinge d9bae59f69
[src/generator/tests] Verify that availability attributes don't include useless version information. Fixes #11029. (#17090)
* Change the generator to not write the version in SupportedOSPlatform
  attributes unless it's greater than min OS version.
* Fix a few redundant Mac Catalyst availability versions.
* Uncomment the test to verify that availability attributes don't include
  useless version information.

Fixes https://github.com/xamarin/xamarin-macios/issues/11029.
2022-12-21 07:44:02 +01:00
Rolf Bjarne Kvinge 83b0727967
[tests] Port and improve the availability attribute test from introspection. (#17083)
Port the availability attribute test from introspection to cecil-tests. It's much
easier and faster to test attributes using Cecil using a desktop executable than
having to execute a test app on each target platform.

This also means that we can make the ApiAvailabilityTest in introspection
legacy-only.

Ref: https://github.com/xamarin/xamarin-macios/issues/10834
2022-12-20 12:46:06 +01:00
Rolf Bjarne Kvinge a227b77402
[generator] tvOS attributes aren't implied from iOS attributes. (#17057)
This hasn't been a problem until now because we've always had tvOS attributes on
most API, but when bumping min OS versions for .NET 8, we'll also remove a lot of
redundant availability attributes. This would break a case where a type is unavailable
on all platforms except tvOS (but without any tvOS availability attribute), and then
we'd get the (implied) iOS (un)availability attribute.
2022-12-20 07:29:19 +01:00
Rolf Bjarne Kvinge 01123bfb0e
[tests] Fix the AppWithNativeDynamicLibrariesInPackageReference to work when not all platforms are enabled. (#17081) 2022-12-19 18:37:10 +01:00
Rolf Bjarne Kvinge d6cb31402f
[tools] Split tools/common/SdkVersions.cs in two files. (#17067)
We need parts of tools/common/SdkVersions.cs when building tests on Windows.
In order to simplify our Windows-life, we're going to check in the generated
SdkVersions.cs file, that way it won't have to be re-generated on Windows (the
logic is very make-based, and not easily executed on Windows).

However, parts of SdkVersions.cs would change every commit, which would make
the above solution rather annoying. So split out those parts into a new file
(ProductConstants.cs), which is still generated during the build (and not
checked in).
2022-12-16 15:25:53 +01:00
Rolf Bjarne Kvinge e69d361c11
[Foundation] Unify the source code for NSAttributedStringDocumentAttributes. (#17069)
Unify the source code for NSAttributedStringDocumentAttributes between
iOS and maOS.

As a result, we're now exposing a few APIs on macOS that were previously
only exposed on iOS.

This PR might be easier to review commit-by-commit.
2022-12-16 15:23:24 +01:00
Rolf Bjarne Kvinge 574031059d
[tests] Improve the Bug35176 generator test. (#17070)
Make it assert on the exact list of attributes we're expecting. This makes it
much easier to see what changed.
2022-12-16 15:20:06 +01:00
Andoni Morales Alastruey 4cfccff38e
Fix libs reidentification deployed in a subdirectory (#16706)
Dynamic libraries might be deployed in subdirectories such as libclrjit.dylib from the nuget package cefglue.common:
Contents/MonoBundle/CefGlueBrowserProcess/libclrjit.dylib

The library ID for that library should be: @executable_path/../MonoBundle/CefGlueBrowserProcess/libclrjit.dylib

Instead of: @executable_path/../MonoBundle/libclrjit.dylib

Beside the library ID being wrong, when it's combined with the nuget package microsoft.netcore.app.runtime.osx-x64 providing a library with the same name, both uses the same `ReidentifiedPath`, which can cause a failure in the InstallNameTool tasks that are run in parallel operating on the same temporary file.

The following patch uses the `RelativePath` for the tempory file used by `InstallNameTool` so that there are no clashes with other files with the same name deployed in other directories. It also uses the `RelativePath` to create the correct library id: @executable_path/../../Contents/MonoBundle/CefGlueBrowserProcess/libclrjit.dylib

Partially fixes https://github.com/xamarin/xamarin-macios/issues/15173 for this scenario
2022-12-16 09:17:01 +01:00
Rolf Bjarne Kvinge 41a4abe54b [xtro] Update. 2022-12-15 16:35:40 +01:00
Rolf Bjarne Kvinge f06c4f2df1
[tests] Remove ignore due to custom code that's been gone for almost two years. (#17027)
We had custom code with Console.WriteLine for macOS 10.12 for a while, but that was removed here:

a93bcdec34

So there's no need to skip the test that verifies we don't call Console.WriteLine anymore.
2022-12-15 14:28:51 +01:00
Rolf Bjarne Kvinge d52fd8ddc8
[tests] Assert that we don't have any private IntPtr constructors in cecil-tests. (#17055) 2022-12-15 13:13:21 +01:00
Rolf Bjarne Kvinge 1c0f4e9c3c
[Network] Fix constructors in NWPathMonitor. (#16977)
* Call _SetUpdatedSnapshotHandler from the (NativeHandle, bool) constructor,
  this way it's called from all constructors.
* Call the (NativeHandle, bool) constructor from all other constructors to
  ensure a consistent instance.
* Remove the internal (IntPtr) constructor, it's no longer used. This also
  fixes a memory leak, because the (IntPtr) constructor would just create a
  new nw_path_monitor instance instead of using the passed-in handle
  (effectively forgetting about it and leaking it).
2022-12-15 08:03:20 +01:00
Rolf Bjarne Kvinge ffad05b9a3
[tests] Use .NET to build cecil-tests. (#17028)
Use .NET to build cecil-tests, using the appropriate verbosity, and creating a
binlog as well.
2022-12-14 22:35:50 +01:00
Rolf Bjarne Kvinge 4a819741f6
[tests] Parameterize the min OS version in a few mtouch tests. (#17035) 2022-12-14 21:44:36 +01:00
Rolf Bjarne Kvinge e3f549fc7e
[tests] Improve cecil-tests's member filtering API. (#17001)
* Improve these methods to find members inside nested types as well.
* Simplify their implementation somewhat.
* Make the filter method optional to allow enumerating everything.
* Rename these methods to Enumerate* to better express what they do.
* Make them extension methods on AssemblyDefinition to make them more
  discoverable and easier to use.
2022-12-13 17:09:45 +01:00
Rolf Bjarne Kvinge 081505b173
[tests] Improve perf in cecil-tests by only loading assemblies once. (#16997)
Improve perf in cecil-tests by caching loaded assemblies, and thus only
loading them once. The gain isn't all that much - it saves about 3s of ~2m on
my machine, so ~1.5% faster - but it'll be more and more important as we write
more tests. Also the code becomes slightly simpler too.
2022-12-13 09:23:25 +01:00
Rolf Bjarne Kvinge 0ba8d7e0e2
[tests] Fix potential NullReferenceException in cecil-tests. (#16998)
Fixes this compiler warning:

    tests/cecil-tests/MarshalAsTest.cs(91,8): warning CS8602: Dereference of a possibly null reference.
2022-12-12 17:14:29 +01:00
Rolf Bjarne Kvinge 3ff320805b
[tests] Enable nullability for numerous files in the .NET tests. (#16976) 2022-12-12 17:13:02 +01:00
Rolf Bjarne Kvinge 660ff60ad5
[tests] Improve performance a bit in Cecil.Tests.GenericPInvokesTest. (#16999)
Improve performance in Cecil.Tests.GenericPInvokesTest by creating fewer
strings.

This saves about 1m07s seconds on my machine, from 2m10s to 1m03s, so ~52%
faster.
2022-12-12 15:29:47 +01:00
Rolf Bjarne Kvinge dc37be300e
Remove bitcode-related code, since bitcode is dead. (#16986) 2022-12-12 15:25:37 +01:00
Rolf Bjarne Kvinge cc5c1bb4bf
[tests] Adjust cecil-tests to not test 32-bit iOS assemblies unless 32-bit iOS architectures are enabled. (#16989) 2022-12-07 18:24:14 +01:00
Rolf Bjarne Kvinge d17191f9c3
[xharness] Parameterize the min OS version for generated projects. (#16985) 2022-12-07 17:43:52 +01:00
Rolf Bjarne Kvinge cb28b21189
[tools/src] Enable nullability in a few error-related source files. (#16987) 2022-12-07 17:43:05 +01:00
Rolf Bjarne Kvinge 78813cb591
[tests] Remove some dead code. (#16988) 2022-12-07 17:42:36 +01:00
Rolf Bjarne Kvinge 7f2d7dcce5
[tests] We don't want exceptions to the obsolete test to apply anymore in XAMCORE_5_0 in cecil-tests. (#16991)
That's the time to fix those exceptions.
2022-12-07 17:42:11 +01:00
Rolf Bjarne Kvinge 25fc6c84d1
[dotnet-linker] Handle null fields in BackingFieldDelayHandler as unmarked fields. Fixes #16957. (#16970)
The BackingFieldDelayHandler will temporarily remove the body of Dispose
methods, and then for every field accessed in the Dispose method that was
preserved by the linker, we'll keep the corresponding code in the Dispose
method (otherwise we'd remove the code).

This is a way to remove fields that are _only_ accessed (and nulled out) in
the Dispose method.

However, we were running into a problem with determining if a field was marked
by the linker: if the field is in a generic type, and that field was not
marked by the linker, the linker might have actually removed the field from
the containing type before we're processing the Dispose methods, and we'd find
a null field definition where no null field definition was expected
(eventually resulting in an ArgumentNullException).

Fix this by treating a null field definition as an unmarked field.

Also add a test.

Fixes https://github.com/xamarin/xamarin-macios/issues/16957.
2022-12-07 15:53:15 +01:00
Rolf Bjarne Kvinge 6581fcb5fb
[Foundation] Create a new NSAttributedStringDocumentAttributeKey enum to match Apple's headers. (#16969)
This allows us to unify the code between all platforms.

Also add all the NSAttributedStringDocumentAttributeKey values we haven't bound yet.

There are no changes in the public API, because I'm only changing internal types.

Ref: #14489.
2022-12-07 15:52:20 +01:00
Steve Hawley 3c512a8331
[net8.0] added a test for blittability of pinvokes, partial #15684 (#16525)
This adds a unit test to check for blittability of arguments to
pinvokes.
2022-12-06 14:35:16 -05:00
Rolf Bjarne Kvinge 407b4c4ac6
[tests] Add logic to detect when macOS and Mac Catalyst test apps don't launch properly. Fixes #xamarin/maccore@2414. (#16946)
Implement a launch timeout for macOS and Mac Catalyst apps where if a certain
environment variable (LAUNCH_SENTINEL_FILE) is set, the app will create that
file at launch. The code launching the test app will wait 10 seconds and check
if the file is there: if it's not, something went wrong, in which case the app
should be terminated and launched again.

This necessitated re-implementing the launch script in C#, since it got quite
complicated to implement in bash.

This fixes an issue with Mac Catalyst apps where something would go wrong
during the app launch and nothing would happen (but the app wouldn't be
deadlocked, it would just sit there, doing nothing).

The TestRuntime.cs and ApplePlatform.cs had to be added to a few test projects
to make this compile, which required a few fixes in these files for building
with legacy Xamarin.Mac.

Fixes https://github.com/xamarin/maccore/issues/2414.
2022-12-06 13:11:36 +01:00
Rolf Bjarne Kvinge 94bdee0d7c
[autoformat] Update some new code. (#16967)
This is code from PRs that were started before we started autoformatting
the files in question, and then merged afterwards.
2022-12-06 07:49:52 +01:00
Rolf Bjarne Kvinge 36125e3b3f
[tests] Ignore the MonoTests.System.TimeZoneInfoTest+IsDaylightSavingTimeTests.Bug_16395 test. Fixes #xamarin/maccore@2629. (#16956)
It looks like some timezone data has changed, so this test is now failing.
Mono will probably not be updated, so just ignore the test.

Fixes https://github.com/xamarin/maccore/issues/2629.
2022-12-05 22:31:16 +01:00
Rolf Bjarne Kvinge b3cb85c0ad
[tests] Allow for timeouts in CI in a few tests. (#16945)
Also add some exception handling.

Hopefully fixes more issues with broken network in CI.
2022-12-05 08:53:33 +01:00
Rolf Bjarne Kvinge f7533f5ab9
Bump xharness. (#16947) 2022-12-05 08:53:05 +01:00
Rolf Bjarne Kvinge 1c80823582
[autoformat] Add all of tests/. (#16857) 2022-12-05 08:23:34 +01:00
Rolf Bjarne Kvinge 084f056855
[tests] Enable nullability in tests/common/DotNet.cs. (#16927) 2022-12-01 21:57:36 +01:00
Haritha Mohan 1dc6cacafb
[UIKit] Add GetWeight method for UIFontWeight (#16922)
Made UIFontWeightConstants visible and added an extensions method to
access font weights easily.
Also added test to ensure GetWeight works as expected. 
Fixes #10753

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-12-01 11:02:24 -08:00
Rolf Bjarne Kvinge 786346cf0c
[autoformat] Update some new code. (#16921)
This is code from PRs that were started before we started autoformatting the
files in question, and then merged afterwards.
2022-12-01 08:31:34 +01:00
Rolf Bjarne Kvinge 7b2b1c746c
[xharness] Packaged macOS tests are a thing now. (#16905)
While this value isn't used directly in xharness, we can add a
'skip-packaged-macos-tests' label for a PR, which xharness will try to match
with a test label, so the test label must exist, otherwise all tests will
fail.
2022-11-29 21:47:30 +01:00
Haritha Mohan 64bb06c71d
[src] use HashCode.Combine to generate hashcodes (#16841)
Fixes #16677

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
Co-authored-by: TJ Lambert <tjlambert@microsoft.com>
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: GitHub Actions <github-actions@xamarin.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Co-authored-by: VS MobileTools Engineering Service 2 <vsmobiletoolsengsvc2@microsoft.com>
2022-11-29 10:43:46 -08:00
Haritha Mohan 5a0366a9fa
[Foundation] Add missing bindings in NSTask (#16856)
Added new bindings for deprecated methods/properties: 

Launch -> LaunchAndReturnError
LaunchFromPath -> LaunchFromUrl
LaunchPath -> ExecutableUrl
CurrentDirectoryPath -> CurrentDirectoryUrl

Fixes #14659
2022-11-29 08:32:36 -08:00
Rolf Bjarne Kvinge eed66a2e21
[tests] Use CFString.FromHandle instead of NSString.FromHandle. (#16874)
Fixes this warning:

> warning CS0618: 'NSString.FromHandle(NativeHandle)' is obsolete: 'Use of 'CFString.FromHandle' offers better performance.'
2022-11-29 09:30:17 +01:00
Rolf Bjarne Kvinge 053078c167
[tests] Ignore CA1422 for some code. (#16875)
Fixes these warnings:

    xamarin-macios/tests/common/TestRuntime.cs(1228,8): warning CA1422: This call site is reachable on: 'MacCatalyst' 13.3 and later. 'ABAuthorizationStatus.Denied' is obsoleted on: 'maccatalyst' 9.0 and later (Use the 'Contacts' API instead.).
    xamarin-macios/tests/common/TestRuntime.cs(1227,8): warning CA1422: This call site is reachable on: 'MacCatalyst' 13.3 and later. 'ABAuthorizationStatus.Restricted' is obsoleted on: 'maccatalyst' 9.0 and later (Use the 'Contacts' API instead.).
    xamarin-macios/tests/common/TestRuntime.cs(1221,8): warning CA1422: This call site is reachable on: 'MacCatalyst' 13.3 and later. 'ABAuthorizationStatus.NotDetermined' is obsoleted on: 'maccatalyst' 9.0 and later (Use the 'Contacts' API instead.).
2022-11-29 09:29:59 +01:00
Rolf Bjarne Kvinge cbfcabacf6
[msbuild] Fix parsing -gcc_flags when the value is the next argument. Fixes #16861. (#16862)
The -gcc_flags in the extra mtouch/mmp arguments can either be of the format
'-gcc_flags=<value>' or '-gcc_flags <value>'. Previously we only parsed the
former correctly, and now fix the parsing logic to handle the latter version
correctly as well.

Fixes https://github.com/xamarin/xamarin-macios/issues/16861.
2022-11-29 09:29:27 +01:00
Haritha Mohan 51afd316cc
[tests] Ensure proper capitalization in API (#16840)
Use reflection to detect incorrectly capitalized public methods, fields,
properties, and events.
Fixes #15733

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2022-11-28 12:11:27 -08:00
Rolf Bjarne Kvinge ff585dca2d
[tests] Move code to avoid unreachable code warning. (#16876)
Fixes this warning:

> xamarin-macios/tests/common/TestRuntime.cs(1321,4): warning CS0162: Unreachable code detected
2022-11-28 18:18:11 +01:00
Rolf Bjarne Kvinge d627b203eb
[tests] Create a shared AppDelegate class and use it everywhere. (#16877)
Create a shared AppDelegate class, which contains all the identical
AppDelegate code for all test projects. This reduces a lot of code duplication.
2022-11-28 18:17:49 +01:00
Rolf Bjarne Kvinge 712d84c18b
[xharness] Use a different identifier than '%...%' for replacement text. (#16878)
When the autoformatter runs into the '%...%' pattern in *.cs files, it
will re-format the text (to '% ... %'), but that breaks our text replacement
logic. So instead use a valid C# identifier as a replacement token, in which
case the autoformatter won't confuse our replacement logic.
2022-11-28 18:17:23 +01:00
Rolf Bjarne Kvinge e7653c5cde
[tests] Adjust the NoAvailabilityOnError cecil test to look in and work with .NET assemblies as well. (#16891)
Also remove some unnecessary null-checking code.
2022-11-28 18:03:47 +01:00
Rolf Bjarne Kvinge e4c940cdb8
[Foundation] Fix NSDate's explicit conversion operators with DateTime. (#16872)
We recently tried to fix NSDate's conversion operators with DateTime
(3c65ab1756), but unfortunately a corner case
was missed.

The new approach in the above-mentioned commit would get the individual
date/time components for a given date and use the appropriate constructor for
the other type to re-construct the date/time in question.

However, one case was missed: when converting from NSDate to DateTime, we'd
get a fractional number of milliseconds. This fractional number could be
something like 999.99 milliseconds, and when converting that to the int the
DateTime constructor expected for the number of milliseconds, then DateTime
would throw an exception, because the number of milliseconds could only be
between 0 and 999.

I've solved this by not using floating-point math in the computations. We're
now getting the number of nanoseconds from the NSDate (which is a natural
number, and represents the total number of nanoseconds less than a whole
second), and then converting that to the number of milliseconds, microseconds
and ticks that can be used with DateTime using integral math. Unfortunately
DateTime doesn't have a constructor that takes the remaining number of ticks
after all the other fields have been provided, but that can be added
afterwards.

I've also made a few other improvements:

* Improve the validation for the NSDate -> DateTime conversion to detect BC
  dates by using the NSDate's Era component (to throw because DateTime only
  supports AC dates). Also don't allow a tick later than year 10.000 (DateTime
  only supports up to a tick before year 10.000) - but explicitly support
  exactly year 10.000, and convert it to DateTime.MaxValue (this is because
  due to precision errors NSDate can't actually express 'a tick before year
  10.000', it ends up being rounded up to year 10.000 exactly). This means
  there are no more magical values in the range validation checks.
* Increase precision in the DateTime -> NSDate conversion by starting with the
  sub-second amount of ticks from the DateTime instance (instead of the number
  of milliseconds). This allows us to compute the nanoseconds NSDate expects
  with much higher precision.
* More tests!

Fixes this test:

    MonoTouchFixtures.Foundation.DateTest.DateTimeToNSDate : 2 ms
        [FAIL] Precision32022 : System.ArgumentOutOfRangeException : Valid values are between 0 and 999, inclusive.
            Parameter name: millisecond
            at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day, System.Int32 hour, System.Int32 minute, System.Int32 second, System.Int32 millisecond, System.DateTimeKind kind) [0x0002d] in <4d40c65adfc14d7fb19bad9310f3eb2a>:0
            at Foundation.NSDate.op_Explicit (Foundation.NSDate d) [0x000b8] in <9cb1e1018c034b75ba5f4ed7b83ba2f2>:0
            at MonoTouchFixtures.Foundation.DateTest.Precision32022 () [0x0000c] in <c44b5df5f7b84b69b737e9fd61bddaed>:0
            at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
            at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <4d40c65adfc14d7fb19bad9310f3eb2a>:0

Fixes https://github.com/xamarin/maccore/issues/2632.

Date and time is difficult.

Ref: https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca
Ref: the rest of internet...
2022-11-23 07:55:22 +01:00
Rolf Bjarne Kvinge 0e778737c7
[tests] Adjust TestNSurlSessionHandlerCookieContainer* tests to not fail in CI in case of network problems. Fixes #2197. (#16817)
Fixes:

    [FAIL] TestNSurlSessionHandlerCookieContainerSetCookie :   Cookies received from server.
        Expected: 1
        But was:  0
            at MonoTests.System.Net.Http.MessageHandlerTest.TestNSurlSessionHandlerCookieContainerSetCookie() in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 233

    [FAIL] TestNSUrlSessionHandlerCookies :   Failed to get managed cookies
        Expected: True
        But was:  False
            at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookies () [0x000aa] in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:144

Fixes https://github.com/xamarin/maccore/issues/2197.
2022-11-23 07:54:04 +01:00
Rolf Bjarne Kvinge c1606d5497
[Foundation] Unify a few NSAttributedString constructor implementations. (#16804)
Unify the code for the following constructors:

* NSAttributedString (NSData data, NSDictionary options, out NSDictionary resultDocumentAttributes, ref/out NSError error);
* NSAttributedString (NSUrl url, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref/out NSError error);
* NSAttributedString (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref/out NSError error);

These functions use 'ref' arguments instead of 'out' arguments for mobile
platforms (likely due to the generator not having proper 'out' parameter
support when these functions were implemented), so improve to use 'out'
parameters in XAMCORE_5_0 (and macOS, where they already use 'out'
parameters).

Also fix nullability.

Ref: https://github.com/xamarin/xamarin-macios/issues/15216
2022-11-21 21:05:20 +01:00
Rolf Bjarne Kvinge d7f5544c18
[tests] Adjust ImageCaptioningTest to skip network-related failures in CI. (#16814)
Fixes:

    MonoTouchFixtures.MediaAccessibility.ImageCaptioningTest
    	[FAIL] GetCaption : Ignore this failure when network is down
    		   at MonoTouchFixtures.MediaAccessibility.ImageCaptioningTest.GetCaption() in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/MediaAccessibility/ImageCaptioningTest.cs:line 36

Ref: https://github.com/xamarin/maccore/issues/2088.
2022-11-21 20:55:49 +01:00
Rolf Bjarne Kvinge 0076cd9920
[autoformat] Add .NET tests. (#16811) 2022-11-21 09:45:49 +01:00
Rolf Bjarne Kvinge ce1a2a7036
[tests] Improve AsyncTests.Bug12221 to not fail on 403 errors on the bots. (#16815)
Fixes:

    [FAIL] Bug12221 : System.AggregateException : One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).)
    ----> System.Net.Http.HttpRequestException : Response status code does not indicate success: 403 (Forbidden).
          at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean )
          at System.Threading.Tasks.Task.Wait(Int32 , CancellationToken )
          at System.Threading.Tasks.Task.Wait()
          at LinkSdk.AsyncTests.Bug12221() in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/linker/ios/link sdk/AsyncTest.cs:line 25
          at System.Reflection.MethodInvoker.InterpretedInvoke(Object , Span`1 , BindingFlags )
       --HttpRequestException
          at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
          at System.Net.Http.HttpClient.GetStringAsyncCore(HttpRequestMessage , CancellationToken )
          at LinkSdk.AsyncTests.<>c.<<LoadCategories>b__0_0>d.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/linker/ios/link sdk/AsyncTest.cs:line 16

One important detail is the change from calling 'Wait ()' to calling
'GetAwaiter ().GetResult ()': this is to avoid the AggregateException in the
stack trace above.

Fixes https://github.com/xamarin/maccore/issues/2570.
2022-11-21 09:37:31 +01:00
Rolf Bjarne Kvinge b3870ccb6d
[tests] Adjust MonoTouchFixtures.VideoToolbox.VTCompressionSessionTests.TestCallback to ignore timeouts in CI. (#16816)
Fixes:

    MonoTouchFixtures.VideoToolbox.VTCompressionSessionTests.TestCallback
    	[FAIL] TestCallback(True) :   timed out
      Expected: True
      But was:  False
    		   at MonoTouchFixtures.VideoToolbox.VTCompressionSessionTests.TestCallback(Boolean stronglyTyped) in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/VideoToolbox/VTCompressionSessionTests.cs:line 171
    	[FAIL] TestCallback(False) :   timed out
      Expected: True
      But was:  False
    		   at MonoTouchFixtures.VideoToolbox.VTCompressionSessionTests.TestCallback(Boolean stronglyTyped) in /Users/builder/azdo/_work/3/s/xamarin-macios/tests/monotouch-test/VideoToolbox/VTCompressionSessionTests.cs:line 171
    		   at InvokeStub_VTCompressionSessionTests.TestCallback(Object, Object, IntPtr*)
2022-11-21 09:37:08 +01:00
Rolf Bjarne Kvinge 5ba78a77cd
[tests] Update the size-comparison test to work on .NET 7+. (#16818) 2022-11-21 09:36:46 +01:00
Rolf Bjarne Kvinge 328f56fd4f
[tests] Ensure all .NET tests use the current .NET version. (#16820) 2022-11-21 09:35:04 +01:00
Rolf Bjarne Kvinge 349b045263
[tests] Don't run watchOS tests for .NET. (#16809)
Fixes these tests:

```
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BuildMachineOSBuild: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleDevelopmentRegion: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleExecutable: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleIdentifier: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleInfoDictionaryVersion: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleName: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundlePackageType: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleSignature: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleSupportedPlatforms: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).BundleVersion: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).DeviceFamily: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).MinimumOSVersion: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).MissingBundleIdentifier: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).MissingDisplayName: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).NormalPlist: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).NoWatchCompanion: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).PlistMissing: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).VerifyAllDT: System.InvalidOperationException : Invalid platform: WatchOS
* Xamarin.MacDev.Tasks.GeneratePlistTaskTests_watchOS_WatchKitExtension(True).XamarinVersion: System.InvalidOperationException : Invalid platform: WatchOS
```
2022-11-21 09:16:15 +01:00
Rolf Bjarne Kvinge 1c29665f72
[tests] Ignore SWCollaborationView in DelegateAndSourceTest. (#16777)
[SWCollaborationView setDelegate:] crashes when passed null.

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-11-18 08:02:42 +01:00
Rolf Bjarne Kvinge 0a53f3cd60
Add automatic support for not building iOS 32-bit stuff when min iOS version is >= 11.0 (#16746)
There are no changes for 32-bit watchOS, because watchOS support is likely to
go away completely anyways.
2022-11-18 07:59:46 +01:00
Rolf Bjarne Kvinge 5e010e6700
[xharness] Fix typo when checking whether legacy Xamarin is enabled or not. (#16771)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-11-17 17:09:02 -05:00
Rolf Bjarne Kvinge 8ad9df8523
[autoformat] Add generator tests. (#16800) 2022-11-17 17:04:21 -05:00
Rolf Bjarne Kvinge 95783dbb50
[Foundation] Unify a few NSAttributedString functions. (#16782)
Unify the code for the following functions:

* NSAttributedString.GetData[FromRange]
* NSAttributedString.GetFileWrapper[FromRange]

These functions use 'ref' arguments instead of 'out' arguments for mobile
platforms (likely due to the generator not having proper 'out' parameter
support when these functions were implemented), so improve to use 'out'
parameters in XAMCORE_5_0 (and macOS, where they already use 'out'
parameters).

Also fix nullability.

Ref: https://github.com/xamarin/xamarin-macios/issues/15216
2022-11-17 15:51:19 +01:00
Rolf Bjarne Kvinge bedcbb063f
[Foundation] Remove support for '[NSAttributedString initWithFileURL:options:documentAttributes:error:]'. (#16787)
The 'initWithFileURL:options:documentAttributes:error:' was deprecated in iOS
9, and a new alternative (initWithURL:options:documentAttributes:error:) was
added. At the time, we implemented automatic detection of the current OS, and
would choose one version or the other depending on which was available.

We won't support anything below iOS 9 anymore, which means that keeping the
backwards-compatible constructor is useless, so just remove the corresponding
code and expose the new alternative directly.

On another note, this constructor uses a 'ref NSError' argument instead of an
'out NSError' on mobile platforms (likely due to the generator not having
proper 'out' parameter support when this constructor was implemented), so
improve to use 'out' parameters in XAMCORE_5_0 (and macOS, where it already
uses 'out' parameters).

Ref: https://github.com/xamarin/xamarin-macios/issues/15216
2022-11-17 15:45:11 +01:00
Rolf Bjarne Kvinge 3585c66844
[autoformat] Add common test files. (#16740) 2022-11-17 13:04:59 +01:00
Rolf Bjarne Kvinge 7003d324ef
[tests] Don't build packaged macOS tests in parallel in CI. (#16785)
The random build failure it causes aren't worth it for the speed gain.
2022-11-17 13:00:43 +01:00
Rolf Bjarne Kvinge 3bbf06aef2
[xharness] Print more diagnostic code during and after the test run. (#16709)
* Print the load average every 15 minutes. Also print a full process list if
  the load average > 10.
* Print a full process list of the system every hour.
* Print a summary to stdout at the end of the test run.

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-11-16 07:55:53 +01:00
Rolf Bjarne Kvinge 97eee84442
[tests] Ignore PassLibraryTest.PassLibraryTest on bots if PKPassLibrary.GetPasses returns null. Fixes #xamarin/maccore@2598. (#16738)
PKPassLibrary.GetPasses randomly returns null for no apparent rhyme or reason
on our bots, so just ignore the test in that case.

Maybe if someone can reproduce locally one day we'll be able to investigate
and figure out what's happening.

Fixes https://github.com/xamarin/maccore/issues/2598.
2022-11-16 07:54:57 +01:00
Rolf Bjarne Kvinge 86da9cc115
[tests] Use a different identifier than '%...%' for replacement text. (#16762)
When the autoformatter runs into the '%...%' pattern in *.cs files, it
will re-format the text (to '% ... %'), but that breaks our text replacement
logic. So instead use a valid C# identifier as a replacement token, in which
case the autoformatter won't confuse our replacement logic.
2022-11-16 07:39:48 +01:00
Rolf Bjarne Kvinge 0140122668
[autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
Manuel de la Pena 58a14e9231
[DevOps] Do not use ta vm for the pkgs upload due to its hdd size. (#16765)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-11-15 18:15:36 -05:00
Rolf Bjarne Kvinge 9af83cd712
[monotouch-test] Ignore certificate chain errors on bots. Fixes #xamarin/maccore@2626. (#16743)
Ignore certificate chain errors on bots in MessageHandlerTest.RejectSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler.

Fixes https://github.com/xamarin/maccore/issues/2626.
2022-11-15 17:43:11 +01:00
Marius Ungureanu 4025f4e881
Fix ownership of CFSocketCreateRunLoopSource (#6089)
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-11-15 15:55:21 +01:00
Rolf Bjarne Kvinge 2d96d43145
[xtro] Fix targets file and print out full path to the html report. (#16721)
There was a typo in the target name for creating the html report for .NET
('report-dotnet' vs 'dotnet-report').

Also print out the full path the html report when it's created, makes it much
easier to open the file from the command line because I can c&p the entire
path.
2022-11-14 18:18:06 +01:00
Rolf Bjarne Kvinge 3b839e1551
[autoformat] Add msbuild tests. (#16717) 2022-11-14 08:58:59 +01:00
Rolf Bjarne Kvinge 09f84f988c
[autoformat] Autoformat after a PR race. (#16720)
There was a PR race:

1. I created a PR to autoformat monotouch-test code.
2. Another PR added incorrectly formatted code to monotouch-test.
3. The first PR was merged, everything was fine.
4. The second PR was merged (it was green) - but its code hadn't been
   autoformatted.
5. Now there's incorrectly formatted code in the repo, which will show up in
   every new PR.

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-11-14 08:43:39 +01:00
Rolf Bjarne Kvinge 380cb06077
[tests] Make CFNotificationCenterTest.TestNullNameAndObserver wait for notifications. Hopefully fixes #xamarin/maccore@1440. (#16699)
Hopefully fixes https://github.com/xamarin/maccore/issues/1440.
2022-11-11 13:42:49 +01:00
Rolf Bjarne Kvinge 34995569fc
[tests] Fix conditional logic for .NET 7+. (#16704)
Fixes this test in .NET 8:

    AesCreate: System.Security.Cryptography.Algorithms,
        Expected: String starting with "System.Security.Cryptography.Algorithms, "
        But was: "System.Security.Cryptography, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
2022-11-11 09:48:33 +01:00
Marius Ungureanu 2bd6433fda
[perf] Add unmanaged constraint to some APIs to allow pinning, and not manual GCHandle code (#7561)
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2022-11-11 08:58:46 +01:00
Rolf Bjarne Kvinge 6f45caa84d
[autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Rolf Bjarne Kvinge bc95efb0ae
[autoformat] Add xtro. (#16622) 2022-11-08 17:44:13 +01:00
Rolf Bjarne Kvinge 30436599f2
[tests] Remove a few duplicated package references. (#16613)
The NUnitLite package is already included in the shared-dotnet.csproj file,
which these projects import.
2022-11-07 16:50:39 +01:00
Rolf Bjarne Kvinge 78229568e7
[autoformat] Add introspection. (#16593) 2022-11-07 15:20:26 +01:00
Rolf Bjarne Kvinge ceaa0171da
Merge net7.0-xcode14.1 into main. (#16555)
This merges .NET 7 + Xcode 14.1 support into main.
2022-11-04 08:36:25 +01:00
Whitney Schmidt 3c65ab1756
Fix DateTime -> NSDate conversion (#7404)
Update conversions from `NSDate` to `DateTime` and `DateTime` to `NSDate` to use date components instead of `SecondsSinceReferenceDate`.

The number of seconds since reference date is inconsistent between `NSDate` and `DateTime`. See the associated bug - converting `DateTime` 1/1/1 to `NSDate` ends up giving you an `NSDate` a couple days off :(

Fixes https://github.com/xamarin/xamarin-macios/issues/6993.

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-11-03 21:11:00 +01:00
Rolf Bjarne Kvinge cdc62aeae9 Merge remote-tracking branch 'origin/net7.0-xcode14.1' into main-net7.0-xcode14.1 2022-11-03 08:21:55 +01:00
Rolf Bjarne Kvinge 940e1d09e9 Merge xcode14.1 into net7.0-xcode14.1. 2022-11-02 19:03:30 +01:00
VS MobileTools Engineering Service 2 988bf9b4ba
[net7.0-xcode14.1] [tests] Handle managed exceptions in a networking callback. (#16535)
Fixes a problem where any exception would crash the process, because the
callback was executed on a background thread, and there was no other managed
frame catching the managed exception:

    MonoTests.System.Net.Http.MessageHandlerTest.RejectSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler
    2022-10-21 07:02:23.557 monotouchtest[91107:28076542] *** Terminating app due to uncaught exception 'NUnit.Framework.AssertionException', reason: '  Expected: None
      But was:  RemoteCertificateChainErrors
     (NUnit.Framework.AssertionException)
       at NUnit.Framework.Assert.ReportFailure(String message)
       at NUnit.Framework.Assert.ReportFailure(ConstraintResult result, String message, Object[] args)
       at NUnit.Framework.Assert.AreEqual(Object expected, Object actual)
       at MonoTests.System.Net.Http.MessageHandlerTest.<>c__DisplayClass14_0.<RejectSslCertificatesWithCustomValidationCallbackNSUrlSessionHandler>b__2(HttpRequestMessage sender, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors errors) in /Users/builder/azdo/_work/2/s/xamarin-macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 613
       at Foundation.NSUrlSessionHandler.ServerCertificateCustomValidationCallbackHelper.Invoke(HttpRequestMessage request, SecTrust secTrust)
       at Foundation.NSUrlSessionHandler.TryInvokeServerCertificateCustomValidationCallback(HttpRequestMessage request, SecTrust secTrust, Boolean& trusted)
       at Foundation.NSUrlSessionHandler.NSUrlSessionHandlerDelegate.DidReceiveChallenge(NSUrlSession session, NSUrlSessionTask task, NSUrlAuthenticationChallenge challenge, Action`2 completionHandler)
    --- End of stack trace from previous location ---
       at ObjCRuntime.Runtime.InvokeMethod(MethodBase method, Object instance, IntPtr native_parameters)
       at ObjCRuntime.Runtime.InvokeMethod(MonoObject* methodobj, MonoObject* instanceobj, IntPtr native_parameters)
       at ObjCRuntime.Runtime.bridge_runtime_invoke_method(MonoObject* method, MonoObject* instance, IntPtr parameters, IntPtr& exception_gchandle)
    '
    *** First throw call stack:
    (
    	0   CoreFoundation                      0x00007ff81dba97c3 __exceptionPreprocess + 242
    	1   libobjc.A.dylib                     0x00007ff81d909bc3 objc_exception_throw + 48
    	2   monotouchtest                       0x000000010426e524 xamarin_process_managed_exception + 820
    	3   monotouchtest                       0x00000001042fec76 _ZL32native_to_managed_trampoline_183P11objc_objectP13objc_selectorPP11_MonoObjectS0_S0_S0_S0_j + 1302
    	4   monotouchtest                       0x00000001042fe750 -[Foundation_NSUrlSessionHandler_NSUrlSessionHandlerDelegate URLSession:task:didReceiveChallenge:completionHandler:] + 80
    	5   CFNetwork                           0x00007ff8225d3635 _CFHostIsDomainTopLevelForCertificatePolicy + 13206
    	6   libdispatch.dylib                   0x00007ff81d8af0cc _dispatch_call_block_and_release + 12
    	7   libdispatch.dylib                   0x00007ff81d8b0317 _dispatch_client_callout + 8
    	8   libdispatch.dylib                   0x00007ff81d8b6317 _dispatch_lane_serial_drain + 672
    	9   libdispatch.dylib                   0x00007ff81d8b6e30 _dispatch_lane_invoke + 417
    	10  libdispatch.dylib                   0x00007ff81d8c0eee _dispatch_workloop_worker_thread + 753
    	11  libsystem_pthread.dylib             0x00007ff81da63fd0 _pthread_wqthread + 326
    	12  libsystem_pthread.dylib             0x00007ff81da62f57 start_wqthread + 15


Backport of #16414

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-11-02 18:05:06 +01:00
VS MobileTools Engineering Service 2 3536335c3a
[xcode14.1] [ObjCRuntime] Change Runtime.GetNSObject<T> to create a new instance if the existing one is of the wrong type. Fixes #13704. (#16502)
Objective-C has an optimization where creating an empty dictionary would
return the same instance every time (probably to a constant empty
dictionary).

This causes a problem with how we've bound generic dictionaries, because
all
empty dictionaries would have the same native handle, even if we'd bound
them
with different managed types.

This surfaces in unfortunate ways when we try to look up a managed
instance
given a native handle, we find that we already have a managed instance,
but
the managed instance is of the wrong type.

Example code:

    var a = new NSDictionary ();
    var b = new NSDictionary<NSString, NSString> ();
    var c = new NSDictionary<NSString, NSObject> ();
    Console.WriteLine ($"a: 0x{a.Handle:X}");
    Console.WriteLine ($"b: 0x{b.Handle:X}");
    Console.WriteLine ($"c: 0x{c.Handle:X}");

would produce something like:

    a: 0x0x7fff80821080
    b: 0x0x7fff80821080
    c: 0x0x7fff80821080

now for this code:

    Runtime.GetNSObject<NSDictionary<NSString, NSString>> (b.Handle)

it would throw an exception like this:

Unable to cast object of type
'Foundation.NSDictionary`2[[Foundation.NSString],[Foundation.NSObject]]'
to type
'Foundation.NSDictionary`2[[Foundation.NSString],[Foundation.NSString]]'

because we'll have the 'c' object (with type `NSDictionary<NSString,
Object>`)
in our dictionary of native handles -> managed instances, and that's not
compatible with the desired return type from GetNSObject
(`NSDictionary<NSString, NSString>`)

This likely happens with all the non-mutable collection types we have a
generic version of (NSArray, NSDictionary, NSOrderedSet, NSSet).

Fixes https://github.com/xamarin/xamarin-macios/issues/16378.
Fixes https://github.com/xamarin/xamarin-macios/issues/13704.

This PR is somewhat simpler to review by ignoring whitespace:
https://github.com/xamarin/xamarin-macios/pull/16491/files?w=1


Backport of #16491

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-10-28 16:53:15 -04:00
Rolf Bjarne Kvinge adf3dacabf
[tests] Don't block forever in CoreFoundation.ProxyTest if something goes wrong. (#16495) 2022-10-28 11:07:11 +02:00
Rolf Bjarne Kvinge 543d73be3c
[ObjCRuntime] Change Runtime.GetNSObject<T> to create a new instance if the existing one is of the wrong type. Fixes #13704. (#16491)
Objective-C has an optimization where creating an empty dictionary would
return the same instance every time (probably to a constant empty dictionary).

This causes a problem with how we've bound generic dictionaries, because all
empty dictionaries would have the same native handle, even if we'd bound them
with different managed types.

This surfaces in unfortunate ways when we try to look up a managed instance
given a native handle, we find that we already have a managed instance, but
the managed instance is of the wrong type.

Example code:

    var a = new NSDictionary ();
    var b = new NSDictionary<NSString, NSString> ();
    var c = new NSDictionary<NSString, NSObject> ();
    Console.WriteLine ($"a: 0x{a.Handle:X}");
    Console.WriteLine ($"b: 0x{b.Handle:X}");
    Console.WriteLine ($"c: 0x{c.Handle:X}");

would produce something like:

    a: 0x0x7fff80821080
    b: 0x0x7fff80821080
    c: 0x0x7fff80821080

now for this code:

    Runtime.GetNSObject<NSDictionary<NSString, NSString>> (b.Handle)

it would throw an exception like this:

    Unable to cast object of type 'Foundation.NSDictionary`2[[Foundation.NSString],[Foundation.NSObject]]' to type 'Foundation.NSDictionary`2[[Foundation.NSString],[Foundation.NSString]]'

because we'll have the 'c' object (with type `NSDictionary<NSString, Object>`)
in our dictionary of native handles -> managed instances, and that's not
compatible with the desired return type from GetNSObject
(`NSDictionary<NSString, NSString>`)

This likely happens with all the non-mutable collection types we have a
generic version of (NSArray, NSDictionary, NSOrderedSet, NSSet).

Fixes https://github.com/xamarin/xamarin-macios/issues/16378.
Fixes https://github.com/xamarin/xamarin-macios/issues/13704.
2022-10-28 11:05:52 +02:00
Rolf Bjarne Kvinge d0fa5760e1
[tests] Fix typo in 'test' call in script to package mac tests. (#16496) 2022-10-28 09:53:28 +02:00
Rolf Bjarne Kvinge c708c71c3b Merge remote-tracking branch 'origin/xcode14.1' into bump-xcode14.1-in-net7.0-xcode14.1-2022-10-24 2022-10-28 09:50:14 +02:00