System.Net and System.IO in Xamarin.Forms apps...

binkman71binkman71 USMember ✭✭

So, if I set up a "regular" Xamarin project with Android and iOS projects, and a shared PCL, in that PCL I can utilize System.Net and System.IO to do web requests and read data and whatnot. This same code, however, does not work in a Xamarin.Forms project.

When compiling, errors occur that methods are not found. For example:

" 'System.IO.Stream' does not contain a definition for 'BeginRead' and no extension method 'BeginRead' accepting a first argument of type 'System.IO.Stream' could be found (are you missing a using directive or an assembly reference?) "

Now, to repeat, this worked in a Xamarin project created manually without Forms, from within a PCL. But in the generated Forms project, in the PCL, I get these missing method errors. Microsoft documentation even states the missing methods are supported in PCL projects. So I don't know entirely what the problem is here. Any advice on how to proceed would be appreciated.

Posts

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    Can you post a sample project? Xamarin.Forms shouldn't affect PCL.

  • binkman71binkman71 USMember ✭✭

    In the project that "works", the PCL in visual studio is targetting .Net Framework 4.5, Silverlight 5, Windows 8, Windows Phone Silverlight 8, Xamarin.Android, and Xamarin.iOS. However, I noticed in the references section, the path differs to the .NET references than it does in the Xamarin created project:

    Xamarin.Forms project:
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile78\

    VisualStudio "standard" project:
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile136\

    I did some more digging. If I remove Silverlight 5 from my "working" project, it then fails for the same reasons. If I try to add Silverlight 5 to my Xamarin.Forms project, it fails to compile at all because it says:

    **The primary reference "Xamarin.Forms.Core" could not be resolved because it was built against the ".NETPortable,Version=v4.5,Profile=Profile259" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.0,Profile=Profile158". **

    So this is quite a fine mess. ;)

    Also, why adding Silverlight changes it to profile 158, and not 136 as it created the other project is beyond me. Nonetheless, still a different profile, and likely still a problem.

    I suppose I will have to rewrite code to work within the confines of this "profile" and use different methods...

Sign In or Register to comment.