简体   繁体   English

获取“类型'SpatialReference' 是在未引用的程序集中定义的。” 仅当优化代码未选中时

[英]Getting "The type 'SpatialReference' is defined in an assembly that is not referenced." ONLY when optimize code is unchecked

I'm getting a weird compilation error and I'm just utterly baffled by it.我收到一个奇怪的编译错误,我完全被它弄糊涂了。

When I compile my project, I get this:当我编译我的项目时,我得到这个:

The type 'SpatialReference' is defined in an assembly that is not referenced.类型“SpatialReference”是在未引用的程序集中定义的。 You must add a reference to assembly 'Esri.ArcGISRuntime, Version=10.2.7.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'.您必须添加对程序集“Esri.ArcGISRuntime, Version=10.2.7.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86”的引用。

That's not the weird part though.不过,这不是奇怪的部分。 I only get this when I have "Optimize Code" unchecked in the C# project settings for the application.当我在应用程序的 C# 项目设置中取消选中“优化代码”时,我才会得到这个。

When I check the "Optimize Code" checkbox, it compiles just fine, and the application runs as expected.当我选中“优化代码”复选框时,它编译得很好,并且应用程序按预期运行。

The type 'SpatialReference' is not being used in the application at all, and that particular type is wrapped up in another assembly referenced by the application, and as far as I can see the type is not leaking out from the wrapper code.应用程序中根本没有使用类型“SpatialReference”,该特定类型被包装在应用程序引用的另一个程序集中,据我所知,该类型没有从包装器代码中泄漏出来。

Other applications that use this same wrapper assembly will compile with no issues, regardless of the Optimize Code state, and the wrapper assembly has been in use for almost 5 years without issue.无论优化代码状态如何,使用相同包装器程序集的其他应用程序都可以毫无问题地编译,并且包装器程序集已使用近 5 年没有问题。

Has anyone else ran into this problem?有没有其他人遇到过这个问题? If so, how'd you fix it?如果是这样,你是怎么解决的?

Just for reference, these applications are WinForms applications.仅供参考,这些应用程序是 WinForms 应用程序。 And I'm using Visual Studio 2019 Enterprise, v16.8.1我使用的是 Visual Studio 2019 Enterprise, v16.8.1

Update 2020-11-22更新 2020-11-22

After uninstalling 16.8 from our build machine (which was affected by this) and putting 16.7.7 back on, it compiles just fine.从我们的构建机器(受此影响)卸载 16.8 并重新安装 16.7.7 后,它编译得很好。 This is starting to look like a problem with v16.8.x.这开始看起来像是 v16.8.x 的问题。

I should note the following:我应该注意以下几点:

  • The projects are windows forms applications running under .NET 4.7.2这些项目是在 .NET 4.7.2 下运行的 windows 窗体应用程序
  • My personal work machine with 16.8 fails to build, the build machine for our CI with 16.8 fails, but my coworker's machine with 16.7.7 works.我的 16.8 个人工作机器无法构建,我们 16.8 的 CI 构建机器失败,但我同事的 16.7.7 机器可以工作。
  • This only affects 1 project out of 10 projects, all of which use the same wrapper API and the same functionality, and no changes have been made to the wrapper in ages.这仅影响 10 个项目中的 1 个项目,所有这些项目都使用相同的包装器 API 和相同的功能,并且多年来没有对包装器进行任何更改。 Why it fails with just one and not the others is unknown.为什么它只有一个而不是其他的失败是未知的。

I've been through the csproj file (using a text editor) for the failing project with a fine tooth comb and I have not seen anything out of the ordinary.我已经使用细齿梳浏览了失败项目的 csproj 文件(使用文本编辑器),但我没有看到任何不寻常的东西。

Please firstly try to clear the NuGet cache and then reinstall NuGet packages, if you installed some NuGet packages for example Esri.ArcGISRuntime .如果您安装了一些 NuGet 包,例如Esri.ArcGISRuntime ,请先尝试清除 NuGet 缓存,然后重新安装 NuGet 包。

For clearing NuGet cache, please go to Tools > Options > NuGet Package Manager > General > Package Restore > select “Allow NuGet to download missing packages” and “Automatically check for missing packages during build in Visual Studio” > then click Clear All NuGet Cache(s) button.要清除 NuGet 缓存,请转到“工具”>“选项”>“NuGet 包管理器”>“常规”>“包还原”> 选择“允许 NuGet 下载丢失的包”和“在 Visual Studio 中构建期间自动检查丢失的包”> 然后单击“ Clear All NuGet Cache(s)按钮。

For reinstalling NuGet packages, please go to Tools > NuGet Package Manager > Package Manager Console > in Package Manager Console enter Update-Package -reinstall to reinstall the NuGet packages.要重新安装 NuGet 包,请转到“工具”>“NuGet 包管理器”>“包管理器控制台”> 在包管理器控制台中输入Update-Package -reinstall以重新安装 NuGet 包。

After that, please restart VS and rebuild your project, check if this issue disappears.之后,请重新启动 VS 并重建您的项目,检查此问题是否消失。 If this issue still persists, please try following steps to troubleshoot:如果此问题仍然存在,请尝试按照以下步骤进行故障排除:

1). 1)。 Please close every VS instances and go to your solution folder, then rename(or delete) the hidden .vs , bin and obj folders, after that launch VS and rebuild your solution.请关闭每个 VS 实例并转到您的解决方案文件夹,然后重命名(或删除)隐藏的.vsbinobj文件夹,然后启动 VS 并重建您的解决方案。

2). 2)。 Please go to this path: C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\VisualStudio\\16.0_XXXX and rename(or delete) every folders named “ComponentModelCache”.请转到此路径: C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\VisualStudio\\16.0_XXXX并重命名(或删除)每个名为“ComponentModelCache”的文件夹。

3). 3)。 Please disable any third-party extensions temporarily from Extensions > Manage Extensions > Installed > Disable and test again.请从“扩展”>“管理扩展”>“已安装”>“禁用”中暂时禁用任何第三方扩展,然后再次测试。

4). 4)。 Please kindly try to repair Visual Studio 2019 from Visual Studio Installer > VS 2019 > More > Repair.请尝试从 Visual Studio Installer > VS 2019 > More > Repair 修复 Visual Studio 2019。

暂无
暂无

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

相关问题 类型“ IReportServerCredentials”在未引用的程序集中定义。 - type 'IReportServerCredentials' is defined in an assembly that is not referenced. 类型&#39;IAsyncOperationWithProgress &lt;,&gt;&#39;在未引用的程序集中定义。 - The type 'IAsyncOperationWithProgress<,>' is defined in an assembly that is not referenced. 为什么我得到:“IThirdParty”类型是在未引用的程序集中定义的。 您必须添加对程序集“ThirdPartyAssembly”的引用吗? - Why am I getting: The type 'IThirdParty' is defined in an assembly that is not referenced. You must add a reference to assembly 'ThirdPartyAssembly'? 类型“ DbConnection”在未引用的程序集中定义。 我无法添加参考? - The type 'DbConnection' is defined in an assembly that is not referenced. I cannot add the reference? “IEnumerable &lt;&gt;”类型在未引用的程序集中定义。 System.Runtime - The type 'IEnumerable<>' is defined in an assembly that is not referenced. System.Runtime 在未引用的程序集中定义类型“ x”。 VS 2010 C# - The type “x” is defined in an assembly that is not referenced. VS 2010 C# “组件”类型是在未引用的程序集中定义的。 您必须添加对程序集“System.ComponentModel.Primitives”的引用 - The type 'Component' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.Primitives' “MarshalByRefObject”类型是在未引用的程序集中定义的。 您必须添加对程序集 &#39;mscorlib, Version=4.0.0.0 的引用 - The type 'MarshalByRefObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0 类型“ System.Data.Common.DbTransaction”在未引用的程序集中定义。 您必须添加对程序集的引用 - The type 'System.Data.Common.DbTransaction' is defined in an assembly that is not referenced. You must add a reference to assembly 该类型在未引用的程序集中定义。 c#,通用存储库模式,URF - The type is defined in an assembly that is not referenced. c#, Generic Repository Pattern, URF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM