Xamarin: System.Net.Http does not work in unit tests, but works on device

510 views Asked by At

I am running Xamarin in OSX Yosemite.

My problem is that I cannot get System.Net.Http to work at all when writing unit tests.

To replicate, one can create a very simple test class:

using NUnit.Framework;
using System.Net.Http;
using ModernHttpClient

namespace testclass
{
    [TestFixture ()]
    public class Test
    {
        [Test ()]
        public void TestCase ()
        {
            var client = new HttpClient (new NativeMessageHandler());
        }
    }
}

Running this invariably yields:

System.IO.FileNotFoundException: Could not load File or Assembly 'System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeytoken=b03f5f7f11d50a3a' or one of its dependencies.

However, inserting the same line of code into an Android app works just fine.

I have already tried completely removing and reinstalling Xamarin, but unfortunately this does not solve the issue. Any ideas?

1

There are 1 answers

0
Robert Anderson On

It is trying to find that assembly but cannot load it.

Things to check:

In your Unit testing project, make sure the reference is exactly the same as the project that works.

For the System.Net.Http reference, right click it and check that specific version = false

Also have a look in the GAC C:\Windows\Assembly and find that dll, right click and check which version it is and that it matches the version in the message.

If no further progress after that, best to remove and readd the reference in the Unit testing project, then close .Net IDE and reopen.

Check the references path is OK for the unit testing project and that it contains the 1.5.0.0 version of the assembly.