13
votes

I'm getting the following error when trying to preview XAML documents via the Xamarin.Forms Previewer while in Visual Studio.

An Android Application project must reference the project containing this xaml file in order to render in the previewer.

I've tried

  1. Closing the XAML file and reopening
  2. Verified the Java SDK path locations are correct
  3. Clean and Rebuilding Solution

Im using Xamarin 4.5.0.486, Android SDK 7.3.1.2, Xamarin.iOS and Xamarin.Mac SDK 10.10, Visual Studio Community Version 2017

enter image description here

6
Are you using forms?Diego Rafael Souza
Yes. Im using the latest version.Kusal Dissanayake
It seems like the projects are not linked... Did you tried exclude the bin and obj folders, clean up the solution and rebuilt it all? I've some troubles using more then one instance of VS too.Diego Rafael Souza
Does your android project have a reference to your forms PCL?Joagwa
Anybody figure this out? Having this issue with VS 15.6.1adinas

6 Answers

6
votes

Check your android project and make sure the dll of your PCL/.net standard project is reference. In my own case, its referenced but shows a yellow color. I deleted the reference and re-reference by right clicking on the android project>projects>solution>select the PCL/.net standard project > ok

enter image description here

0
votes

just check if your project structure fits the file system/ folder structure.

rename the folders to fit the project structure helped in my case.

like if your Android Shared Project name is : "AppBla.Shared" and your folder name is "App4" or something.

0
votes

i think my solution is help this problem.

it has two problem, one is the solution path, the other one is dll reference.

I'll explain it with the example program Todo(example forum).

first, you have to clean your solution path like below png

png

secondly, you have to clean your all project (Todo, Todo.android, Todo.ios...)

then, you'll be able to see warning at Todo.dll(in Todo.android referense)

then, you have to delete Todo.dll

and build your Todo project then will create new dll

finally, Add it('new dll') to Todo.anroid project reference and include a Todo project in your Todo.android project(Todo.android reference add-> project -> check Todo).

check Todo

and restart visual studio

result

0
votes

None of the suggestions here worked for me. Upgrading to VS 2019 solved it.

0
votes

This solved my problem.

  1. Right Click on the project
  2. Click on Manage NuGet Packages
  3. Click on the Update Tab
  4. Select Xamarin.Forms and hit update

Update Xamarin.Forms NuGet Package

-1
votes

This problem can occur for a number of issues. Main problem is that for some reason Android's project can't build or be run inside Xamarin.

For me, the issue was that the latest JDK was not installed. My JRE was, but not JDK. Once I reinstalled JDK and restarted Visual Studio. All was well.