C# 没有 System.Runtime.Caching 可用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13615407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:11:29  来源:igfitidea点击:

No System.Runtime.Caching available?

c#.netvisual-studio-2012

提问by Fred

output type of 'Class Library', and a target framework of '.NET Framework 4'.

“类库”的输出类型,以及“.NET Framework 4”的目标框架。

According to everything I've read, I should have it available, but all I'm seeing in the System.Runtime namespace is the following:

根据我读过的所有内容,我应该可以使用它,但是我在 System.Runtime 命名空间中看到的所有内容如下:

CompilerServices
ConstrainedExecution
ExceptionServices
Hosting
InteropServices
Remoting
Serialization
Versioning

Any ideas?

有任何想法吗?

采纳答案by Jon Skeet

You just need to add a reference to the System.Runtime.Cachingassembly.

您只需要添加对System.Runtime.Caching程序集的引用。

  1. In solution explorer, right-click on "References"
  2. Select "Add reference"
  3. From left side menu select "Assemblies"
  4. Look for (or filter) and add System.Runtime.Caching.dll.
  1. 在解决方案资源管理器中,右键单击“参考”
  2. 选择“添加参考”
  3. 从左侧菜单中选择“程序集”
  4. 查找(或过滤)并添加System.Runtime.Caching.dll.

It's not part of the default set of references in a class library, but you should be able to add it with no problems.

它不是类库中默认引用集的一部分,但您应该能够毫无问题地添加它。

回答by tmesser

Reference System.Runtime.Caching.dll. This is another one of those rather obtuse gotchas in the .NET framework right now where there will be very similar namespaces in some things, but the actual classes you want will be referenced in different assembles. As an example, CacheItemis in this alternate DLL, whereas ApplicationActivator(in System.Runtime.Hosting) is in mscorlib.

参考System.Runtime.Caching.dll。这是 .NET 框架中的另一个相当迟钝的问题,其中在某些方面会有非常相似的命名空间,但您想要的实际类将在不同的汇编中引用。例如,CacheItem在这个备用 DLL 中,而ApplicationActivator(在 System.Runtime.Hosting 中)在 mscorlib 中。

回答by Irf

To complement Jon Skeets answer, (for those who run into this problem), if you stillget red squiggly lines under Cachingafter having added reference to System.Runtime.Cachingassembly, just restart the Visual Studio, after having saved the solution, and you should be good to go.

为了补充 Jon Skeets 的回答,(对于那些遇到这个问题的人),如果在添加对程序集的引用后仍然看到红色波浪线,只需在保存解决方案后重新启动 Visual Studio,你就可以开始了.CachingSystem.Runtime.Caching

Visual Studio red squiggly lines

Visual Studio 红色波浪线

Having added the reference, saved the solutionand ( if need may be) restartedVisual Studio, you should be able to usethe typeswithin this namespace. In order to get my solution to work, I had to do this very way.

已经添加了引用保存解决方案和(如果需要可重新启动Visual Studio中,你应该能够使用types范围内本namespace。为了让我的解决方案发挥作用,我不得不这样做。

Edit:

编辑:

While trying to recreate the problem, and solving this way, it seems that we need to set Copy Localto Truein System.Runtime.Caching> Propertiesand thenrestart Visual Studio for getting it to work. At least, for my case, the problem didn't seem to solve without this. ;)

虽然试图重现问题,解决这样一来,我们似乎需要设置Copy LocalTrueSystem.Runtime.Caching>Properties然后重新启动Visual Studio它自己动手。至少,就我而言,没有这个问题似乎无法解决。;)

enter image description here

在此处输入图片说明