简体   繁体   English

Resource.Designer.cs中的模糊引用智能感知错误

[英]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. 我在Visual Studio 2017上开发时遇到了一个奇怪的错误,我已经能够忽略一段时间,但现在开始真的我感到烦恼

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. 我将此问题称为错误而不是错误,因为我仍然可以在Visual Studio中构建我的项目并将它们部署到我的开发设备,而不会出现构建输出中的错误或警告。 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 这似乎可以忽略一点,但随着时间的推移它已经成为一个问题,因为我的intellisense用红色强调它作为一个错误

一个

every time I reference attributes from the Resource class. 每次我引用Resource类的属性。 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... 正如你可能猜到的那样,我引用了很多这个类,Visual Studio编辑器最终变得混乱了这些“错误”,它们(a)阻碍了我在代码中发现实际错误的能力,并且(b)让我无法理解......

"Error" Investigation “错误”调查

  • As shown in the last image, intellisense is picking up an "Ambiguous Reference" to each attribute in the Resource class. 如上图所示,intellisense正在为Resource类中的每个属性选择一个“不明确的引用” When I check my Resource.Designer.cs file I only see one reference, but get a second error 当我检查我的Resource.Designer.cs文件时,我只看到一个引用,但得到第二个错误

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. 这让我相信有第二个Resource.Designer.cs文件,但我的解决方案资源管理器和Windows资源管理器都只显示一个。

C

Attempted solutions 试图解决方案

  • Changed the namespace from InventoryApp (the default namespace of the file) to InventoryApp.Resources . 将命名空间从InventoryApp (文件的默认命名空间)更改为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. 删除了Resource.Designer.cs文件,从项目中删除了“obj”和“bin”文件夹,清理并重建了解决方案,然后将新的Resource.Designer.cs文件添加回我的解决方案。 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. 即使在从Visual Studio模板创建空白Android应用程序后,错误仍然存​​在。 This begs the question: Is this a problem with my installation of Xamarin.Android? 这引出了一个问题: 这是我安装Xamarin.Android的问题吗?

Side-notes 侧面笔记

  • The Resource.Designer.cs file's Build Action is set to "Compile" Resource.Designer.cs文件的Build Action设置为“Compile”
  • The .csproj config file contains the tags: .csproj配置文件包含标记:

     <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> 

6/6/2018 Update 6/6/2018更新

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). 如果你有ReSharper,你很可能会忽略我下面描述的每个项目解决方案,而只需安装最新版本(目前是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. 有关更多信息,请参阅youtrack.jetbrains.com/issue/RSRP-469636

Thanks to @davidbauduin over at Xamarin Forums for this information. 感谢@davidbauduin在Xamarin论坛上获取此信息。


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: 将以下内容添加到.csproj文件中的<PropertyGroup>部分:

<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. 虽然以前版本的Visual Studio默认关闭了该功能,但最新的VS2017更新(15.7.3)已打开。 That feature generates a second Resources.Designer.cs file that results in the ambiguous reference issue. 该功能会生成第二个Resources.Designer.cs文件,导致模糊的引用问题。

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. 您可以通过将智能感知错误悬停在资源常量上进行验证,右键单击,选择“转到定义”,然后选择第一个项目,该项目将转到Resource.Designer.cs文件。 If you repeat, but select the 2nd one, you'll be taken to a different Resource.Designer.cs file. 如果您重复,但选择第二个,您将被带到另一个Resource.Designer.cs文件。 One of these points to the obj\\Debug\\designtime\\Resource.Designer.cs file. 其中一个指向obj \\ Debug \\ designtime \\ Resource.Designer.cs文件。 By setting that feature to False as described above, that Resource.Designer.cs file in the obj\\Debug\\designtime path will not be generated. 通过如上所述将该功能设置为False,将不会生成obj \\ Debug \\ designtime路径中的Resource.Designer.cs文件。

Information Regarding the AndroidUseManagedDesignTimeResourceGenerator Feature: 有关AndroidUseManagedDesignTimeResourceGenerator功能的信息:

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#design-time-builds-managed-resource-parser 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 https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#design-time-builds

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM