Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous reference intellisense error from Resource.Designer.cs

I am running into a peculiar bug when developing on Visual Studio 2017 that I have been able to ignore for a while, but is now beginning to really bug me.

I refer to this issue as a bug rather than an error because I am still able to build my projects in Visual Studio and deploy them to my development device without errors or warnings from the build output. This might seem alright to ignore for a bit, but over time it has become an issue because my intellisense is underlining it in red as an error

a

every time I reference attributes from the Resource class. As you might guess, I refer this class a lot and the Visual Studio editor eventually becomes cluttered with these "errors" which (a) hinders my ability to find actual errors in my code and (b) irritates me beyond all reason...

"Error" Investigation

  • As shown in the last image, intellisense is picking up an "Ambiguous Reference" to each attribute in the Resource class. When I check my Resource.Designer.cs file I only see one reference, but get a second error

b.

  • It is now telling me that that a "Member with the same name is already declared". This lead me to believe that there is a second Resource.Designer.cs file, but my solution explorer and windows explorer both show only one.

c

Attempted solutions

  • Changed the namespace from InventoryApp (the default namespace of the file) to InventoryApp.Resources. This rid me of the ghastly errors but, upon building the project, it reverts the namespace in the file back to it's default, and the errors pop back up. I was also told by somebody who knows better that this is a big no-no.
  • Deleted the Resource.Designer.cs file, deleted the "obj" and "bin" folders from the project, cleaned and rebuilt the solution, then added the new Resource.Designer.cs file back to my solution. This did nothing to solve the problem.
  • Created an entirely new project from scratch. Even after creating a Blank Android App from the Visual Studio templates, the error persists. This begs the question: Is this a problem with my installation of Xamarin.Android?

Side-notes

  • The Resource.Designer.cs file's Build Action is set to "Compile"
  • The .csproj config file contains the tags:

    <AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
    <AndroidResgenClass>Resource</AndroidResgenClass>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
    <TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
    
like image 477
ding Avatar asked May 29 '18 22:05

ding


1 Answers

6/6/2018 Update

If you have ReSharper, you most likely will be able to disregard my per-project solution described below and, instead, simply install the latest version (currently ReSharper 2018.1.2). Apparently, the underlying issue was caused by a bug in a previous version. Upgrading resolved the issue for me.

See youtrack.jetbrains.com/issue/RSRP-469636 for more information.

Thanks to @davidbauduin over at Xamarin Forums for this information.


I believe I have figured out the underlying issue and have a viable solution.

Solution

Add the following to the <PropertyGroup> section in your .csproj file:

<AndroidUseManagedDesignTimeResourceGenerator>False</AndroidUseManagedDesignTimeResourceGenerator>

Reason

While previous versions of Visual Studio had that feature turned off by default, the latest VS2017 update (15.7.3) has it turned on. That feature generates a second Resources.Designer.cs file that results in the ambiguous reference issue.

You can verify by hovering over the resource constant with the Intellisense error, right-clicking, selecting "Go To Definition", and selecting the 1st item, which takes you to a Resource.Designer.cs file. If you repeat, but select the 2nd one, you'll be taken to a different Resource.Designer.cs file. One of these points to the obj\Debug\designtime\Resource.Designer.cs file. By setting that feature to False as described above, that Resource.Designer.cs file in the obj\Debug\designtime path will not be generated.

Information Regarding the AndroidUseManagedDesignTimeResourceGenerator Feature:

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#design-time-builds-managed-resource-parser

https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#design-time-builds

Hope this helps!

like image 57
Robert Bruce Avatar answered Nov 05 '22 20:11

Robert Bruce