KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
darkdragon
User
Posts: 149

KeyNotFoundException: The given key 'value' was not present in the dictionary (v2023)

Post 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)

MichaelG
User
Posts: 1103

Post by MichaelG »

  1. Make sure that you have deleted all files/folders in the destination folder manually first, and then regenerate all files and folders again.
  2. This may be related to your other topic: viewtopic.php?t=55502.

darkdragon
User
Posts: 149

Post by darkdragon »

OK, problem is in the translation file. Switching the default language to English, app works with no issue.


darkdragon
User
Posts: 149

Post 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.


MichaelG
User
Posts: 1103

Post by MichaelG »

You can always turn on Tools -> Advanced Settings -> Debug to find more info.


darkdragon
User
Posts: 149

Post 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!


Post Reply