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
Remove dependency on Newtonsoft.Json #1060
Comments
I knew this day might come... 😂 |
Here's one issue. |
Well, Microsoft's problem is Microsoft's problem. We can at least remove our dependency, as a show of moral superiority. 😄 |
You could try including the following rather than referencing Newtonsoft.Json: I've tested/used this with Mono.Cecil and Castle.Core, but haven't used the above file more than simply checking that it compiles. You will need to use the 'Internal.Newtonsoft.Json' namespace. Let me know if you try it! 😄 |
Note, this can easily be automated using Paket and src2proj. Here is how I turn 'Mono.Cecil.csproj' into 'Mono.Cecil.cs': https://github.com/jcansdale/GhostAssemblies/blob/master/setup.bat |
We actually still have the old ASP.NET vNext JSON parser hanging around in our source: https://github.com/xunit/xunit/blob/master/src/xunit.runner.utility/Configuration/Json.cs That might be sufficient for our needs. |
Isn't it in the plan that you can swap in local source for PackageReferences? If that works as it should, then that'd mean your source ref should supersede all dependency references on the graph and your source would be used everywhere, under test and during loading the tests by all of the dependencies... ? |
@bradwilson What about |
Can SimpleJson.cs (Outercurve Foundation) be an option? |
DataContractJsonSerializer and SImpleJson are both options. .NET Standard 2.0 might also bring back JavaScriptSerializer.
It doesn't have a serializer. |
I am still running an issue with this on 2.3 because |
My tests pass when I use |
Take a look at this repro. It shows that with the release build of |
@smbecker I've looked at this, and unfortunately there's nothing we can do. We aren't taking a direct dependency on JSON.NET, but rather indirectly through This is the component responsible for parsing the The only way for us to remove this dependency would be for us to copy the source code to Microsoft.Extensions.DependencyModel (and, recursively, all of its non-Platform-shipped dependencies I've already brought this issue up (on Twitter) with some people at Microsoft, but I'm surprised to see someone hitting it already. They've told me that they have no plans to fix it at this time, and the earliest place they could fix it would be in 3.0 (because removing the JSON.NET dependency is considered by them to be a breaking change). /cc @DamianEdwards @davidfowl @natemcmaster |
I vaguely remember those twitter conversations, but I couldn't find it in our issue trackers. It's worth opening the issue on https://github.com/dotnet/core-setup so we can get the right people involved. |
I definitely did not open an issue. Unless I was willing to forego .NET Core 1.0 support, none of your .NET Core 3.0 fixes would help me anyways. :-p |
I'm going to leave this open, to see if the source copying is feasible. I really need a narrow subset of functionality, so maybe it's not as bad as the worst case scenario. |
What changed from beta to release that would cause the issue? In the repro I posted, it loads the correct version in the beta and the wrong version in the release build. It also doesn't load native dependencies between beta to release. |
I'm curious about that too. I created this issue because I noticed a bug in Newtonsoft.Json would then affect xunit, so xunit was obviously using the application's version (in my case it was the version built from source). What has changed since then? Also is this issue specific to Newtonsoft.Json? Won't any assemblies that are loaded by xunit also have the same problem when an app has a different version? |
We stopped (incorrectly) causing all references to be copied into the bin folder, and started (correctly) supporting the So while it works for you, there were several other broken scenarios that got fixed along the way that prevent us from simply rolling this change back.
It is not, though you're the most obvious thing people would want to use. Anything which doesn't ship with the .NET runtime itself is a potential problem point. The easy way to figure out what's affected is look what DLLs show up when do you a For our console runner right now, that's:
That is everything we use that doesn't ship with the platform itself. I worked pretty hard to make that list small (with @natemcmaster's help understanding why the list used to be like 90 items long In my opinion, this problem gets significantly worse for any large application that wants to implement a plug-in style system, wherein the plug-ins are running in the same process. Anything they use which could potentially conflict with something a plug-in might want to use is a potential failure point. Worse, though, is that ASP.NET Core now ships with the 2.0 runtime (it did not in 1.x), and that internally takes the Now you can see why I'm considering just source copying the bits and pieces of those other dependencies that I need rather than bringing them in as package dependencies. In my scenario, it would be ideal if my publish directly looked identical to my bin directory. |
In case you wondered how we got here in the first place, we had a problem with the old .NET Core never had this behavior, because it uses its own loader which can look things up out of your NuGet cache. When you look at your So, we inherited this behavior from As a result, I consider 2.2 .NET Core support to be in a degenerate state that "sort of works, and sort of doesn't" (aka, for managed dependencies only), and 2.3 .NET Core support to be much better (but we'll be patching some significant issues with a 2.3.1 point release very soon now). |
You mentioned that you switched to using .deps.json, which is required to load native dependencies. Ironically, that change broke the ability to use native dependencies. |
How so? |
If you run the repro, one of the tests is to create a sqlite connection. The test passes using the beta but fails to load e_sqlite3 with the release build. |
I had similar issues with sqlconnection and loading sni.dll where it passes with the beta but fails with the release. |
Can you provide a repro project that fails against the current CI build from MyGet ( |
And if so, please open a new issue, as it doesn't belong here. |
I updated the repro to use |
One work-around that I found was to by-pass public static class Program
{
public static void Main(string[] args) => Xunit.ConsoleClient.Program.Main(new[] { typeof(Program).Assembly.Location }.Concat(args).ToArray());
} |
@smbecker As mentioned before, you're trading one problem for another if you're using ASP.NET Core, since it has a reference to 9.0.1, and without thorough testing you won't know about any incompatibilities until they surface at runtime. Tread very carefully, here. |
…osoft.Extensions.DependencyModel (and all downstream dependencies, including Newtonsoft.Json) (another fix for #1060)
|
FWIW, my solution here is based on the old JSON parser that I stole from DNX days, which likely has much worse memory performance than using JSON.NET (whose source I had no intention of actually copying). dotnet/core-setup#3311 suggests that there might be something newer and better that I could steal down the road if needed. ;) |
Closed again. Hopefully for the last time. 😌 |
@bradwilson Everything works fine for me if both my WebApi and my xUnit project reference But when using version 11.0.2 for both project I get the familiar exception: |
@stefan-schweiger Make sure you're using the latest build of xUnit.net (2.4 beta 1). If you can still repro, please open a new issue. |
Running into this issue: #1910 XUnit just gets stuck when a project uses Json.NET. If you XUnit would just change the json.net assembly name, then alias it under a global namespace we could load two independent versions without an issue I would think. |
Microsoft.Extensions.DependencyModel will be moving to use System.Text.Json which will hopefully solve the runtime dependency. |
The current version of xUnit.net has no dependencies on JSON.net. If you can repro the problem with 2.4.1, then please open a new issue. |
Just looked at #1910. My answer is: stop building everything into a single folder. It's not supported, because things are constantly broken when you do it. You just hit one of literally dozens of ways in which this is going to bite you. |
json.net is the only lib in that folder causing an issue. If its not a dependency why is it being there causing an issue? Something in xUnit or VS 2017 is loading it. Seems like this started to happen after I updated from .NET Core 2.1 to 2.2 |
VS test runner is probably using it to serialize the messages passed between the test process and VS. |
@JamesNK Maybe VSTest itself, but nothing in xUnit.net (including our VSTest adapter). I definitely put in the effort to remove it once it was clear that we couldn't take any non-platform dependencies at all if we wanted .NET Core to work correctly. |
@zezba9000 .NET Core itself takes a dependency on JSON.NET. In your case, putting an incompatible (.NET Framework) version of JSON.NET into your bin folder was undoubtedly the cause of the problem. |
It is hard to test Newtonsoft.Json when xunit uses it and the project reference and xunit Newtonsoft.Json.dll collide!
The text was updated successfully, but these errors were encountered: