locked
Using the Azure MobileServiceClient with Xamarin.Mac (missing assemblies) RRS feed

  • Question

  • User310157 posted

    Hi there, I made a post yesterday, but it disappeared after I edited it...

    Introduction

    I'm having trouble getting the MobileServiceClient working. If I download the sample AzureToDo.Mac app, open the project in Visual Studio and attempt to compile without changing anything, it throws an error during the building phase.

    The type 'System.IDisposable' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Full build log: http://pastebin.com/raw/WwD57wcL

    I can fix this by adding a few references. First: System.Runtime 4.1.1.0

    Then I get this error

    error CS0012: The type 'System.Threading.Tasks.Task'1' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    http://pastebin.com/raw/1Cgtx4xE

    If I then reference System.Threading.Tasks 2.6.10.0 it compiles and launches.

    Real problem

    So when I try to implement the MobileServiceClient in my own app which runs the Xamarin.Mac framework, I get a load of errors with this unpleasant build log: http://pastebin.com/raw/8vGHGhuE

    this: var results = await query.ToListAsync(); throws:

    /Users/frederiktheisen/Projects/GeneViewerMac/GeneViewerMac/CrossPlatformFiles/App_webservice.cs(43,43): Error CS0012: The type 'System.Collections.Generic.List'1' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (CS0012) (GeneViewerMac)

    this: var q = DataBaseRestrictionEnzymes.Where(o => o.OwnerID == CurrentUser.Id); throws:

    /Users/frederiktheisen/Projects/GeneViewerMac/GeneViewerMac/CrossPlatformFiles/App_webservice.cs(48,48): Error CS0012: The type 'System.Linq.Expressions.Expression'1>' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (CS0012) (GeneViewerMac)

    And a few more which are basically the same.

    Starting a new project and working one line at a time, I get all the way to using the .ToListAsync(); method which throws a build error requesting a "System.Collections.Generic.List`1" type. Log: http://pastebin.com/raw/V5M0FGze

    I can get past this error by referencing a System.Collections.dll I found in the AzureToDo.Mac sample, however it will throw a new error when launching. System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections' or one of its dependencies at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) [0x00081] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/src/mono/mcs/class/corlib/System/AppDomain.cs:746 at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/src/mono/mcs/class/corlib/System/AppDomain.cs:714 at at (wrapper remoting-invoke-with-check) System.AppDomain:Load (System.Reflection.AssemblyName) at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/src/mono/mcs/class/corlib/System.Reflection/Assembly.cs:596 at ObjCRuntime.Runtime.CollectReferencedAssemblies (System.Collections.Generic.List'1[T] assemblies, System.Reflection.Assembly assembly) [0x0001e] in /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:410

    I have no idea what I should do to make this work. I don't even know where to look.

    If anyone could help me with this I'd be very grateful.

    Thank you

    Regards Frederik

    Sunday, March 26, 2017 12:34 PM

Answers

  • User35201 posted

    For future reference, you can delete the packages, bin and obj directory to drastically reduce your sample size. Your sample with that done is 370KB, nearly 200x smaller.

    The first thing I noticed is that you are using the Mobile (Modern) target framework. You can read about it here: https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/

    when I tried to restore/add Microsoft.Azure.Mobile.Client.3.1.0 I got:

    Could not install package 'Microsoft.Bcl 1.1.10'. You are trying to install this package into a project that targets 'Xamarin.Mac,Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

    which unfortunately makes sense. Like iOS, Xamarin.Mac Mobile (Modern) requires library authors to create special builds if they aren't just netstandard compatible.

    Switching your target framework to XM 4.5 (Full) got me farther:

    /Users/donblas/Downloads/AzureTestApp18/AzureTestApp18/CSC: Error CS1703: An assembly System.ComponentModel.Primitives' with the same identity has already been imported. Consider removing one of the references (CS1703) (AzureTestApp18) /Users/donblas/Downloads/AzureTestApp18/AzureTestApp18/CSC: Error CS1703: An assemblySystem.ComponentModel.TypeConverter' with the same identity has already been imported. Consider removing one of the references (CS1703) (AzureTestApp18)

    This is a bug:

    https://bugzilla.xamarin.com/show_bug.cgi?id=54139

    There are two work arounds:

    • The easy one. Open your csproj in a text editor and remove the HintPath for System.ComponentModel.Primitives / System.ComponentModel.TypeConverter
    • The more correct future one - If you build your project with msbuild we handle these facades more correctly. You'll need to swap to Xamarin.Mac in the Alpha channel however.
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 28, 2017 4:03 PM
  • User35201 posted

    You will need to swap to XM 4.5 (Full) target framework. The library that you wish to use has not released anything compatible with Mobile (Modern) yet - https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/

    Then to work around the bug you need to either:

    • Open your csproj in a text editor
    • Find the reference section for System.ComponentModel.Primitives and System.ComponentModel.TypeConverter
    • Delete the inner HintPath tag

    OR

    • Xamarin Studio -> Check for Updates
    • Change the Update Channel dropdown to Alpha
    • Install
    • Xamarin Studio -> Preferences -> Projects -> Builds -> Check "Build with MSBuild instead of xbuild (EXPERIMENTAL)"

    The second is a global setting, which would affect any other projects you build, and might require restarting Xamarin Studio.

    The first is a bit of a hack, but significantly more isolated.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 28, 2017 6:51 PM

