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

NuGetForUnity Doesn't install System.Text.Json properly #428

Closed
Incubatio opened this issue Nov 16, 2021 · 2 comments · Fixed by #393
Closed

NuGetForUnity Doesn't install System.Text.Json properly #428

Incubatio opened this issue Nov 16, 2021 · 2 comments · Fixed by #393

Comments

@Incubatio
Copy link

Description

Installing System.Text.Json via command line will install 7 packages:
"Microsoft.Bcl.AsyncInterfaces.5.0.0, System.Buffers.4.5.1, System.Memory.4.5.4, System.Runtime.CompilerServices.Unsafe.5.0.0, System.Text.Encodings.Web.5.0.1, System.Text.Json.5.0.2, System.Threading.Tasks.Extensions.4.5.4"

Installing System.Text.Json via NugetForUnity install 3 packages:
"Microsoft.Bcl.AsyncInterfaces.5.0.0, System.Text.Encodings.Web.5.0.1, System.Text.Json.5.0.2"

Running unity project using NugetForUnity and missing 4 packages will lead to this error:
Assembly 'Assets/NugetPackages/System.Text.Json.5.0.2/lib/net461/System.Text.Json.dll' will not be loaded due to errors: Unable to resolve reference 'System.Runtime.CompilerServices.Unsafe'. Is the assembly missing or incompatible with the current platform? Reference validation can be disabled in the Plugin Inspector.

Specs

  • NuGet Package: System.Text.Json 5.0.2
  • NuGetForUnity Version: 3.0.3
  • Unity Version: 2021.2.1f1
  • Unity Project Settings' default Api Compatibility Level" is ".NET Framework"
  • Operating System: Windows 10

How to reproduce

  • Create a new empty project in unity 2021.2.1f1
  • Install NugetForUnity and install System.Text.Json version 5.0.2
  • In the main scene, create an empty game object and add a monoBehavior.
  • In the new monobehavior's Start() add the following line:
    Debug.Log(JsonSerializer.Deserialize<string>("\"test\""));

Additional Notes / Bugs

  • Using System.Text.Json version 6.0.0 in a new project will lead to an additional layer of errors:
    Multiple precompiled assemblies with the same name System.Text.Json.SourceGeneration.resources.dll included on the current platform. Only one assembly with the same name is allowed per platform.
  • Unity Project Settings' default "Api Compatibility Level*" is .Net Standard 2.1 which download netstandard2.0.
    You might get an error where unity tries to reference net461.
@etareduction
Copy link

Did you found any workaround on that? I'm currently struggling to fix it.

@Incubatio
Copy link
Author

I ended up using https://github.com/xoofx/UnityNuGet
works like a charm.

@JoC0de JoC0de linked a pull request Dec 26, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants