Forum Visual Studio

Xaml files showing twice & ambiguity error in .Net Std/Forms projects

Not sure if this belongs in the Xamarin Forms forum or here... but I think it has something to do with the following bug reported where .xaml files are showing up twice in the IDE in .Net Standard projects:

I have converted one of my Xamarin Forms apps to .Net Standard targetting Core 2.... everything working fine but Intellisense is reporting the following (or similar) for all Xaml elements referenced in the code behind...

**Error: Ambiguity between 'Page.lblHeading' and 'Page.lblHeading'...

So all elements referenced from the code behind are highlighted red/underlined in Intellisense.

Best Answer


  • mattwardmattward GBMember Xamurai

    That bug linked to is specific to the project on a particular GitHub site since it uses file wildcards to include .xaml files into the project. The latest code on GitHub has a change that solves the problem in the .csproj file itself.

    What does the contents of .csproj file look like?

  • LeonPotgieterLeonPotgieter ZAMember ✭✭

    Hi, ok have tested this extensively and still cannot find a way to sort it out...

    I've attached 2 csproj files which both have different issues:

    "csproj test 1" is the only way I can still successfully compile a project without the Duplicate Embedded Resource items (as explained below) but I do have the ambiguity error as described in my first post...

    "csproj test 2" (as per the github example) doesn't compile and produces the following error:

    /usr/local/share/dotnet/sdk/2.0.0/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.DefaultItems.targets(5,5): Error: Duplicate 'EmbeddedResource' items were included. The .NET SDK includes 'EmbeddedResource' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultEmbeddedResourceItems' property to 'false' if you want to explicitly include them in your project file. For more information, see The duplicate items were: 'Views/CreateContent/CreateNewMessagePage.xaml'; 'Views/Main/ActivityPage.xaml'; 'Views/Main/AssistancePage.xaml'; 'Views/Main/ContentViews/PanicView.xaml'; 'Views/Main/ContentViews/PhotoPage.xaml'; 'Views/Main/DashboardPage.xaml'; 'Views/Main/MapPage.xaml'; 'Views/Main/NewsPage.xaml'; 'Views/Main/NHWMasterPage.xaml'; 'Views/Opened/ActivityOpenedPage.xaml'; 'Views/Opened/NewsOpenedPage.xaml'; 'Views/Opened/PanicPage.xaml'; 'Views/Registration and Login/AddGroupPage.xaml'; 'Views/Registration and Login/AddressConfirmationPage.xaml'; 'Views/Registration and Login/AddressPage.xaml'; 'Views/Registration and Login/AddressResultsPage.xaml'; 'Views/Registration and Login/GroupPage.xaml'; 'Views/Registration and Login/LoginPage.xaml'; 'Views/Registration and Login/OldRegistrationPage.xaml'; 'Views/Registration and Login/RegistrationPage.xaml'; 'Views/Registration and Login/SetPinPage.xaml'; 'Views/Registration and Login/SignupPage.xaml'; 'Views/Tab/TabbedNavPage.xaml' (NHW)

  • LeonPotgieterLeonPotgieter ZAMember ✭✭

    Thank you Matt, I can confirm that updating to pre2 has resolved the issue.

  • mattwardmattward GBMember Xamurai

    It looks like this works with since the .targets file there is incorrect and never adds any default items. It looks like a mistake which has been corrected in a more recent version of Xamarin.Forms.

    I tried the latest nightly of Xamarin.Forms and that seems OK. The only problem was that the files were duplicated in the Solution window in VS Mac. Removing all the files from the .csproj fixes the solution window problem but then that seems to break compilation - it seems that the .g.cs files are not generated for the .xaml files in the obj directory.

  • LeonPotgieterLeonPotgieter ZAMember ✭✭

    Ok, so are you saying that future versions of Xamarin Forms will most probably break compilation again (and that the only alternative is to have duplicate files in the solution window?)

    Is this a VS Mac issue then?

  • mattwardmattward GBMember Xamurai

    No the latest Xamarin.Forms nightly did not break compilation unlike the pre2 version. The build error when removing all files seems like a Xamarin.Forms NuGet package problem and not a VS Mac bug.

    With the latest nightly you can also disable the items added by the Xamarin.Forms NuGet package by using the MSBuild property:


    I have opened a bug about the VS Mac problems with the latest Xamarin.Forms NuGet package.

  • mdizzymdizzy USMember ✭✭

    I'm seeing a similar problem with the released version of forms ( but I guess because I don't reference the UI in my code behind the problem only exists when I attempt to build from the cli.

    I upgraded a pre-existing project to target dotnetstandard so I'm thinking I didn't do the translation right. (Also the codebehind is no longer nested beneath the xaml in Visual studio).

  • mattwardmattward GBMember Xamurai

    Xamarin.Forms 2.4 provides its own default MSBuild items which is currently not handled by Visual Studio for Mac and causes it to show duplicate items in the Solution window. There are also other problems here with VS Mac. This bug is currently being tracked on bugzilla:

Sign In or Register to comment.