I am using VS2015 with Resharper for WebAPI 2.0 project. Trying to use System.Net.Http.HttpRequestMessageExtensions.GetRequestContext gives me an error saying
Error CS0433 The type 'HttpRequestMessageExtensions' exists in both 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I've tried editing web.config to read
<compilation debug="true" targetFramework="4.5.1" batch="false" />
Also as suggested in numerous posts - restarted visual studio, clear resharper cache, rebuild the solution.
Nothing helps and I am still seeing this error. Any other suggestions?
You need to use a “extern alias” to manage two classes with the same namespace.
First, define de name of your custom alias in the properties of the assembly:
Then, in the code:
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
extern alias Alias1;
extern alias Alias2;
using namespace1 = Alias1::System.Net.Http.HttpRequestMessageExtensions;
using namespace2 = Alias2::System.Net.Http.HttpRequestMessageExtensions;
public class HomeController : Controller
{
public void Test()
{
// ...
namespace1.GetRequestContext(request);
//namespace2.GetRequestContext(request); // error
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With