All replies

  • User35201 posted

    Could you post a small sample application showing the problem? Setting up an app using Azure the way you are is likely non-trivial. Remember to delete any credentials (it just has to build and crash on launch.

    Monday, March 27, 2017 9:33 PM
  • User310157 posted

    Hi, sure, my internet is somewhat slow though, so it'll take some time uploading.

    However, this is the only code that is needed to get the first error which I cannot resolve. The missing Collections.Generic.List´1 assembly.

    ! using AppKit; ! using Foundation; ! using Microsoft.WindowsAzure.MobileServices; ! using System.Threading.Tasks; ! using System.Collections.Generic; !
    ! namespace AzureTestApp18 ! { ! [Register("AppDelegate")] ! public class AppDelegate : NSApplicationDelegate ! { ! MobileServiceClient client; ! IMobileServiceTable userTable; !
    ! //Server key goes here ! string serverkey = @"https://AskIfYouNeedTheServer.azurewebsites.net"; !
    !
    !
    ! public AppDelegate() ! { ! //Since the 'User' class i not complete, it may throw an error if you run this function ! Foo(); ! } !
    ! public override void DidFinishLaunching(NSNotification notification) ! { ! // Insert code here to initialize your application ! } !
    ! public override void WillTerminate(NSNotification notification) ! { ! // Insert code here to tear down your application ! } !
    ! private async void Foo() ! { ! client = new MobileServiceClient(serverkey); !
    ! userTable = client.GetTable(); !
    ! //These line do not compile. I can't find the right assembly. ! var result1 = userTable.ToListAsync(); ! //var result2 = await userTable.ToListAsync(); !
    ! //This line does compile... ! var testlist = new List(); ! } ! } !
    ! public class User ! { ! public string Id { get; set; } ! } ! } !

    Apart from this I also reference a number of assemblies:

    System.Net.Http v4.0.0.0 from Xamarin.Mac System.Net.Http.Primitives.dll v4.2.29.0 from some net45 library (possibly from the AzureToDo sample) System.Runtime.dll v4.1.1.0 from net462 (AzureToDo sample) Microsoft.WindowsAzure.Mobile.dll v3.0.0.0 from AzureToDo
    Microsoft.WindowsAzure.Mobile.Ext.dll v3.0.0.0 from AzureToDo System.Threading.Tasks.dll v2.6.10.0 from some Microsoft.Bcl.1.1.10/lib/net40

    and the Newtonsoft Json nuget package

    This should be enough to get the error. Otherwise I have a .zip containing the entire test project folder: https://drive.google.com/file/d/0B6x3Wy-T0_nxdDNjXzJMVG40ZlE/view?usp=sharing

    Thank you.

    Monday, March 27, 2017 10:24 PM
  • User310157 posted

    Also when I reference a System.Collections.dll v4.0.0.0 the same line throws a build error saying that the assembly is defined multiple times.

    /Users/frederiktheisen/Projects/AzureTestApp18/AzureTestApp18/AppDelegate.cs(23,23): Error CS0433: The imported type `System.Collections.Generic.List' is defined multiple times (CS0433) (AzureTestApp18)

    Again, thank you for (hopefully) helping me out :)

    Tuesday, March 28, 2017 1:16 PM
  • User35201 posted

    For future reference, you can delete the packages, bin and obj directory to drastically reduce your sample size. Your sample with that done is 370KB, nearly 200x smaller.

    The first thing I noticed is that you are using the Mobile (Modern) target framework. You can read about it here: https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/

    when I tried to restore/add Microsoft.Azure.Mobile.Client.3.1.0 I got:

    Could not install package 'Microsoft.Bcl 1.1.10'. You are trying to install this package into a project that targets 'Xamarin.Mac,Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

    which unfortunately makes sense. Like iOS, Xamarin.Mac Mobile (Modern) requires library authors to create special builds if they aren't just netstandard compatible.

    Switching your target framework to XM 4.5 (Full) got me farther:

    /Users/donblas/Downloads/AzureTestApp18/AzureTestApp18/CSC: Error CS1703: An assembly System.ComponentModel.Primitives' with the same identity has already been imported. Consider removing one of the references (CS1703) (AzureTestApp18) /Users/donblas/Downloads/AzureTestApp18/AzureTestApp18/CSC: Error CS1703: An assemblySystem.ComponentModel.TypeConverter' with the same identity has already been imported. Consider removing one of the references (CS1703) (AzureTestApp18)

    This is a bug:

    https://bugzilla.xamarin.com/show_bug.cgi?id=54139

    There are two work arounds:

    • The easy one. Open your csproj in a text editor and remove the HintPath for System.ComponentModel.Primitives / System.ComponentModel.TypeConverter
    • The more correct future one - If you build your project with msbuild we handle these facades more correctly. You'll need to swap to Xamarin.Mac in the Alpha channel however.
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 28, 2017 4:03 PM
  • User310157 posted

    Ok, so do I need to switch to the XM 4.5 framework and do one of the two workarounds?

    I'm not sure what msbuild is, but when I check for updates in the alpha channel VS doesn't find any. Should I just wait for better support for Azure within the Xamarin.Mac framework or is this as good as it gets within next few month?

    Tuesday, March 28, 2017 6:30 PM
  • User35201 posted

    You will need to swap to XM 4.5 (Full) target framework. The library that you wish to use has not released anything compatible with Mobile (Modern) yet - https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/

    Then to work around the bug you need to either:

    • Open your csproj in a text editor
    • Find the reference section for System.ComponentModel.Primitives and System.ComponentModel.TypeConverter
    • Delete the inner HintPath tag

    OR

    • Xamarin Studio -> Check for Updates
    • Change the Update Channel dropdown to Alpha
    • Install
    • Xamarin Studio -> Preferences -> Projects -> Builds -> Check "Build with MSBuild instead of xbuild (EXPERIMENTAL)"

    The second is a global setting, which would affect any other projects you build, and might require restarting Xamarin Studio.

    The first is a bit of a hack, but significantly more isolated.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, March 28, 2017 6:51 PM
  • User310157 posted

    Tried switching a completely new app to XM 4.5 and I got a load of errors. (missing debugger and mscorlib.dll)

    Is using Visual Studio a problem and should I switch to Xamarin Studio? (I thought they were identical, the same button is even broken in both programs).

    Giving it a quick look, it appears less broken than VS in some parts. I guess I'll give it a try and continue my app from Xamarin Studio.

    Will return with results when I've tested properly.

    Tuesday, March 28, 2017 7:31 PM
  • User35201 posted

    Visual Studio for Mac or Visual Studio proper on Windows?

    I'm not tracking what you are saying.

    Tuesday, March 28, 2017 7:33 PM
  • User310157 posted

    For Mac.

    Anyways, just having some slight issues with Drawing (missing RectangleF, PointF and so on). Will be updating Xamarin software and looking into your thread about the drawing system.

    Tuesday, March 28, 2017 7:45 PM
  • User310157 posted

    I can't fix the errors I'm getting from moving to XM4.5, so I'm pretty much stuck in a limbo between two frameworks. I made a post in the drawing thread with some csproj files.

    Wednesday, March 29, 2017 10:36 AM