3
votes

I've installed a fresh copy of Visual Studio 2017 Community Edition on Windows 10 Pro Fall Creators Update recently, and I'm unable to properly create a new ContentPage on Xamarin.Forms (see screenshots 1-3). At my first attempt of creating a new ContentPage in a new Xamarin.Forms project, I encountered the errors seen on screenshot 1 and 2.

Next, an automated error log was generated (as attached). If I don't create any new items and run as-is, I can successfully launch the app on my Android emulator with no issues.

Exception of type 'System.Exception' was thrown

Screenshot 1 - Exception of type 'System.Exception' was thrown

The project system has encountered an error.

Did not find new element in the hierarchy for item "Page2.xaml". The
item would have been added with type "Page". The project item
schema service knows about this item type. The item does exist
in the project file.

A diagnostic log has been written to the following location: "C:\..." (see below link)

Automatically generated error log file - txt

Screenshot 2 - Project system encountered an error; did not find new element in the hierarchy for item "Page2.xaml"...

The issues arise when I create a new ContentPage. The code-behind .cs file and .xaml file will not be immediately visible in the Solution Explorer. I need to manually click the Show All Files button to show the newly created files (as seen in screenshot 3). However, I couldn't include them into project despite multiple tries.

Screenshot 3 - Newly created xaml and cs files (Page1, Page2) not immediately visible and cannot be included into project

When I open a .xaml file (in this case Page2.xaml), errors mentioning missing references and assemblies are visible (see screenshot 4 below).

Screenshot 4 - in editor while editing xaml files - The type 'ContentPage' was not found...

I've done the following thus far:

  • Removed mobile app development (Xamarin) in the Visual Studio installer
  • Reinstalled Xamarin by including (checking) the mobile app development (Xamarin) in the Visual Studio installer

Are there any known solutions to this issue? Any assistance is kindly appreciated. Thanks!

UPDATE (Feb 27): Attempted recommendation by Paul-Jan but the issues still persist. However, the newly created Page1.xaml was properly included and recognized by Solution Explorer (as shown below). Newly created ContentPage is properly recognized

1
You have taken effort to assemble your question, admittedly, but please don't add code and error messages as images, but as text. This will render the quetion much mor searchable and is way better to read and understand.Paul Kertscher
Thanks for your comment Paul! I've added the error code texts for screenshot 1 and 2. However, I've retained the screenshot links for anyone who's interested to know in full.AdrianK09
for missing references please delete pages manually if you have deleted that pages.and then clean and rebuild.Neelam Prajapati
are you new to xamarin? may i know how you are adding new xamal page in project?Neelam Prajapati
I used Xamarin before, and I've come back recently to refresh my memory. Done deleting, cleaning, and building but there were no favorable results. I added a new ContentPage using Add > New Item from Solution Explorer.AdrianK09

1 Answers

1
votes

I've had this happen with fresh VS2017 Professional installs where Universal Windows Platform (UWP) support was not added during install. Of course you might have no desire at all to develop for UWP, but apparently there are bits and pieces of the Xamarin Forms toolchain missing when you don't install it.

Running the Visual Studio Installer again, adding UWP support, helps.

UWP Support checkbox in VS2017