Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax our restrictions on Newtonsoft major versions #304

Closed
jeffhollan opened this issue Apr 8, 2019 · 15 comments · Fixed by #323
Closed

Relax our restrictions on Newtonsoft major versions #304

jeffhollan opened this issue Apr 8, 2019 · 15 comments · Fixed by #323
Assignees
Labels

Comments

@jeffhollan
Copy link

jeffhollan commented Apr 8, 2019

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

@jeffhollan jeffhollan added the P1 label Apr 8, 2019
@jeffhollan jeffhollan added this to the Triaged milestone Apr 8, 2019
@metrodeveloper
Copy link

metrodeveloper commented Apr 11, 2019

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

@nicholasdoyle
Copy link

nicholasdoyle commented May 15, 2019

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'.

@bartdk-be
Copy link

@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 !

@fabiocav
Copy link
Member

fabiocav commented Jun 3, 2019

@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?

@PureKrome
Copy link

PureKrome commented Jun 3, 2019

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

🚀 🍰

@brandonh-msft
Copy link
Member

🎉

@AartBluestoke
Copy link

@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?

@fabiocav
Copy link
Member

fabiocav commented Jul 2, 2019

@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.

@DustinKingen
Copy link

Background information to think on: https://codeblog.jonskeet.uk/2019/06/30/versioning-limitations-in-net/

@fabiocav
Copy link
Member

fabiocav commented Jul 2, 2019

Thanks, @DustinKingen. That’s 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.

@jwisener
Copy link

jwisener commented Jul 3, 2019

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

@metro-mark
Copy link

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.

@DeluxZ
Copy link

DeluxZ commented Sep 24, 2019

@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.

@TestUser0811
Copy link

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"

@AartBluestoke
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.