The type "AppListEntry" exists in both Microsoft.Windows.SDK.NET and Windows.Foundation.UniversalApiContract

Viewed 144

I have an app (.NET 5.0) which references another project (.NET Core 2.1) via nuget (not publically available).

When I reference this project, the following line throws up an error:

AppListEntry appListEntry = await InstallUWPFromStoreAsync(appTest.CatalogId);

Error:

The type 'AppListEntry' exists in both 'Microsoft.Windows.SDK.NET, Version=10.0.17763.22, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Windows.Foundation.UniversalApiContract, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'

Is there a way to override which library should be the global source of truth for the application?

Update

Adding a fully qualified reference doesn't seem to resolve the issue:

enter image description here

2 Answers

There are a few ways you could disambiguate your references to AppListEntry.

You could fully qualify individual references:

Windows.ApplicationModel.Core.AppListEntry appListEntry =
    await InstallUWPFromStoreAsync(appTest.CatalogId);

Alternatively, you could use a using alias (typically placed with your other using directives):

using AppListEntry = Windows.ApplicationModel.Core.AppListEntry;
...
AppListEntry appListEntry = await InstallUWPFromStoreAsync(appTest.CatalogId);

If you're using C# 10 or later, you could make the using alias global, which would apply it to all files in the compilation (while only declaring it in one file):

global using AppListEntry = Windows.ApplicationModel.Core.AppListEntry;

You can try doing the following.

  1. Open your Nuget Package reference Properties.

  2. Provide new Alias for the reference, say another.

  3. Open your file and add this line extern alias another; before your namespace declaration.

  4. Now change your erroneous line to

    var appListEntry = await another::{Full Name of the locating namespace of the another library}.InstallUWPFromStoreAsync(appTest.CatalogId);

See details about extern keyword

Related