Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin System.Exception when adding Content page VS

When trying to add a Content Page to the solution in visual studio, the following error occurs:

Exception of type 'System.Exception' was thrown.

The project system has encountered an error.

Did not find new element in the hierarchy for item `Views\MyPage.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.

When adding the file I do the following:

Right click on Views in my Xamarin Solution > Add > New Item > Content Page > Add

When looking in the windows explorer, there is a file created MyPage.xaml but it has not created MyPage.xaml.cs and it is not added to the solution

It is a blank Xamarin shared project and this error just keeps happening...

It's driving me nuts as I can't even add a single page

As a workaround, I add the files manually using the W. explorer and then edit app.projitems manually, but this is just ridiculous.

like image 908
Mazzy Avatar asked Dec 10 '17 10:12

Mazzy


Video Answer


1 Answers

As a dirty workaround until this gets fixed, adding the files "manually" to the project gets the job done.

With Visual Studio closed,

  1. copy/paste existing (working) *.xaml and *.xaml.cs files (rename them as you please)
  2. open the newly pasted files with a text editor (not VS) and rename the contents to your chosen name in #1
  3. add newly pasted files to your *.projitems file (open it in a text editor, search for the filenames you copied in #1 and add the new ones similarly) - there'll be 3 places to add them

Now open the solution in VS and rebuild - it should look and build fine.

like image 57
The_Torst Avatar answered Sep 28 '22 09:09

The_Torst