M Zeinstra
M Zeinstra

Reputation: 1981

Namespace is found in class, but not in aspx

I'm having trouble with the namespace System.Net.Http.

I want to use, e.g. HttpClient, from the namespace System.Net.Http. When I use using System.Net.Http; in a C# class, I can use HttpClient just fine, but when I try to import the namespace in an aspx file, like this: %@ Import Namespace="System.Net.Http" %> it won't regonize HttpClient:

The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)

I've already installed it like this and added it to my references by doing this.

How do I use, e.g. HttpClient, in my .aspx file like I use it in a C# class?

UPDATE

This is not a duplicate of Why should i include the namespace in each aspx page?, because I'm not asking how I'm supposed to include a namespace in every class.

Upvotes: 4

Views: 1435

Answers (1)

Mr. B
Mr. B

Reputation: 2985

First it is worth pointing out that you probably shouldn't do this. You should probably prepare the data you need in the Page_Load event and just display it on the WebForms page. If you still want to do it this way, I am pretty sure what is happening is that you have a dependent assembly other than System.Web.HttpClient. Have a look at your CodeBehind page and make sure all imports are there in the aspx page for every using in the CodeBehind. In other words:

System.Web.HttpClient depends on another assembly you are not referencing.

Upvotes: 2

Related Questions