16

Today I created a new empty vnext web project and started to follow this guide: http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6

When I try to add:

using Microsoft.Framework.DependencyInjection;

and

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

I get an error saying:

The type 'IServiceCollection' exists in both 'Microsoft.Framework.DependencyInjection.IServiceCollection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Microsoft.Framework.DependencyInjection.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

I have been trying different betas of aspnet.mvc and I removed the aspnetcore50 from project.json (as it have solved problems before for me). I also tried to specify the namespace to use but it did not solve anything. Now I am out of ideas on how to solve this.

My project.json

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
    "wwwroot"
],
"packExclude": [
    "node_modules",
    "bower_components",
    "**.kproj",
    "**.user",
    "**.vspscc"
],
"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta4-12857"
},
"frameworks" : {
    "aspnet50" : { }
}
}

Have anyone got the same error and solved it?

3
  • Updated the visual studio to the newest release and now it works for some reason Feb 24, 2015 at 14:46
  • How did you explicitly update VS? I think I have latest VS and still have this problem.
    – ryan1234
    Feb 26, 2015 at 19:51
  • I downloaded VS from go.microsoft.com/fwlink/?LinkId=521794 and did not change any settings while installing Feb 27, 2015 at 9:17

5 Answers 5

1

Why not use explicit reference public void ConfigureServices(Microsoft.Framework.DependencyInjection.IServiceCollection services)

Or Alternatively You may need to use aliases like this

using DI = Microsoft.Framework.DependencyInjection;

then

public void ConfigureServices(DI.IServiceCollection services)
{
    services.AddMvc();
}
0

This error is generally caused by a conflict of two references in the project.json pointing to two different versions. Because of dependencies you can get two references to two different versions of the DependencyInjection library. So it could be a -beta3 and -beta4 mismatch, or something like that. Even if the two libraries are not the same thing, it can cause the problem.

0

You need to update to the latest versions of you nuget packages as explained here. Most of them are in pre-release, you might need need to add https://www.myget.org/F/aspnetvnext/api/v2/ as part of your nuget packages to get nightly builds

0

On your dependencies in project.json you use Microsoft.AspNet.Server.IIS beta2 and Microsoft.AspNet.Mvc beta4. You can't do this. You have ot use the same beta version for all your mvc6 dependencies.

Fix this and then you have to update Microsoft ASP.NET and Web Tools to match the beta you are using in your project (beta4).

0

the problem happened after i upgraded to Visual Studio 2015 CTP 6. This error only exists in my project created in previous version. i have a quick check just now and when i change the following inside project.json from "Microsoft.AspNet.Server.IIS": "1.0.0-beta2" to "Microsoft.AspNet.Server.IIS": "1.0.0-beta3", and now my error gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.