nUnit tests for PLC

Hi!

I'm having trouble with running unit tests for a PCL. I can reference the PCL from my unit test project but when I try to use one of the classes from the PLC I get the following error:

c:\Users\Jeroen\workspace\glass.xamarin\GlassBroker\GlassBroker.Core.Tests\Tests\Test.cs(4,4): Error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (CS0012) (GlassBroker.Core.Tests)

I'm using profile78 for the PCL and this is what my solution looks like:

Who can help me out?

Posts

  • JeroenSJeroenS NLMember

    I sort of fixed it by manually adding a reference to System.Runtime but now Xamarin gives me 133 warnings.
    Every one of them says something like:

    Warning CS1685: The predefined type 'System.Int16' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll' (CS1685) (GlassBroker.Core.Tests)

    So when I don't reference System.Runtime Xamarin won't build and gives an error stating it can't be found, and when I do reference it's suddenly referenced twice.

  • When I test a PCL, I do it from a regular class library that refrences the PCL. I don't have any of the problems you see. You might want to give that a shot.

    I have a question on this forum asking if this is a good practice or not. I haven't seen an answer yet.

  • mattwardmattward GBMember Xamurai

    @JeroenS‌ - You should not have to add a reference to System.Runtime.dll manually.

    The error you are seeing can occur if Xamarin Studio is for some reason not compiling against the Facade assemblies. If you look at the Build Output in the Errors window what do you see when you rebuild the GlassBroker.Core.Tests project?

    I see the following:

        Building: GlassBroker.Core.Tests (Debug)
        Performing main compilation...
        C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /noconfig "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll"
         -nostdlib
         "/out:d:\temp\GlassBroker.Core\GlassBroker.Core.Tests\bin\Debug\GlassBroker.Core.Tests.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll"
         "/r:d:\temp\GlassBroker.Core\GlassBroker.Core.Tests\..\packages\NUnit.2.6.3\lib\nunit.framework.dll"
         "/r:d:\temp\deletethisfolder\GlassBroker.Core\GlassBroker.Core\bin\Debug\GlassBroker.Core.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Collections.Concurrent.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Collections.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.ComponentModel.Annotations.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.ComponentModel.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.ComponentModel.EventBasedAsync.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Diagnostics.Contracts.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Diagnostics.Debug.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Diagnostics.Tools.dll"
         "/r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Diagnostics.Tracing.dll"
         ...
         ...
    

    Lots of other assemblies are referenced including System.Runtime.dll without my test project explicitly referencing them.

  • JeroenSJeroenS NLMember

    I get these errors: http://pastebin.com/7Q3HUUpm

    I have no idea how to fix them though. I have already installed the Portable Library Tools and reinstalled Xamarin after that.
    Could you help me out?

  • mattwardmattward GBMember Xamurai

    @JeroenS - You could try installing the .NET 4.5 SDK which is part of the Windows SDK. That should get rid of the warnings about the reference assemblies. Not sure it will fix the other error but it is a starting point.

  • JeroenSJeroenS NLMember

    @mattward‌ - I already have the .NET 4.5 SDK installed.

    The strange(?) thing when I reference GlassBroker.Core (The PCL) from an Monodroid project it works fine.

  • mattwardmattward GBMember Xamurai

    The MonoDroid project will be using a different MSBuild .targets file which is correctly resolving the Facade dlls. It looks like a normal .NET class library project is not resolving those Facade dlls nor finding the reference assemblies on your machine for some reason.

    On my machine I have several Windows SDKs as well as the .NET 4.5.1 targeting pack.

  • JeroenSJeroenS NLMember

    Installing the Windows SDK and then changing the project's target framework to ".NET Framwork 4.5.1" worked! Thanks for the help @mattward!

Sign In or Register to comment.