Azure / Azure-Functions

1.11k stars 197 forks source link

Error Microsoft.NET.Sdk.Functions.targets Could not load file or assembly Newtonsoft.Json, Version=9.0.0.0 #387

Closed richardjharding closed 7 years ago

richardjharding commented 7 years ago

I'm trying to use the AlexaSkillsKit.net package AlexaSkillsKit

With the latest tooling vs2017 preview, azure functions sdk

Adding a function compiles fine until I add the reference to the package above and attempt to use it in the function

Here is my csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AlexaSkillsKit.NET" Version="1.5.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha6" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

and here is the error

 ---\.nuget\packages\microsoft.net.sdk.functions\1.0.0-alpha6\build\netstandard1.0\Microsoft.NET.Sdk.Functions.targets(44,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

Looking at the nuget packages for both the functions sdk and alexaskillskit both seem to be satisfied by the version of newtonsoft referenced so I'm struggling to see how to resolve the error?

duckwaffle commented 7 years ago

This is probably going to be due to the fact that the AlexaSkillsKit library is an old style .net library using the old format .csproj.

The issue is that Binding Redirects aren't being generated automatically, if you add the following to your .csproj: <PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>

You will end up with a [FunctionsProjectName].dll.config file which should have the correct Binding Redirects in it for consuming a different version of json.net than what the alexa skills kit library is expecting.

However, this still won't help you when it comes to debugging, the Functions debug CLI doesn't support Binding Redirects for some reason, I haven't had a chance to investigate properly yet, when I do so I will probably raise a new bug here for the guys to look at.

The best temporary solution is to drop your version of newtonsoft.json down to 9.0.0 if the rest of your references can accept that.

lindydonna commented 7 years ago

The problem is actually that we don't support binding redirects (in either the CLI or the runtime in Azure). So, you need to use the exact version that we provide in the runtime. The easiest way to discover these versions is to look at the dependencies of the NuGet package https://www.nuget.org/packages/Microsoft.Azure.WebJobs/2.1.0-beta1. This package is automatically added when you create a new Functions project in Visual Studio.

So, you need to drop down to Newtonsoft 9.0.0. In the future, we'll make this more streamlined, so it's easier to get the right dependencies.

We have an open feature request for binding redirects. See https://github.com/Azure/azure-webjobs-sdk-script/issues/573

tomkerkhove commented 7 years ago

Any update on this? Still have this..

lindydonna commented 7 years ago

@tomkerkhove Please watch https://github.com/Azure/azure-webjobs-sdk-script/issues/573 for updates.