runtime: net6.0 preview 4 "Entry point was not found." exception when PublishReadyToRun with old Newtonsoft.Json 9.0.1
Description
Using an older version of Newtonsoft.Json 9.0.1 results in an “Entry point was not found.” exception after a PublishReadyToRun publish.
With the latest version 13.0.1 of Newtonsoft.Json it works correctly or when PublishReadyToRun is false.
Configuration
- Which version of .NET is the code running on?
6.0.100-preview.4.21255.9(I also tried out the daily6.0.100-preview.6.21301.1build which resulted in the same exception) - What OS and version, and what distro if applicable?
win - What is the architecture (x64, x86, ARM, ARM64)?
x64 - Do you know whether it is specific to that configuration? no
Regression?
Yes, with net6.0 preview 3 this worked.
Other information
csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Platform>x64</Platform>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows10.0.19041</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<SelfContained>true</SelfContained>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>
</Project>
Program.cs
using System;
namespace EntryPointNotFound
{
class Program
{
static void Main(string[] args)
{
try
{
Newtonsoft.Json.Linq.JToken token = Newtonsoft.Json.Linq.JToken.Parse("{}");
var result = token.ToObject<object>();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
Console.Read();
}
}
}
Publish with: dotnet publish -c Release
Console output when running the published exe:
Entry point was not found.
at System.Collections.Generic.IEnumerable`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) in System.Private.CoreLib.dll:token 0x60065c5+0x5c
at Newtonsoft.Json.Utilities.ReflectionUtils.GetFields(Type targetType, BindingFlags bindingAttr) in Newtonsoft.Json.dll:token 0x6000431+0x0
at Newtonsoft.Json.Utilities.ReflectionUtils.GetFieldsAndProperties(Type type, BindingFlags bindingAttr) in Newtonsoft.Json.dll:token 0x6000428+0x0
at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers(Type objectType) in Newtonsoft.Json.dll:token 0x60004b0+0xa
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization) in Newtonsoft.Json.dll:token 0x60004cc+0x0
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType) in Newtonsoft.Json.dll:token 0x60004b2+0xe
at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType) in Newtonsoft.Json.dll:token 0x60004c7+0xc9
at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type) in Newtonsoft.Json.dll:token 0x60004af+0x38
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in Newtonsoft.Json.dll:token 0x60005df+0xe
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in Newtonsoft.Json.dll:token 0x6000152+0x45
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer) in Newtonsoft.Json.dll:token 0x600093e+0x11
at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType) in Newtonsoft.Json.dll:token 0x600093c+0x2c8
at Newtonsoft.Json.Linq.JToken.ToObject[T]() in Newtonsoft.Json.dll:token 0x600093b+0x0
at EntryPointNotFound.Program.Main(String[] args) in C:\Users\xxx\source\repos\EntryPointNotFound\EntryPointNotFound\Program.cs:line 11
Reference https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/issues/1284
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (25 by maintainers)
Commits related to this issue
- Fix for bug #53520, Entry point not found Manish investigated this issue and he found out that the problem is caused by the fact that in the method Newtonsoft.Json.Utilities.ReflectionUtils.GetField... — committed to trylek/runtime by trylek 3 years ago
- Fix for bug #53520, Entry point not found Manish investigated this issue and he found out that the problem is caused by the fact that in the method Newtonsoft.Json.Utilities.ReflectionUtils.GetField... — committed to trylek/runtime by trylek 3 years ago
- Fix for bug #53520, Entry point not found (#53772) Manish investigated this issue and he found out that the problem is caused by the fact that in the method Newtonsoft.Json.Utilities.ReflectionUt... — committed to dotnet/runtime by trylek 3 years ago
- Remove PublishReadyToRunUseCrossgen2 = false workaround as the underlying issue has been fixed: https://github.com/dotnet/runtime/issues/53520 — committed to campersau/NuGetPackageExplorer by campersau 3 years ago
Tested with a crossgen2 build from today (6.0.0-preview.6.21306.9) and I couldn’t repro. I could if I used preview 4 bits.