Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No System.Runtime.Caching available?

output type of 'Class Library', and a target framework of '.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:

CompilerServices ConstrainedExecution ExceptionServices Hosting InteropServices Remoting Serialization Versioning 

Any ideas?

like image 792
Fred Avatar asked Nov 28 '12 22:11

Fred


People also ask

What is a runtime cache?

Runtime caching refers to gradually adding responses to a cache "as you go". While runtime caching doesn't help with the reliability of the current request, it can help make future requests for the same URL more reliable.

What is memory cache in C#?

In-Memory Cache is used for when you want to implement cache in a single process. When the process dies, the cache dies with it. If you're running the same process on several servers, you will have a separate cache for each server. Persistent in-process Cache is when you back up your cache outside of process memory.


2 Answers

You just need to add a reference to the System.Runtime.Caching assembly.

  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.

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.

like image 114
Jon Skeet Avatar answered Oct 05 '22 23:10

Jon Skeet


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

Visual Studio red squiggly lines

Having added the reference, saved the solution and ( if need may be ) restarted Visual Studio, you should be able to use the types within this namespace. In order to get my solution to work, I had to do this very way.

Edit:

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

enter image description here

like image 45
Irf Avatar answered Oct 05 '22 23:10

Irf