Open matt-psaltis opened 2 years ago
And then after the array is removed, running dnt switch-to-packages
thows this exception:
System.InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token)
at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable`1 value)
at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable`1 value)
at Dnt.Commands.Packages.Switcher.SingleOrArrayConverter.<>c.<ReadJson>b__1_1(JProperty val) in C:\projects\dnt\src\Dnt.Commands\Packages\Switcher\SingleOrArrayConvertor.cs:line 25
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Dnt.Commands.Packages.Switcher.SingleOrArrayConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\projects\dnt\src\Dnt.Commands\Packages\Switcher\SingleOrArrayConvertor.cs:line 25
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(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at Dnt.Commands.Packages.Switcher.ReferenceSwitcherConfiguration.Load(String fileName, IConsoleHost host) in C:\projects\dnt\src\Dnt.Commands\Packages\Switcher\ReferenceSwitcherConfiguration.cs:line 43
at Dnt.Commands.Packages.SwitchProjectsToPackagesCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\dnt\src\Dnt.Commands\Packages\SwitchProjectsToPackagesCommand.cs:line 22
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.Process(String[] args, Object input)
at Dnt.Program.Main(String[] args) in C:\projects\dnt\src\Dnt\Program.cs:line 33
Current workaround is to manually modify switcher.json
again and add the arrays.
A workaround seems to be to make sure you have no single-item arrays by duplicating single entries. It does then get added to the .csproj
twice but Visual Studio handles it.
{
"solution": "All.sln",
"mappings": {
"Package1": [
"Path1/Package1.csproj",
"Path1/Package1.csproj" <- duplicate
],
"Package2": [
"Path2/Module1/Package2.csproj",
"Path2/Module2/Package2.csproj",
]
}
}
After executing a switch-to-projects the json is modified to: