Page 1 of 1
KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)
Posted: Sun Feb 05, 2023 11:20 pm
by darkdragon
Still the issue appears in generated code (Lang.cs) , not in user code:
KeyNotFoundException: The given key 'value' was not present in the dictionary.
ASPNETMaker2023.Models.EvOLT_2_0+Lang+<>c.<PhrasesToJson>b__36_1(KeyValuePair<string, object> kvp) in Lang.cs
+
.ToDictionary(kvp => kvp.Key, kvp => (string)kvp.Value["value"]);
System.Linq.Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
System.Linq.Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
Re: ANM2023, converted project fails to start
Posted: Mon Feb 06, 2023 6:58 am
by MichaelG
- Make sure that you have deleted all files/folders in the destination folder manually first, and then regenerate all files and folders again.
- This may be related to your other topic: viewtopic.php?t=55502.
Re: KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)
Posted: Mon Feb 06, 2023 10:07 pm
by darkdragon
OK, problem is in the translation file. Switching the default language to English, app works with no issue.
Re: KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)
Posted: Tue Feb 07, 2023 6:20 pm
by darkdragon
Any idea how to capture the exact phrase which is failing?
Ay some point I have identified a phrase which was missing the "value" attribute, but that was not an issue on an another project which renders ok my translated language.
Re: KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)
Posted: Tue Feb 07, 2023 7:22 pm
by MichaelG
You can always turn on Tools -> Advanced Settings -> Debug to find more info.
Re: KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)
Posted: Tue Feb 07, 2023 10:00 pm
by darkdragon
It was from the phrase with missing value attribute, in translation file.
An idea to update the PhrasesToJson method in Lang.js, to filter out pharses without "value":
// Output phrases as JSON
public async Task PhrasesToJson(dynamic phrases)
{
Dictionary<string, string> dict = ((Dictionary<string, dynamic>)phrases)
.Where(kvp => kvp.Value["value"] != null)
.ToDictionary(kvp => kvp.Key, kvp => (string)kvp.Value["value"]);
foreach (var (key, value) in dict) {
await _writer.WritePropertyNameAsync(key);
await _writer.WriteValueAsync(value);
}
}
Thanks for your time!