ikvmnet / ikvm-maven

Support for adding dependencies on Maven artifacts to .NET projects, using IKVM.
MIT License
53 stars 5 forks source link

An exception should not occur when adding maven references with big dependency graphs #47

Closed REscobar closed 11 months ago

REscobar commented 11 months ago

When adding some maven references with big dependencies graphs a JsonReaderException is thrown

Steps to reproduce:

An exception similar to this one will be thrown:

Severity    Code    Description Project File    Line    Suppression State
Error       JsonReaderException: The reader's MaxDepth of 64 has been exceeded. Path 'graph.children[0].children[2].children[21].data[0].value.children[4].data[0].value.children[8].data[0].value.children[5].data[0].value.children[0].data[0].value.children[0].data[0].value.children[0].data[0].value.children[1].data[0].value.children[0].data[0].value.children[0].data[0].value.children[1].data[0].value.children[0].dependency.artifact', line 46194, position 141.
   at Newtonsoft.Json.JsonReader.Push(JsonContainerType value)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
   at IKVM.Maven.Sdk.Tasks.Aether.DefaultDependencyNodeJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\w\ikvm-maven\src\IKVM.Maven.Sdk.Tasks\Aether\DefaultDependencyNodeJsonConverter.cs:line 29
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
   at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.TryReadCacheFile() in C:\w\ikvm-maven\src\IKVM.Maven.Sdk.Tasks\MavenReferenceItemResolve.cs:line 119
   at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.ResolveCompileDependencyGraphFromCache(IkvmMavenEnvironment maven, IList`1 dependencies) in C:\w\ikvm-maven\src\IKVM.Maven.Sdk.Tasks\MavenReferenceItemResolve.cs:line 291
   at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.ResolveCompileDependencyGraph(IkvmMavenEnvironment maven, RepositorySystemSession session, IList`1 repositories, IList`1 items) in C:\w\ikvm-maven\src\IKVM.Maven.Sdk.Tasks\MavenReferenceItemResolve.cs:line 245
   at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.ResolveReferences(IList`1 repositories, IList`1 items) in C:\w\ikvm-maven\src\IKVM.Maven.Sdk.Tasks\MavenReferenceItemResolve.cs:line 195
   at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.Execute() in C:\w\ikvm-maven\src\IKVM.Maven.Sdk.Tasks\MavenReferenceItemResolve.cs:line 153
    IkvmMavenCacheException C:\Users\xxxxxxxx\.nuget\packages\ikvm.maven.sdk\1.6.3\buildTransitive\IKVM.Maven.Sdk.targets   96  

Other notes: adding this dependency creates a ~72MB cache file, I don't know if this is relevant

wasabii commented 11 months ago

Oh geeze. I'll take a look.

wasabii commented 11 months ago

I'm going to increase the max depth for now. But, long term, I would much rather have a different format for the cache file. The JSON thing was just the easiest solution available at the time.

REscobar commented 11 months ago

Can this be made configurable with the same current default, so the current behavior is not changed and also allow to tune it for other unforeseen scenarios?

wasabii commented 11 months ago

I don't see why. There's a legit max depth for this use case. As long as this isn't a circular dependency or something.

wasabii commented 11 months ago

Ya know that's probably a thing to check. Make sure this isn't a circular dependency.

REscobar commented 11 months ago

The cache file does get saved to disk, the exception occurs when it's read back.

I can upload the generated file if it helps

wasabii commented 11 months ago

Naw that's fine.

I'm also taking this chance to convert this to System.Text.Json.

wasabii commented 11 months ago

Alright, new commit to main, will release shortly after testing.

Changes: