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

System.Text.Json: Method not found System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8 stil happens in NuGet 5.0.0 ans 5.0.1 #49940

Closed
juwens opened this issue Mar 20, 2021 · 16 comments

Comments

@juwens
Copy link

juwens commented Mar 20, 2021

Still happens with:

  • Xamarin.iOS 14.14.2.5
  • and: System.Text.Json Nuget 5.0.0 and 5.0.1

Background info, because this was discussed in another thread.

Related: #1460 #31066 #31326

=== Visual Studio Community 2019 for Mac ===

Version 8.9.2 (build 0)
Installation UUID: 5b6201d9-6c1b-4904-a5a7-463b3da00b5a
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000125

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.125 (2020-02/8c552e98bd6) (64-bit)
	Package version: 612000125

=== Roslyn (Language Service) ===

3.9.0-6.21152.10+c10f884b30737542ddd84ca889a4aad9281ce210

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.201/Sdks
SDK Versions:
	5.0.201
	3.1.407
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.4
	3.1.13

=== .NET Core 3.1 SDK ===

SDK: 3.1.407

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin Designer ===

Version: 16.9.0.316
Hash: 2241b204a
Branch: tags/vsm-rel/d16.9-4540908
Build date: 2021-03-10 22:18:10 UTC

=== Apple Developer Tools ===

Xcode 12.4 (17801)
Build 12D4e

=== Xamarin.Mac ===

Version: 7.8.2.5 (Visual Studio Community)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:43-0500

=== Xamarin.iOS ===

Version: 14.14.2.5 (Visual Studio Community)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:44-0500

=== Xamarin.Android ===

Version: 11.2.2.1 (Visual Studio Community)
Commit: xamarin-android/d16-9/877f572
Android SDK: /Users/jjaehrig/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2

Build Information: 
Mono: 5e9cb6d
Java.Interop: xamarin/java.interop/d16-9@54f8c24
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.34.1@daff8f4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@d210f11

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/jjaehrig/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.22
Hash: a391de2
Branch: remotes/origin/d16-9
Build date: 2021-03-05 19:52:30 UTC

=== Android Device Manager ===

Version: 16.9.0.17
Hash: fc2b3db
Branch: remotes/origin/d16-9
Build date: 2021-03-05 19:52:54 UTC

=== Build Information ===

Release ID: 809020000
Git revision: a69906fb0095d046b113a63419c9af3034ce104e
Build date: 2021-03-11 14:01:37-05
Build branch: release-8.9
Xamarin extensions: a69906fb0095d046b113a63419c9af3034ce104e

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.3.0 Darwin Kernel Version 20.3.0
    Thu Jan 21 00:06:51 PST 2021
    root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 x86_64

https://gist.github.com/juwens/d04e750ac0ad352f085da571b6a5482f

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Mar 20, 2021
@ghost
Copy link

ghost commented Mar 20, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

#31326 still happens in System.Text.Json Nuget 5.0.0 and 5.0.1

Author: juwens
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@juwens juwens changed the title #31326 still happens in System.Text.Json Nuget 5.0.0 and 5.0.1 System.Text.Json: Method not found System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8 stil happens NuGet 5.0.0 ans 5.0.1 Mar 20, 2021
@juwens juwens changed the title System.Text.Json: Method not found System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8 stil happens NuGet 5.0.0 ans 5.0.1 System.Text.Json: Method not found System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8 stil happens in NuGet 5.0.0 ans 5.0.1 Mar 20, 2021
@GrabYourPitchforks
Copy link
Member

@ericstj Is this the same root cause as #49211? See also your earlier comment at #1460 (comment).

@filipnavara
Copy link
Member

@GrabYourPitchforks yes, same error

@juwens
Copy link
Author

juwens commented Mar 22, 2021

There's also in issue on the xamrin.ios board: dotnet/macios#10912

@ghost
Copy link

ghost commented Mar 22, 2021

Tagging subscribers to this area: @GrabYourPitchforks
See info in area-owners.md if you want to be subscribed.

Issue Details

Still happens with:

  • Xamarin.iOS 14.14.2.5
  • and: System.Text.Json Nuget 5.0.0 and 5.0.1

Background info, because this was discussed in another thread.

Related: #1460 #31066 #31326

=== Visual Studio Community 2019 for Mac ===

Version 8.9.2 (build 0)
Installation UUID: 5b6201d9-6c1b-4904-a5a7-463b3da00b5a
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000125

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.125 (2020-02/8c552e98bd6) (64-bit)
	Package version: 612000125

=== Roslyn (Language Service) ===

3.9.0-6.21152.10+c10f884b30737542ddd84ca889a4aad9281ce210

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.201/Sdks
SDK Versions:
	5.0.201
	3.1.407
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.4
	3.1.13

=== .NET Core 3.1 SDK ===

SDK: 3.1.407

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin Designer ===

Version: 16.9.0.316
Hash: 2241b204a
Branch: tags/vsm-rel/d16.9-4540908
Build date: 2021-03-10 22:18:10 UTC

=== Apple Developer Tools ===

Xcode 12.4 (17801)
Build 12D4e

=== Xamarin.Mac ===

Version: 7.8.2.5 (Visual Studio Community)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:43-0500

=== Xamarin.iOS ===

Version: 14.14.2.5 (Visual Studio Community)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:44-0500

=== Xamarin.Android ===

Version: 11.2.2.1 (Visual Studio Community)
Commit: xamarin-android/d16-9/877f572
Android SDK: /Users/jjaehrig/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2

Build Information: 
Mono: 5e9cb6d
Java.Interop: xamarin/java.interop/d16-9@54f8c24
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.34.1@daff8f4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@d210f11

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/jjaehrig/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.22
Hash: a391de2
Branch: remotes/origin/d16-9
Build date: 2021-03-05 19:52:30 UTC

=== Android Device Manager ===

Version: 16.9.0.17
Hash: fc2b3db
Branch: remotes/origin/d16-9
Build date: 2021-03-05 19:52:54 UTC

=== Build Information ===

Release ID: 809020000
Git revision: a69906fb0095d046b113a63419c9af3034ce104e
Build date: 2021-03-11 14:01:37-05
Build branch: release-8.9
Xamarin extensions: a69906fb0095d046b113a63419c9af3034ce104e

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.3.0 Darwin Kernel Version 20.3.0
    Thu Jan 21 00:06:51 PST 2021
    root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 x86_64

https://gist.github.com/juwens/d04e750ac0ad352f085da571b6a5482f

Author: juwens
Assignees: -
Labels:

area-System.Memory, untriaged

Milestone: -

@GrabYourPitchforks GrabYourPitchforks removed the untriaged New issue has not been triaged by the area owner label Mar 22, 2021
@GrabYourPitchforks
Copy link
Member

Keeping this open for now as tracking, but if it's a true dupe we can resolve.

@ericstj
Copy link
Member

ericstj commented Mar 22, 2021

@juwens can you try this workaround:

<PackageReference Include="System.Memory" Version="4.5.3" IncludeAssets="None" />

That should confirm the issue and unblock you if necessary.

@filipnavara
Copy link
Member

Actually, the version should be 4.5.4 (the highest version in NuGet; possibly referenced from other NuGets):

<PackageReference Include="System.Memory" Version="4.5.4" IncludeAssets="None" />

@juwens
Copy link
Author

juwens commented Mar 22, 2021

With IncludeAssets="None"

<PackageReference Include="System.Memory" Version="4.5.4" IncludeAssets="None" />

I get a build error

/Users/jjaehrig/repo/moonshot/src/FooApp/FooApp/App.xaml.cs(31,31): Error CS0012: The type 'ReadOnlySpan<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. (CS0012) (FooApp)

image

Without IncludeAssets="None"

<PackageReference Include="System.Memory" Version="4.5.4" />

I get the exception again

System.TypeInitializationException: The type initializer for 'Moonshot.App.App' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception. ---> System.MissingMethodException: Method not found: int System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<byte>)
  at System.Text.Json.JsonEncodedText.EncodeHelper (System.ReadOnlySpan`1[T] utf8Value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00000] in <3e024d1008104aac9fe12198f4c68344>:0
  at System.Text.Json.JsonEncodedText.TranscodeAndEncode (System.ReadOnlySpan`1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00033] in <3e024d1008104aac9fe12198f4c68344>:0
  at System.Text.Json.JsonEncodedText.Encode (System.ReadOnlySpan`1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <3e024d1008104aac9fe12198f4c68344>:0
  at System.Text.Json.JsonEncodedText.Encode (System.String value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <3e024d1008104aac9fe12198f4c68344>:0
  at System.Text.Json.JsonSerializer..cctor () [0x00042] in <3e024d1008104aac9fe12198f4c68344>:0
  --- End of inner exception stack trace ---
  at Moonshot.App.App..cctor () [0x00007] in /Users/jjaehrig/repo/moonshot/src/App/App/App.xaml.cs:36
  --- End of inner exception stack trace ---
  at Moonshot.App.Setup.Init (System.Action`1[T] nativeConfigureServices, System.Action`1[T] nativeConfigureLogging) [0x00057] in /Users/jjaehrig/repo/moonshot/src/App/App/Setup.cs:84
  at Moonshot.App.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00013] in /Users/jjaehrig/repo/moonshot/src/App/App.iOS/AppDelegate.cs:34
  at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
  at Moonshot.App.iOS.Application.Main (System.String[] args) [0x00001] in /Users/jjaehrig/repo/moonshot/src/App/App.iOS/Main.cs:19

@juwens
Copy link
Author

juwens commented Mar 22, 2021

While I'm currently creating a sample app, I noticed that I'm having trouble to reproduce the problem.
Maybe it's a combination of Nuget-Packages in our production app.

@filipnavara
Copy link
Member

filipnavara commented Mar 22, 2021

It's exactly the same error as the ones linked from dotnet/macios#10928. I do have a repro app, several of them in fact.

@filipnavara
Copy link
Member

The triggering combination is usually a library that targets netstandard2.0 and references NuGet package System.Memory. This library can be a local one or a NuGet one. Once you include this library from Xamarin.Mac/iOS project it incorrectly overrides the built-in System.Memory.dll (version 4.0.99.0) with the one from the NuGet (version 4.0.1.1). The one from the NuGet is not meant to be used with Xamarin and causes errors at runtime for certain usage (but not always, some methods are self contained).

@juwens
Copy link
Author

juwens commented Mar 22, 2021

Thanks a lot :)

@juwens juwens closed this as completed Mar 22, 2021
@juwens
Copy link
Author

juwens commented Mar 22, 2021

@filipnavara all of our shared libs are netstandard2.0

Do you have another hint where to look at? I'm somewhat lost.

I've greped for 4.0.1.1, but found only these entries in the deps.json

      "System.Memory/4.5.4": {
        "dependencies": {
          "System.Buffers": "4.5.1",
          "System.Numerics.Vectors": "4.4.0",
          "System.Runtime.CompilerServices.Unsafe": "5.0.0"
        },
        "runtime": {
          "lib/netstandard2.0/System.Memory.dll": {
            "assemblyVersion": "4.0.1.1",
            "fileVersion": "4.6.28619.1"
          }
        }
      },

dotnet restore -v d | grep System.Memory mentions no 4.0.1.1

         (in) PackageReferences 'StyleCop.Analyzers;NETStandard.Library;AsyncAwaitBestPractices.MVVM;Rg.Plugins.Popup;Serilog.Extensions.Logging;Serilog.Sinks.File;Serilog.Sinks.Trace;Com.Airbnb.Xamarin.Forms.Lottie;Microsoft.AppCenter;Microsoft.AppCenter.Analytics;Microsoft.AppCenter.Crashes;Microsoft.AppCenter.Distribute;Microsoft.Extensions.DependencyInjection;Microsoft.Extensions.Hosting;Microsoft.Extensions.Logging;System.Reactive.Core;System.Text.Json;Xam.Plugin.SimpleAudioPlayer;Xamarin.CommunityToolkit;Xamarin.Forms;Xamarin.Essentials;System.Memory'
         Checking compatibility for System.Memory 4.5.4 with .NETCoreApp,Version=v3.1.
         Checking compatibility for System.Memory 4.5.0 with .NETStandard,Version=v2.0.
         Checking compatibility for System.Memory 4.5.4 with .NETStandard,Version=v2.0.
         Checking compatibility for System.Memory 4.5.4 with .NETStandard,Version=v2.0.
         Checking compatibility for System.Memory 4.5.4 with .NETStandard,Version=v2.0.
         Checking compatibility for System.Memory 4.5.4 with .NETStandard,Version=v2.0.
         Checking compatibility for System.Memory 4.5.4 with .NETStandard,Version=v2.0.
         Checking compatibility for System.Memory 4.5.3 with .NETCoreApp,Version=v3.1.
         Checking compatibility for System.Memory 4.5.3 with .NETCoreApp,Version=v3.1.
         Checking compatibility for System.Memory 4.5.3 with .NETCoreApp,Version=v3.1.

@juwens
Copy link
Author

juwens commented Mar 22, 2021

I guess binlog is good point to start, if the above are not helpful.

Looking for things like this?

image

and

image

@juwens juwens reopened this Mar 22, 2021
@ericstj
Copy link
Member

ericstj commented Mar 22, 2021

@juwens we understand what's going on and @filipnavara's fix should address this.

One thing that seems to happen (occured for me when I tried to reproduce this) was that Xamarin's ImplicitlyExpandDesignTimeFacades was not running and adding System.Memory to the build. You could workaround this by either adding <Reference Include="System.Memory" /> (what should happen after the fix) or by explicitly setting <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime> property. I wasn't sure why Xamarin's ImplicitlyExpandDesignTimeFacades target wasn't running for me, as I would have expected it here. THat might be something to look at @filipnavara

@ghost ghost locked as resolved and limited conversation to collaborators Apr 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants