Win8/Metro app issue

Topics: Web Api
Jan 23, 2012 at 9:38 PM

I am trying to use the .6 webapi in a C# metro app. I am able to add the references in a console app, but I can't get it to work in a Metro/Xaml app. I can add Microsoft.Net.Http.Formatting, but when I add System.net.http, it conficts with the System.net.http dll in the GAC I think.

var resp = httpClient.GetAsync("").Result;
Person person = resp.Content.ReadAsAsync<Person>().Result;

Has anone been able to do these simple two lines of code in a Win8/Metro/Xaml app?

Jan 23, 2012 at 9:44 PM

If you don't want to use the one in the gac then remove its reference first.

Remember the assemblies in the GAC aren't in your project unless you include them.

It only makes it so it doesn't have to copy them to your BIN to use them.

Try removing the System.Net.Http reference, then adding it from wherever you are adding it from.

Also I would suggest using NUGET to install WebApi instead of doing it manually.

Jan 23, 2012 at 9:55 PM

digital thanks for your reply.

I use nuget to get the package, but I am on my 100'th project trying to get webclient working with Win8/Metro xaml.

Do you have any experience in this are?  In my post I mentioned that I can perform these steps in a console app, everything changes when you get to Window 8 and a Metro Xaml application.

When you add System.net.http, nothing happens, I guess because it is in the gac already. 

Jan 23, 2012 at 10:10 PM
Edited Jan 23, 2012 at 10:11 PM

Well when you are adding a reference, if you add it from the ".net tab" then it adds a reference from the GAC.
That's where those assemblies come from.
If you are adding a manual reference to it then you have to use the browse tab when adding a reference, this will not add it from the GAC.

But no, I have not had any experience with using metro apps, but I don't see how this would be related because WebApi has nothing to do with the project type.
The only time the project type matters is the hosting environment for how you end up planning to actually host it, whether using MVC routing for easy startup, a service host, or console startup.

 You can also set "copy local" to true. This will copy it to your bin on compile. Then you can override it if you have your own assembly and it won't pull from GAC.

I do not have a System.Net.Http in my GAC.
Did you install it into your GAC, or does System.Net.Http come with the preview for Win8 development? 
I can't find anything official about it.

Since this is the MS team, maybe the assembly is the same?
Do you actually have an issue using the one from the Win8 preview?

I would suggest removing System.Net.Http, download the DLLs for WebApi, and add System.Net.Http via browse.

That's all I got :P Sorry man, GL

Jan 23, 2012 at 10:28 PM

hey digital, thanks for you thoughts.

I am adding it via browse, but it does not appear in the refrences section of the project.

>>Do you actually have an issue using the one from the Win8 preview?

.6 has the async methods, async is required for all metro apps, so I need to use the new .6 version.

>>but I don't see how this would be related because WebApi has nothing to do with the project type.
In a console app, you can't add the system.net.http dll to the project, but if you change it's project type from .net 4.5 client profile, to .net 4.5 you can add it.

In a Metro app, you can't change the project type, so nothing happens when you try and add the dll.

>>I would suggest removing System.Net.Http, download the DLLs for WebApi, and add System.Net.Http via browse.

That is what I am doing.

Thanks for anymore ideas or suggestions you might have.