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

'Platform' does not contain a definition for 'Init' (iOS) #23145

Closed
metal450 opened this issue Jun 19, 2024 · 5 comments
Closed

'Platform' does not contain a definition for 'Init' (iOS) #23145

metal450 opened this issue Jun 19, 2024 · 5 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@metal450
Copy link

metal450 commented Jun 19, 2024

Description

I'm seeing the same issue as #21253, but in iOS rather than Android. Responses to the previous issue say he was using the wrong namespace & needs to use Microsoft.Maui.ApplicationModel...however...his original post states that he was using exactly that namespace (?). To eliminate any ambiguity, I'm using the full namespace inline:

  • I have an existing Xamarin.iOS app with TargetFramework net7.0-ios. It works perfectly, including Maui.Essentials
  • Upon updating the TargetFramework to net8.0-ios16.1, the same code no longer builds. The error is 'Platform' does not contain a definition for 'Init' on the line Microsoft.Maui.ApplicationModel.Platform.Init(() => window.RootViewController);
  • The project has a reference to Microsoft.Maui.Essentials 8.0.60.
  • The project previously worked without <UseMauiEssentials>true</UseMauiEssentials>, but I tried adding it after the error appeared in .Net 8. The behavior was the same.

Steps to Reproduce

  1. Create a new C# iOS application
  2. Add a reference to Microsoft.Maui.Essentials 8.0.60 from nuget
  3. Paste into AppDelegate.cs:
public void test()
{
    Microsoft.Maui.ApplicationModel.Platform.Init(() => new UIViewController());
}
  1. You'll see the error CS0117 'Platform' does not contain a definition for 'Init'
  2. Edit the project properties & downgrade the .NET target runtime from 8.0 to 7.0
  3. The error immediately resolves

Link to public reproduction project repository

link

Version with bug

8.0.60 SR6

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@metal450 metal450 added the t/bug Something isn't working label Jun 19, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@metal450
Copy link
Author

Added repro repo (tho it was created with just the 3 steps listed above)

@kevinxufei kevinxufei added platform/iOS 🍎 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Jun 20, 2024
@drasticactions
Copy link
Contributor

スクリーンショット 2024-06-20 17 27 58

Yeah, your repro shows this working.

My guess, based on your error, is that you either have that code inside a file that is being referenced by another target framework. Even though you mentioned this happening in AppDelegate in (I think) a MAUI UI project, which I also tried and worked fine, as expected.

public static void Init(Func<UIKit.UIViewController>? getCurrentUIViewController) =>

This would only works on iOS/Catalyst, and the single target MAUI solution targets iOS, Catalyst, Windows, and Android. So maybe you have it placed somewhere we're it's trying to be compiled for other platforms. Or maybe your IDE is targeting that file for other platforms and it's showing it as failing, but it would compile fine from CLI. My guess looking at that other issue you linked to is they had the same issue. Without having a sample project nor context into where they were typing their code, it was probably targeting the base TFM where nothing exists for Platform.

There is no change in that API from net7.0 to net8.0. IMO I don't think there's a bug here, I think it's more a configuration issue with your project and/or IDE. Could you try creating a MAUI UI project showing your issue?

@PureWeen PureWeen added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Jun 20, 2024
@kevinxufei kevinxufei removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jun 20, 2024
@drasticactions drasticactions added the s/needs-repro Attach a solution or code which reproduces the issue label Jun 20, 2024
@metal450
Copy link
Author

Ok, I had to do 2 things:

  • Upon updating Visual Studio, it fixed it in the repro project. But it still occurred in my actual app.
  • I had to change the Target OS version of the project to 17.2. Anything lower than that (even 17.0) causes this to occur, including in the sample project.

When the issue is present, if I go to the definition of Microsoft.Maui.ApplicationModel, I can see that it's because the #elif IOS || MACCATALYST case isn't being compiled. aka IOS isn't defined. I'm not sure why it should be necessary to both upgrade Visual Studio and change the target OS version for that to be defined, but in any event, it is an extremely unclear error that seems to crop up on multiple platforms, so it seems like there'd be a better way to handle it / report the issue to the user...?

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Jun 21, 2024
@drasticactions
Copy link
Contributor

My best guess would be it depends on what dotnet workloads you have, and what target framework you have selected in the IDE (As in, in the Editor dropdown, did you select ios, catalyst, or android). If your code compiles in CLI but the IDE shows errors then some wires are crossed in the IDE with what it thinks it can build and run.

In any case, those are more fundamental issues with target framework support in dotnet and the IDE/Editor your using, and not something that's specific to the MAUI UI framework. That can't be addressed here. I would direct that to VSFeedback.

@drasticactions drasticactions closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants