I’ve seen a few people run into this issue in both Visual Studio 2015 and 2017. For those of you who don’t know what I’m talking about, the issue is that code highlighting drops completely in newly opened files. I’ve personally seen it happen in both Xamarin.Forms PCLs and in Xamarin.Android projects. The reason you lose your highlighting is because the project fails to load properly, and your files will then open as “Miscellaneous Files”:
These should be opening up as part of the project and thus getting the references required for highlighting, so the goal here is to fix the project load and get these files to open as part of that project.
So here are a few steps that have worked for everyone who has reached out for help:
- Don’t panic! This will be quick.
- Try unloading the project and reloading it (Right click the project in the Solution Explorer > Unload Project, Right click > Reload Project)
- Still happening when you open files in that project? Keep reading.
- Check your Error List, there might be warnings to give you hints here.
In this post, we will look at resolving the issue for Xamarin.Android projects. If you are looking for resolving issues in your Xamarin.Forms PCL projects look at this earlier post: Xamarin.Tips – Fixing the Highlighting Drop In Your Xamarin.Forms Projects
Xamarin.Android Project Issues
There are two common issues that are particular to Xamarin.Android projects that cause this.
Dependencies aren’t built
The first is a known bug in Xamarin projects (especially when first created). The problem is that it relies on it’s dependencies to load properly, however, if you have not built one or more of the projects that the Android project depends on, you will get this load error:
along with it’s partner:
However, you may have seen this and followed the steps listed without fixing anything or learning more about the issue:
1. Close Visual Studio
2. Open a Visual Studio Developer Command Prompt
3. Set environment variable “TraceDesignTime” to true (set TraceDesignTime=true)
4. Delete .vs directory/.suo file
5. Restart VS from the command prompt you set the environment variable (devenv)
6. Open the solution
A Corrupt or Broken Android Resource
This one can be elusive because it does not always throw errors or warnings, but is also quite common. The problem is that one of your Android resources has an error. This is likely in your layouts
or your values
folders.
THE SOLUTION:
1. Go through your error list for warnings about your Android resources
2. If you have any issues there, fix those problems and unload > reload the Android project.
3. If you do NOT see any items in your Error List, go through each of your layout and value files (like colors.xml
and styles.xml
) and search for errors. They are more likely to show warning squiggles in your editor.
4. Resolve all issues and unload > reload the Android project.
If none of these solutions fixed your problem, read below for more generic solutions for this issue.
Refresh Your Intellisense Cache
Your Intellisense cache could be corrupt, so try clearing it. Close all your open files then:
Edit > IntelliSense > Refresh Local Cache
Or Ctrl + Shift + R
Clearing Your Local Data
Close Visual Studio Completely, then go to %appdata%\Microsoft\VisualStudio{your_version_number}\ReflectedSchemas and delete all the content.
Reset your Visual Studio Settings
In Visual Studio, go to Tools > Import and Export Settings and hit Reset all settings.
Restart Visual Studio.
Fix All Errors and Warnings In the Error List
Similarly to how we talked about fixing your XAML error, try making sure all of your errors and warnings are fixed. Some other common issues that can cause the project to load with errors include:
- Circular References
- Missing project references
- Failed nuget downloads
- Duplicate files
- Broken/wrong typed partial classes
Still Not Working?
Leave a comment describing all the detail you can about the errors and warnings you are seeing and we can work together to fix your problems!
If you like what you see, don’t forget to follow me on twitter @Suave_Pirate, check out my GitHub, and subscribe to my blog to learn more mobile developer tips and tricks!
Interested in sponsoring developer content? Message @Suave_Pirate on twitter for details.
One thought on “Xamarin.Tips – Fixing the Highlighting Drop In Your Xamarin.Android Projects”