IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http

We are trying to authenticate with ASP.NET 5. In this security example, we see this type of thing:

app.Run(async context =>
{    
    var types = context.Authentication.GetAuthenticationSchemes();
}

      

Initial task

However, our project HttpContext

did not have a property Authentication

and we would receive the following error:

Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException: C: \ myApp \ Startup.cs (71,46): Error CS1061:

"HttpContext" does not contain a definition for "Authentication", and the "Authentication" extension method cannot be found that takes a first argument of type "HttpContext" (are you missing a using directive or an assembly reference?)

So we looked at the source and found what 's inside the assembly hereHttpAbstractions

. So, we added this assembly to our project.

Subsequent problem

Unfortunately, we now receive the following error:

Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException: C: \ myApp \ Startup.cs (43,31): Error CS0433:

The type "IApplicationBuilder" exists as in "Microsoft.AspNet.Http.Abstractions, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null" and "Microsoft.AspNet.Http, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null '

Question

Fair enough. How can we ask the compiler to use one assembly but not another for this particular type? We tried to delete .dnx\packages\Microsoft.AspNet.Http

, but it only comes back after dnu restore

.

+3


source to share


2 answers


You've probably "crossed the streams" as the ASP.NET teams say. Make sure you are after breaking the changes and don't include packages from multiple versions beta

(make sure you don't have both, beta4

and beta5

for example the easiest way to check is to search your project .lock.json for them.) The most common accidents involve using packages .Interfaces

as most of them have been renamed to .Abstractions

, but there have been other assembly naming changes (and deletions too!).

Update:



This error can also occur if you are unable to communicate with NuGet packages through the servers you configured and for the version dnvm

you are using. (There was an update recently to dnvm

which I had to update to use the latest packages, it seems that even within the same beta number, streams can still overlap!) To get VS2015 to use a specific dnvm

a global.json

might require:

{
    "projects": [ "src", "tests" ],
    "sdk": {
        "version": "1.0.0-beta6-12005"
    }
}

      

+3


source


Matt Dackrey was right. I didn't have to cross streams. In short, I needed beta6

and was on beta4

. Here are the steps to fix:

1 Modify project.json

Now it looks like

  "dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta6",
    "Microsoft.AspNet.Mvc": "6.0.0-beta6",
    "EntityFramework.SqlServer": "7.0.0-beta6",
    "EntityFramework.InMemory": "7.0.0-beta6",
    "Microsoft.AspNet.Identity": "3.0.0-beta6"
  }

      



2 Add Nuget.config

It is important to note that I need to add the Nuget.config file to the root of my repository because it beta6

is not included in NuGet yet.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2" />
    <add key="NuGet" value="https://nuget.org/api/v2/" />
  </packageSources>
</configuration>

      

The entry AspNetVNext

is what Default Unstable

we see at startup dnvm

.

+1


source







All Articles