Newtonsoft.Json nuget package fails on Electron.NET app #784

Closed
opened 2026-01-29 16:48:29 +00:00 by claunia · 9 comments
Owner

Originally created by @domingoladron on GitHub (Apr 18, 2022).

  • Version:
    13.5.1

NET 5 or NET 6 (tried both), Node: v16.14.0

  • Target:
    Windows to start with

This is likely an issue with the versioning pattern of Newtonsoft.json but good to note if anyone else encounters this issue. You can grab a copy of my repo to reproduce the issue.
https://github.com/domingoladron/LearnBlazor.ElectronNet/tree/bug/json-net-electon-net

It appears that if you run up a Blazor app inside Electron.NET and try to call anything using Newtownsoft.Json library (tried both 13.01 and 12.03), it will fail with the following error:

FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.

If you try this same thing when running the app as a web app (IIS, Docker, etc.) it works fine.

I've added a blob of simple JSON deserialisation using the Newtonsoft.JSON JsonConvert class to the Index.razor page to show the error when you run up the Electron.NET app.

//just calling Newtownsoft.Json class to fire the exception
 
 var fakeClassData = JsonConvert.DeserializeObject<FakeClass>(await File.ReadAllTextAsync(Path.Join(Environment.CurrentDirectory, "fakefile.json")));

I think this has to do with how Newtownsoft.JSON versions packages. While the package is labeled 13.0.1, internally, the package itself is versioned '13.0.0' and the app running in Electron.NET can't find it.

Steps to Reproduce:

  1. Including Newtonsoft.JSON to your web app as a nuget package

  2. Call some code from within the Newtonsoft.JSON package

  3. Start the app as a website. Everything will run fine
    image

  4. Start the app via electronize. It will bomb immediately upon hitting the Newtownsoft.JSON code
    image

Originally created by @domingoladron on GitHub (Apr 18, 2022). * **Version**: 13.5.1 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> NET 5 or NET 6 (tried both), Node: v16.14.0 <!-- What target are you building for? --> * **Target**: Windows to start with <!-- Enter your issue details below this comment. --> This is likely an issue with the versioning pattern of Newtonsoft.json but good to note if anyone else encounters this issue. You can grab a copy of my repo to reproduce the issue. https://github.com/domingoladron/LearnBlazor.ElectronNet/tree/bug/json-net-electon-net It appears that if you run up a Blazor app inside Electron.NET and try to call anything using Newtownsoft.Json library (tried both 13.01 and 12.03), it will fail with the following error: `FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.` If you try this same thing when running the app as a web app (IIS, Docker, etc.) it works fine. I've added a blob of simple JSON deserialisation using the Newtonsoft.JSON JsonConvert class to the Index.razor page to show the error when you run up the Electron.NET app. ``` //just calling Newtownsoft.Json class to fire the exception var fakeClassData = JsonConvert.DeserializeObject<FakeClass>(await File.ReadAllTextAsync(Path.Join(Environment.CurrentDirectory, "fakefile.json"))); ``` I think this has to do with how Newtownsoft.JSON versions packages. While the package is labeled 13.0.1, internally, the package itself is versioned '13.0.0' and the app running in Electron.NET can't find it. Steps to Reproduce: 1. Including Newtonsoft.JSON to your web app as a nuget package 2. Call some code from within the Newtonsoft.JSON package 3. Start the app as a website. Everything will run fine ![image](https://user-images.githubusercontent.com/28288031/163881662-b92dc127-a463-42de-816c-04321d42c362.png) 4. Start the app via electronize. It will bomb immediately upon hitting the Newtownsoft.JSON code ![image](https://user-images.githubusercontent.com/28288031/163881427-1a3a7736-aa88-451b-a8e4-55b81d2286a2.png)
claunia added the bug label 2026-01-29 16:48:29 +00:00
Author
Owner

@domingoladron commented on GitHub (Apr 18, 2022):

I can confirm that if I ditch Newtonsoft.JSON (which, btw, appears to be used in the Electron.NET WebApp csproj as a dependency) and instead use System.Text.Json Serializer / Deserializer classes, everything works mint.

