Forum Xamarin Cross Platform with Xamarin

PCLs and Async

I'm working on a little demo project for a talk and I really want to use PCLs and async.

Originally I used the hack to add mono(touch|droid) to the list of PCLs, but I'm not totally sure what it's doing, and it didn't let me use the async anyway - plus I thought Xamarin had PCL support now, so I'm not sure I should have to do this.

Another suggestion I saw recommended manually modifying the mono* project file and adding the reference in notepad. This kind of worked, but it led to some strange issues: for example on android I can't use any linq (I can work around this), and on monotouch I'm getting the following (which I can't work around yet...)

Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the MonoTouch profile?

Whats is the current recommended way to get PCL working and still use Async?

Thanks

Ross

Posts

  • ChWoChWo DEMember

    This blogpost from @cheesebaron describes how to use PCLs, async/await and HTTPClient in Xamarin:
    http://blog.ostebaronen.dk/2013/07/working-with-pcls-in-lates.html

    You can use Xamarin's stable channel instead of the alpha channel which is referenced inside the blogpost.

  • RossDargan.0957RossDargan.0957 GBInsider, University ✭✭

    Thanks for the link. That is pretty much what I'm doing - yet I still have the issue with Linq under android.

    For iOS this solved the system.runtime issue, but now it can't find System.Resources.ResourceManager.dll - I can't see that package in any of the packages folder so I'm not sure where I should add it from?

  • RossDargan.0957RossDargan.0957 GBInsider, University ✭✭

    To summarise using the method described by @cheesebaron I have the following scenario:-
    Android: Linq can't be used in the PCL method (I'm using MVVM Cross, so this isn't ideal, but can be worked around) - everything else works fine
    iOS: refuses to build because it can't find System.Resources.ResourceManager.dll. The full error is below:-

    C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the MonoTouch profile? [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj]
    C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : File name: 'System.Resources.ResourceManager.dll' [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj]
    C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : at Xamarin.MonoTouch.Build.Tasks.Utilities.MonoTouchResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj]
    C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : at Xamarin.MonoTouch.Build.Tasks.ResolveAssemblies.AddAssemblyReferences(List1 assemblies, AssemblyDefinition assembly) [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj] C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : at Xamarin.MonoTouch.Build.Tasks.ResolveAssemblies.AddAssemblyReferences(List1 assemblies, AssemblyDefinition assembly) [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj]
    C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : at Xamarin.MonoTouch.Build.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1 assemblies, AssemblyDefinition assembly) [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj]
    C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.MonoTouch.Common.targets(68,3): error : at Xamarin.MonoTouch.Build.Tasks.ResolveAssemblies.Execute() [C:\Workspaces\Sandpit\Facts.Core\Facts.iOS\Facts.iOS.csproj]

    I don't know if this could be the problem, but with the mono* projects I can't add the nuget microsoft.bcl.build project - I'm getting build warnings about this so I don't know if thats what the problem is?

  • RossDargan.0957RossDargan.0957 GBInsider, University ✭✭

    For those more technically minded this is a bit more detail about the iOS issue:

    4> Unified Dependency "System.Runtime, Version=2.6.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:16)
    4> Using this version instead of original version "1.5.11.0" in "C:\Workspaces\Sandpit\Facts.Core\packages\Microsoft.Net.Http.2.2.15\lib\portable-net40+sl4+win8+wp71\System.Net.Http.dll" because of a binding redirect entry in the file "app.config". (TaskId:16)
    4> Could not resolve this reference. Could not locate the assembly "System.Runtime, Version=2.6.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. (TaskId:16)
    4> For SearchPath "C:\Workspaces\Sandpit\Facts.Core\packages\Microsoft.Net.Http.2.2.15\lib\portable-net40+sl4+win8+wp71". (TaskId:16)
    4> Considered "C:\Workspaces\Sandpit\Facts.Core\packages\Microsoft.Net.Http.2.2.15\lib\portable-net40+sl4+win8+wp71\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "C:\Workspaces\Sandpit\Facts.Core\packages\Microsoft.Net.Http.2.2.15\lib\portable-net40+sl4+win8+wp71\System.Runtime.dll", but it didn't exist. (TaskId:16)
    4> Considered "C:\Workspaces\Sandpit\Facts.Core\packages\Microsoft.Net.Http.2.2.15\lib\portable-net40+sl4+win8+wp71\System.Runtime.exe", but it didn't exist. (TaskId:16)
    4> For SearchPath "{TargetFrameworkDirectory}". (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v4.0\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v4.0\System.Runtime.dll", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v4.0\System.Runtime.exe", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v4.0\Facades\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v4.0\Facades\System.Runtime.dll", but its name "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" didn't match. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v4.0\Facades\System.Runtime.exe", but it didn't exist. (TaskId:16)
    4> For SearchPath "{AssemblyFolders}". (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Runtime.dll", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Runtime.exe", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\System.Runtime.dll", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\System.Runtime.exe", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\System.Runtime.dll", but it didn't exist. (TaskId:16)
    4> Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\System.Runtime.exe", but it didn't exist. (TaskId:16)
    4> For SearchPath "{GAC}". (TaskId:16)
    4> Considered "System.Runtime, Version=2.6.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", which was not found in the GAC. (TaskId:16)
    4> For SearchPath "bin\iPhoneSimulator\Debug\". (TaskId:16)
    4> Considered "bin\iPhoneSimulator\Debug\System.Runtime.winmd", but it didn't exist. (TaskId:16)
    4> Considered "bin\iPhoneSimulator\Debug\System.Runtime.dll", but it didn't exist. (TaskId:16)
    4> Considered "bin\iPhoneSimulator\Debug\System.Runtime.exe", but it didn't exist. (TaskId:16)

  • CheesebaronCheesebaron DKInsider, University mod

    I've only been using PCL's on WP8 and Droid because it has been broken on iOS for some time. Haven't tried with the latest release of Xamarin.iOS though. Xamarin is still working on getting stuff working as they should.

  • RossDargan.0957RossDargan.0957 GBInsider, University ✭✭

    In the end I stuck with the limitation that I can't use linq for android, and for iOS I have used the file linking method :-/ It works, but not ideal obviously!

  • GuillermoGutierrezGuillermoGutierrez ESMember ✭✭✭

    I'm using async/await, the new HttpClient, JSON, LINQ and all the candy in a PCL in both MonoTouch and MonoDroid using the latest Alpha versions. The only issue right now is that I have to add a reference to the PCL DLL instead of the PCL project from Android. Everything else works fine.

  • RossDargan.0957RossDargan.0957 GBInsider, University ✭✭

    Hi @GuillermoGutierrez - I've tried just adding a reference to the PCL DLL and I'm have the same issue with linq not working on monodroid (on both the latest alpha, and stable). How strange.

Sign In or Register to comment.