question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contacts API namespace conflicts on MacCatalyst and iOS

See original GitHub issue

Description

I just upgraded to VS 17.3 P1.1 and the essentials API is complaining that the Contacts type in the Microsoft.Maui.ApplicationModel.Communication namespace is missing. Digging further it seems that there is a conflict with the type because there is a root namespace of Contacts already imported.

Generic code for .NET MAUI that should compile across all platforms won’t compile for iOS or MacCatalyst without #if or always fully qualifying the type.

Steps to Reproduce

Code that contains the following line should work on all platforms. It won’t compile on iOS/MacCatalyst

var contact = await Contacts.Default.PickContactAsync();

Version with bug

Release Candidate 3 (current)

Last version that worked well

Release Candidate 2

Affected platforms

iOS, macOS

Affected platform versions

Unsure

Did you find any workaround?

You have to fully qualify the name:

var contact = await Microsoft.Maui.ApplicationModel.Communication.Contacts.Default.PickContactAsync();

Relevant log output

CS0234	The type or namespace name 'Default' does not exist in the namespace 'Contacts' (are you missing an assembly reference?)	PlatformIntegration (net6.0-ios), PlatformIntegration (net6.0-maccatalyst)	

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
adegeocommented, May 25, 2022

@Eilon I’m finding that if iOS or Mac is a target, you must always fully qualify the type, or you can’t compile for all platforms. And these are targeted by default, obviously.

When I ran into this issue, I tried what you suggested, mapping Contacts specifically, this didn’t work though

image

The only way this works is by mapping the namespace instead:

using Communication = Microsoft.Maui.ApplicationModel.Communication;

...

Communication.Contacts.Default.Get...
1reaction
adegeocommented, May 23, 2022

@Eilon it seems to be something with mac/ios directly. There is a root namespace automatically imported when you target that framework. Here is the output of the intellisense and browsing to the code of one of those items:

image

#region Assembly Microsoft.iOS, Version=15.4.300.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
// C:\Program Files\dotnet\packs\Microsoft.iOS.Ref\15.4.303\ref\net6.0\Microsoft.iOS.dll
#endregion

using ObjCRuntime;
using System.Runtime.Versioning;

namespace Contacts
{
    [Native]
    [SupportedOSPlatform("ios9.0")]
    [SupportedOSPlatform("macos10.11")]
    [SupportedOSPlatform("maccatalyst9.0.0")]
    public enum CNAuthorizationStatus : long
    {
        NotDetermined = 0,
        Restricted = 1,
        Denied = 2,
        Authorized = 3
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Contacts - .NET MAUI
Because of a namespace conflict, the Contacts type must be fully qualified when targeting iOS or macOS: Microsoft.Maui.ApplicationModel.
Read more >
WKContentWorld | Apple Developer Documentation
A WKContentWorld object is a namespace and doesn't persist data outside of the current web view or webpage. If you use the same...
Read more >
The type or namespace name 'Platforms' does not exist in ...
When I read the entire error message, it states that it can't resolve the name in the iOS, Windows, MacCatalyst and Tizen projects....
Read more >
Avoiding property/method naming conflicts in Swift
Namespaces are used so we can group related methods and properties and avoid naming conflicts between multiple identifiers which may share the same...
Read more >
Apple Seeds Fifth Betas of iOS 17 and iPadOS 17 to ...
Apple today seeded the fifth betas of upcoming iOS 17 and iPadOS 17 updates to developers for testing purposes, with the software coming...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found