Search code examples
visual-studio-2012monoxamarinmvvmcrossportable-class-library

Reference to System.net on PCL and MVVMCross


I'm builind my PCL Core library using MVVMCross and Mono with VisualStudio 2012 and Stable version of Xamarin. I have following compile error.

Error 3 'System.Net.WebHeaderCollection' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Net.WebHeaderCollection' could be found (are you missing a using directive or an assembly reference?)

When try to do that:

string address = "http://www.test.com/;

            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;  
            request.Method = "GET";
            request.Accept = "application/json";
            request.Headers.Add(HttpRequestHeader.Cookie, "customcookie");

HttpWebRequest is well referenced.

N.B. Same code work in Xamarin Studio on Mac.


Solution

  • The PCL System.Net stack is portable - which means it isn't fully featured.

    For cookies in the PCL .Net stack I believe you can set the CookieCollection on a Request and that you can then inspect the Cookies on a Response

    If that's not sufficient for you, then you'll have to use some kind of 'injection' technique to implement the functionality you want on each platform - e.g. you could use plugins in mvvmcross


    I think one thing that you may be missing is that currently xamarin does not build PCLs correctly - this is about to change, but right now today xamarin builds PCLs against its full monotouch or monodroid stack. As a result, xamarin may report pcl functionality availability incorrectly - and PCLs built on xamarin are certainly not portable - see http://slodge.blogspot.co.uk/2013/01/almost-portable-binaries.html