4

I am converting an existing .Net 4.5 MVC 5 project to a new ASP.NET 5 project. One of my files is referencing the System.Runtime.Caching namespace but on moving this file to the new project this namespace cannot be found.

I have added System.Runtime as a dependency in the new project, but the .Caching bit seems to be missing from this. Has anybody experienced a similar problem?

Andrew
  • 769
  • 7
  • 16

2 Answers2

3

You need to bring in 'Microsoft.Extensions.Caching.Memory' using the following line in your project JSON.

"dependencies": {
    "Microsoft.Extensions.Caching.Memory": "1.0.0"
  }

Current documentation can be found here.

https://docs.asp.net/en/latest/performance/caching/memory.html

CountZero
  • 6,171
  • 3
  • 46
  • 59
1

To use the System.Runtime.Caching namespace in an ASP.NET application, you must add a reference to the namespace.

To add a reference to the Website

  1. In Solution Explorer, right-click the name of the Web site and then click Add Reference.
  2. Select the .NET tab, select System.Runtime.Caching, and then click OK.

Ref: https://msdn.microsoft.com/en-us/library/ff477235(v=vs.110).aspx#Anchor_2

Aung Myo Linn
  • 2,820
  • 3
  • 27
  • 38
  • 1
    This fixed the problem. The root cause of the problem is related to the fact that System.Runtime is a package that can be downloaded whereas System.Runtime.Cache still needs to be referenced from the GAC. I was attempting to add System.Runtime.Caching under "dependencies" in the project.json file, it actually needs to be added under "frameworkAssemblies". Covered here: http://stackoverflow.com/questions/30747965/what-is-the-difference-between-dependencies-and-frameworkassemblies-in-proje – Andrew Jan 14 '16 at 17:10