3

I've a Azure Function project (created using VS 2017 15.3.4). I have added a unit test project in the same solution (4.6.1). As soon as i add reference to my Azure function project, and i try to run my simple test case i get this error "Could not load file or assembly System.Net.Http, Version=4.1.1.0" as i execute MyFunction's Run method.

Exception Image I have tried alot of approached recommended but nothing seems to work.

I have tried to add the the binding in app.config file

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
  </dependentAssembly>

I have tried to add the nuget package for System.Net.http explicitly (from latest version to few version behind) but that's not helping either.

has anyone managed to find the solution for this?

Thanks Sanjay

Sanjay Bhagia
  • 155
  • 12

1 Answers1

7

There is a way to make this work, but it is not completely straightforward:

  • Create a Unit Test (.NET Core) project and not Unit Test (.NET Framework). This forces it to use the new Project System.
  • Edit the csproj for the unit test project.
  • Change the <TargetFramework> from netcoreapp2.0 to net461. Note: you cannot change this from the VS UI, hence the manual editing!
  • In VS, add a reference to your Functions Project

And now everything should work a lot better. e.g. see https://github.com/vijayrkn-test/FunctionsProjectWithClassLib for a full sample.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • Ahan, that's something worth a shot. I did try to create netcore project but ofcourse due to version mismatch didn't go further much. I'll try this one and let you know if it works. Thanks! – Sanjay Bhagia Sep 19 '17 at 05:42
  • I am required to use VS2015 for now, I have installed the .NET Core 2.0 platform to try the workaround, however there is not a unit test project available under '.NET Core' so how is it possible to use this workaround? – Darren Oct 26 '17 at 22:06
  • 1
    Azure Functions VS tooling is only available for VS 2017, so don't know of a way to make this work in 2015. – David Ebbo Oct 26 '17 at 22:49
  • I am using this method with VS2015: https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app/ ...getting the same exception though via test project, are .NET Core unit test projects not supported in VS2015? – Darren Oct 26 '17 at 23:41
  • 1
    That was a manual workflow that we had put together as a stop gap before we have VS 2017 support. It is not well supported. – David Ebbo Oct 26 '17 at 23:43