Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning "retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIApplicationDelegate' [-Wproperty-attribute-mismatch]" after building ios xamarin app #10722

Open
rolfbjarne opened this issue Feb 25, 2021 · 12 comments
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Milestone

Comments

@rolfbjarne
Copy link
Member

Steps to reproduce:

  1. Create iOS Single view App
  2. Build for device

Expected:

There are no warnings

Actual:

  1. After building project, there are two warnings
  In file included from /Users/rolf/Projects/devdiv1283065/obj/iPhone/Debug/mtouch-cache/registrar.m:3:
/Users/rolf/Projects/devdiv1283065/obj/iPhone/Debug/mtouch-cache/registrar.h(20,43): warning GBD8E3C1A: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIWindowSceneDelegate' [-Wproperty-attribute-mismatch] [/Users/rolf/Projects/devdiv1283065/devdiv1283065.csproj]
          @property (nonatomic, assign) UIWindow * window;
                                                   ^
/Users/rolf/Projects/devdiv1283065/obj/iPhone/Debug/mtouch-cache/registrar.h(41,43): warning GBD8E3C1A: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIApplicationDelegate' [-Wproperty-attribute-mismatch] [/Users/rolf/Projects/devdiv1283065/devdiv1283065.csproj]
          @property (nonatomic, assign) UIWindow * window;

This happens because the static registrar doesn't take into account inherited properties when generating the Objective-C property declaration.

Full build log:
build.txt

Project:
devdiv1283065-d8864fc.zip

Source: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1283065

@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac iOS Issues affecting Xamarin.iOS labels Feb 25, 2021
@rolfbjarne rolfbjarne added this to the Future milestone Feb 25, 2021
@awattar
Copy link

awattar commented Oct 5, 2023

Any update, fix or workaround?

@rolfbjarne
Copy link
Member Author

@awattar none that I know of. Note that this is a warning only, so it shouldn't break anything.

@vogtadi
Copy link

vogtadi commented Oct 18, 2023

Using a legacy project, which I ported from Xamarin to net7.0 I had the same error as documented in the initial post.

In my projects, Debug builds where declared with <MtouchLink>None</MtouchLink>.
Replacing this with <MtouchLink>SdkOnly</MtouchLink> resolved the warning.

I guess this is rather a workaround, than a fix.

@JHUcperry30
Copy link

JHUcperry30 commented Oct 21, 2024

I was asked to share this here from a stack overflow question https://stackoverflow.com/questions/79094858/maui-error-retain-or-strong-attribute-on-property-window-does-not-match-pro/79101001#79101001:

I am also getting this error, however unlike what @rolfbjarne said this does break the app; it works in all simulators but crashes as soon as it attempts to boot on a physical IOS device. This is weather I am trying to boot it via TestFlight or attempting to boot to an IOS device connected to my Mac via a USB.

Again this is the error:

warning: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIApplicationDelegate' [-Wproperty-attribute-mismatch] [/Users/user/Projects/cds-tims-mobile-client/TIMS.csproj]

I googled around a bit and have tried a few things. I changed my AppDelegate file:

using Foundation;
using UIKit; // Add this to resolve UIWindow

namespace TIMS;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
	[Export("window")]
    public override UIWindow? Window { get; set; }

    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

Adding this part:

[Export("window")]
public override UIWindow? Window { get; set; }

I also tried @vogtadi solution: setting MtouchLink in the csproj file to sdkOnly:

<MtouchLink>SdkOnly</MtouchLink>

But this also did not help. I have also made sure to delete the obj and bin folder and try again but that still did not help.

Upon further testing I am not sure if I was even the right track whatsoever. I have altered my app delegate class to look like this:

using Foundation;

namespace TIMS;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

and I still get the same error.

I have research this a bit and my problem seems to be more specifically this:

The attribute on my window property (nonatomic, assign) does not match what UIApplicationDelegate expects (retain or strong). The line @property (nonatomic, assign) UIWindow * window; is in an automatically generated Objective-C header file (registrar.h) that is generated during the build process in a Xamarin or .NET MAUI iOS project. It is part of the Objective-C interop code generated by the Xamarin.iOS or .NET MAUI toolchain, which is responsible for marshaling between C# and Objective-C during the build.

So I need to find a way to get my AppDelegate to generate the line @property (nonatomic, strong) UIWindow * window; instead of @property (nonatomic, assign) UIWindow * window;.

