Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

c# - 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>ResourcesResource.Designer.cs</AndroidResgenFile>
    <AndroidResgenClass>Resource</AndroidResgenClass>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
    <TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
    <AndroidManifest>PropertiesAndroidManifest.xml</AndroidManifest>
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
    
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 objDebugdesigntimeResource.Designer.cs file. By setting that feature to False as described above, that Resource.Designer.cs file in the objDebugdesigntime 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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...