Skip to content

Platform dependent file not found #6674

@MichaelRumpler

Description

@MichaelRumpler

Description

I created a new MAUI Class Library with platform dependent files and folders. Now from a file with an *.iOS.cs extension which should only be compiled for iOS and MacCatalyst I want to call a method in a file in Platforms/iOS/iOSHelper.cs which should also only be compiled for iOS and MacCatalyst. But I get an error that the Platforms.iOS namespace does not exist. It looks like VS tries to compile my .iOS.cs file for net6 and for that TargetFramework it really does not exist.

image

But the project dropdown only shows iOS and MacCatalyst as expected.

image

The same as the class I want to call.

image

The funny thing is, that VS does not show an error in intellisense. It even added the using statement itself (added with ctrl-.).

I also have similar code in LabelHandler.Android.cs where I call into MauiLib2.Platforms.Android.AndroidHelper and this works.

Here is a repro project:
MauiLib2.zip

Steps to Reproduce

  1. open VS Version 17.2.0 Preview 5.0
  2. create a new MAUI Class Library
  3. copy the lines from https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/configure-multi-targeting#combine-filename-and-folder-multi-targeting to the .csproj file
  4. create a class with an .iOS.cs extension outside the Platforms folder
  5. create another class in Platforms/iOS
  6. try to call the latter from the former

(or simply open the attached repro project and try to compile it)

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Visual Studio Version 17.2.0 Preview 5.0

Did you find any workaround?

No

Relevant log output

The error message in the Output window is:

1>D:\Temp\MauiLib2\MauiLib2\Handlers\LabelHandler.iOS.cs(3,16,3,25): error CS0234: The type or namespace name 'Platforms' does not exist in the namespace 'MauiLib2' (are you missing an assembly reference?)

But the Error List shows it better as this includes the platform for which it tries to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-single-projectSplash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizerplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions