Azure-functions-vs-build-sdk: Relax our restrictions on Newtonsoft major versions

Created on 8 Apr 2019  路  15Comments  路  Source: Azure/azure-functions-vs-build-sdk

A few people running into issues when they try to pull down a package that has Newtonsoft 12 requirements as a transitive dependency. While users can get around this today by explicitly pulling down a higher version of Newtonsoft 12 (which will be honored and work in v2 functions), it still leads to a bit of customer confusion. A potential option is to relax our restriction on Newtonsoft 11 so NuGet doesn't complain when this transitive dependency mismatch surfaces.

Related to azure/azure-functions-host#4049

P1

Most helpful comment

I have a az function project I am trying to build in vs.net 2019 as soon as I include this namespace

using Newtonsoft.Json.Serialization;

and try to use it. I get a build error (below)

Severity Code Description Project File Line Suppression State
Error System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
at System.AppDomain.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()

Error generating functions metadata
nuget\packages\microsoft.net.sdk.functions\1.0.29\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets 41

All 15 comments

Both V1 and V2 should support JSON.NET >9.01 or JSON.NET > 11.0.2, not =

I am running into issues trying to use newtonsoft 12.0.2. The runtime is loading 11, even when i explicitly pull 12 into my az functions 2.0 project. I am encountering an exception running JsonConvert.SerializeObject (which is fixed in v12.0.1) and can see the exception.TargetSite.Module is using 11.

I can see both are loaded, but runtime version is being used for this invocation of JsonConvert.
'func.exe' (CoreCLR: clrhost): Loaded '...\AppData\Local\AzureFunctionsTools\Releases\2.22.0\cli\Newtonsoft.Json.dll'.
'dotnet.exe' (CoreCLR: clrhost): Loaded '...\.nuget\packages\newtonsoft.json\12.0.2\lib\netstandard2.0\Newtonsoft.Json.dll'.

@fabiocav : Can you make a preview build and push it to nuget in order to validate your fix ? Current version still has a fixed version (.11). Thanks !

@nicholasdoyle can you please open a separate issue at https://github.com/Azure/azure-functions-host/issues with the details so that can be investigated?

@fabiocav this existing issue can be used by @nicholasdoyle IMO.

馃殌 馃嵃

馃帀

@fabiocav Is this actually resolved? The linked pr is simply relaxes the library requirement, but that will cause horrible to diagnose runtime failures.
If i understand things correctly At runtime the 11.x is what is loaded by the functions runtime, so if I actually use any functionally except from the 11.x version this will be a runtime failure.
Given that protects will typically version change (11->12 in this case) if they use a new feature, then can you confirm that if they did, would things exception?

@AartBluestoke you're correct that this pushes potential issues to happen at runtime, which is why the original restriction was in place to begin with. This didn't prevent the dependency from being added, so it was a small protection that was in place. We ended up making the change (after a lot of consideration and requests) as in the vast majority of cases, this shouldn't cause an issue, but because this could indeed cause problems that may be difficult to diagnose, we're making enhancements to the runtime to properly warn when this binding condition is hit and eventually also unify on 12 (for a few different reasons, primarily related to HTTP binding, there are some specific binding rules for Json.NET).

Those changes will be tracked in the host repository, though.

Thanks, @DustinKingen. That鈥檚 a good post and covers much of what has been considered for this particular case. In the end, we do believe this change, coupled enhancements made to runtime binding, will improve the overall experience.

I have a az function project I am trying to build in vs.net 2019 as soon as I include this namespace

using Newtonsoft.Json.Serialization;

and try to use it. I get a build error (below)

Severity Code Description Project File Line Suppression State
Error System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
at System.AppDomain.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()

Error generating functions metadata
nuget\packages\microsoft.net.sdk.functions\1.0.29\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets 41

Fabio, we have discussed this at Build. For V1, I would like you to make Azure Function to be compatible up to 11.02 of newtonsoft's JSON. I have way too many .net third party libraries that are simply not available for .net core. This is a Deal breaker as I have to resort to either cloud service or something else or different platform all together.

@jwisener Thanks for pointing me in the direction to remove the using Newtonsoft.Json.Serialization; and try if that helps. And it does. This issue did cost me about 8 hours to figure out.

Why this ticket is in closed status though the issue still persists even today ??
Warning received:
_"Detected package version outside of dependency constraint: Microsoft.NET.Sdk.Functions 1.0.29 requires Newtonsoft.Json (= 11.0.2) but version Newtonsoft.Json 12.0.3 was resolved"_

@ThiruA1980 that's only a warning, not the outright error that it was before the hard dependency was removed. At runtime, the 11.0.2 library will be the one physically present. That warning indicates that there is indeed a potential runtime error within your code if you use features from the not-loaded dll.

Was this page helpful?
0 / 5 - 0 ratings