Brent Arias
Brent Arias

Reputation: 30155

How to Access AsyncLocal

The classic .net CallContext was replaced with AsyncLocal in .NET 4.6...and is available in ASP.NET Core. I notice that the latest version of SimpleInjector is using it.

However, I am unable to use it in my dnx451 ASP.NET Core project.

I can make the following two declarations:

using System.Threading;
using System.Threading.Tasks;
...
static ThreadLocal<string> foo = new ThreadLocal<string>();
static AsyncLocal<string> tenant = new AsyncLocal<string>();

The first one is fine, but the second one is not properly defined, as shown by this message:

AspAsyncLocal.DNX 4.5.1 - Not Available
AspAsyncLocal.DNX Core 5.0 - Available

What am I missing? My project.json has the following dependencies:

"dependencies": {
  "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
  "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
  "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
},

"frameworks": {
  "dnx451": {
    "dependencies": {
      "System.Threading": "4.0.11-beta-23516"
    }
  },
  "dnxcore50": { }
},

Upvotes: 1

Views: 614

Answers (1)

Pawel
Pawel

Reputation: 31610

Try using dnx46 instead of dnx451.

Upvotes: 1

Related Questions