This is where I am stuck. This issue is not specific to 1 app. This happens to any MAUI app even in a brand new untouched MAUI project.

I am using MacOS Sequoia 15.0.1, Xcode 16 beta, and dotnet 8.0.401. It doesn't matter what the phone model or IOS version because the issue occurs on every phone we have tried. Would be happy to share anything else to help find a solution.

@rolfbjarne
Copy link
Member Author

@JHUcperry30 the build output is a bit confusing, because first a few warnings are reported, and then errors. Unfortunately the output is truncated before the errors are shown, which makes it look like the problem are the warnings, but they're completely unrelated.

Please get an MSBuild binlog, and we'll have a look at the complete output to see what's actually going on.

@JHUcperry30
Copy link

JHUcperry30 commented Oct 21, 2024

Thank you so much for the quick reply @rolfbjarne . When I tried to generate the file it gave me this error:

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : clang exited with code 1: [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : In file included from /Users/coleperry/Projects/cds-tims-mobile-client/obj/Debug/net8.0-ios/ios-arm64/linker-cache/registrar.mm:3: [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : /Users/coleperry/Projects/cds-tims-mobile-client/obj/Debug/net8.0-ios/ios-arm64/linker-cache/registrar.h:257:43: warning: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIApplicationDelegate' [-Wproperty-attribute-mismatch] [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : 257 | @property (nonatomic, assign) UIWindow * window; [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : | ^ [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : /Users/coleperry/Projects/cds-tims-mobile-client/obj/Debug/net8.0-ios/ios-arm64/linker-cache/registrar.h:1339:43: warning: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIWindowSceneDelegate' [-Wproperty-attribute-mismatch] [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : 1339 | @property (nonatomic, assign) UIWindow * window; [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : | ^ [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : /Users/coleperry/Projects/cds-tims-mobile-client/obj/Debug/net8.0-ios/ios-arm64/linker-cache/regis [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj]

Condensed version:
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : clang exited with code 1: [/Users/coleperry/Projects/cds-tims-mobile-client/TIMS.csproj] /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : Undefined symbols for architecture arm64: "_xamarin_is_object_valid", "_xamarin_is_user_type" /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8303/targets/Xamarin.Shared.Sdk.targets(1455,3): error : 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIApplicationDelegate' or 'UIWindowSceneDelegate'

But it did generate a .binlog file that Github file picker will not let me add... I apologize if I am missing something here...

@rolfbjarne
Copy link
Member Author

But it did generate a .binlog file that Github file picker will not let me add... I apologize if I am missing something here...

You can zip it and attach the zip file.

@JHUcperry30
Copy link

But it did generate a .binlog file that Github file picker will not let me add... I apologize if I am missing something here...

You can zip it and attach the zip file.

Duh, idk why I didn't think to do that. I apologize...
msbuild.binlog.zip

@rolfbjarne
Copy link
Member Author

It looks like you're using a beta version of Xcode:

/Applications/Xcode-beta.app/Contents/Developer

Can you try upgrading to the latest stable (Xcode 16.0)?

@JHUcperry30
Copy link

@rolfbjarne I did not think I could. I did not think Xcode 16 supported dotnet 8: #20802. Someone in this thread recommended using 16 beta which did work for me and that's why I'm still using it. Am I misunderstanding that thread?

@rolfbjarne
Copy link
Member Author

@rolfbjarne I did not think I could. I did not think Xcode 16 supported dotnet 8: #20802. Someone in this thread recommended using 16 beta which did work for me and that's why I'm still using it. Am I misunderstanding that thread?

At the very top, it says:

⚠️ Xcode 16 support is now released for .NET 8, please see release notes dotnet-8.0.1xx-xcode16.0-8303 (release) for installation instructions. This version of the macios workloads will be also included in the next version of Visual Studio 17.11.5.

So yes, Xcode 16 is supported on .NET 8.

@JHUcperry30
Copy link

JHUcperry30 commented Oct 21, 2024

So yes, Xcode 16 is supported on .NET 8.

I installed Xcode 16 and you are correct it did work this time with my simulators. However, I am still getting the same error as before when attempting to run on a physical device. Here is my new binlog:
Uploading msbuild.binlog.zip…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Projects
None yet
Development

No branches or pull requests

4 participants