Here's a branch with the fixed code

https://github.com/domingoladron/LearnBlazor.ElectronNet/tree/bug/json-net-electron-net-fixed

So it is specifically to do with Newtonsoft.JSON.

@domingoladron commented on GitHub (Apr 18, 2022): I can confirm that if I ditch Newtonsoft.JSON (which, btw, appears to be [used in the Electron.NET WebApp csproj as a dependency](https://github.com/ElectronNET/Electron.NET/blob/master/ElectronNET.WebApp/ElectronNET.WebApp.NET5.csproj#L18)) and instead use System.Text.Json Serializer / Deserializer classes, everything works mint. Here's a branch with the fixed code https://github.com/domingoladron/LearnBlazor.ElectronNet/tree/bug/json-net-electron-net-fixed So it is specifically to do with Newtonsoft.JSON.
Author
Owner

@Melethainiel commented on GitHub (Apr 22, 2022):

It seems not to be only newtonsoft library. I got the same error with epplus. Last month it was working well.

@Melethainiel commented on GitHub (Apr 22, 2022): It seems not to be only newtonsoft library. I got the same error with epplus. Last month it was working well.
Author
Owner

@domingoladron commented on GitHub (Apr 22, 2022):

What is the error message you're getting? What version are you now using? Under which version was it working?

@domingoladron commented on GitHub (Apr 22, 2022): What is the error message you're getting? What version are you now using? Under which version was it working?
Author
Owner

@domingoladron commented on GitHub (Apr 22, 2022):

Didn't intend to close that. Mobile app is tetchy.

@domingoladron commented on GitHub (Apr 22, 2022): Didn't intend to close that. Mobile app is tetchy.
Author
Owner

@ipax77 commented on GitHub (Apr 23, 2022):

I could not make my app build/publish successful with dotnet 6.0.4, the window does not open and it is stuck at

Electron Socket IO Port: 8000
Electron Socket started on port 8000 at 127.0.0.1
ASP.NET Core Port: 8001

I reverted to dotnet 6.0.3 and everything is working as usual.

@ipax77 commented on GitHub (Apr 23, 2022): I could not make my app build/publish successful with dotnet 6.0.4, the window does not open and it is stuck at ``` Electron Socket IO Port: 8000 Electron Socket started on port 8000 at 127.0.0.1 ASP.NET Core Port: 8001 ``` I reverted to dotnet 6.0.3 and everything is working as usual.
Author
Owner

@Melethainiel commented on GitHub (Apr 25, 2022):

@domingoladron I got this error :

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IO.RecyclableMemoryStream, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Le fichier spécifié est introuvable.
File name: 'Microsoft.IO.RecyclableMemoryStream, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I Tried with dotnet 6.0.102 to 6.0.202 and none are working

@Melethainiel commented on GitHub (Apr 25, 2022): @domingoladron I got this error : ``` System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IO.RecyclableMemoryStream, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Le fichier spécifié est introuvable. File name: 'Microsoft.IO.RecyclableMemoryStream, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ``` I Tried with dotnet 6.0.102 to 6.0.202 and none are working
Author
Owner

@Melethainiel commented on GitHub (May 2, 2022):

The bug seems to be only on my computer as on Azure CI build, I don't get the exception.

@Melethainiel commented on GitHub (May 2, 2022): The bug seems to be only on my computer as on Azure CI build, I don't get the exception.
Author
Owner

@ipax77 commented on GitHub (May 14, 2022):

Updating my NuGet packages to 6.0.5 solved my problems.

@ipax77 commented on GitHub (May 14, 2022): Updating my NuGet packages to 6.0.5 solved my problems.
Author
Owner

@domingoladron commented on GitHub (Jun 14, 2022):

Updating my NuGet packages to 6.0.5 solved my problems.

I'll give that a try and close the bug if that sorts it. Cheers

@domingoladron commented on GitHub (Jun 14, 2022): > Updating my NuGet packages to 6.0.5 solved my problems. I'll give that a try and close the bug if that sorts it. Cheers
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#784