0

I am trying to write some pretty basic MVC Controller code to read in a file in a direcory located in a wwwroot sub folder.

When I add this code to my controller:

String path = HttpContext.Current.Server.MapPath("~/Data/data.html");

VS tells me that HttpContext is available in "Microsoft.AspNet.Http.Abstractions": "1.0.0-beta5-11495" so using Visual Studio's quick helper I choose the option to add it to the project.json file. It also adds this using statement to my controller class.

using Microsoft.AspNet.Http;

Then all heck breaks out because while HttpContext resolves the 'Current' property does not. Furthermore, adding that package breaks the Startup.cs code because the IApplicationBuild parameter in the Configure method cannot be resolved because VS says:

The type 'IApplicationBuilder' exists in both 
'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'   
VS_MVCWebApp.DNX 4.5.1

Maybe I am not doing this right at all using the new dnx framework and if that is the case what is the correct approach?

At the end of the day I would like to just read in a file in my controller using 1.0.0-beta4 of he dnx451 framework.

Thanks for any help you can provide.

ChiliYago
  • 11,341
  • 23
  • 79
  • 126
  • David Fowler often says "Don't cross the streams!" Don't include beta5 and beta4 in the same projects. All of us working with the betas have done it at one point, though... – Matt DeKrey May 29 '15 at 02:38

1 Answers1

0

Check your packages versions. I just manage to fix this error by changing all my .NET nuget packages in question to "1.0.0-*". Make sure to do the same for the class libraries project if you have some.

For example in my situation I have a 'business' class library which is using Microsoft.AspNet.Http and my Test class library which is using the same, so just make sure that they both have the version of "1.0.0-*"

Update: Please ignore the previous comment because that would reference only the latest available package which obviously could create a lot of problems!

I managed to fix this by referencing the same package in all the projects in my solution. Also make sure that when you reference a project in your MVC project and that project is using Microsoft.AspNet.Http (for example it contains a middleware), make sure that this project is referencing Microsoft.AspNet.MVC instead of Microsoft.ASPNET.Http.

This created a problem for me also running my xunit tests. Check this question for more info xUnit.net v2 not discovering .NET Core Tests in Visual Studio 2015

Community
  • 1
  • 1
Sul Aga
  • 6,142
  • 5
  • 25
  • 37