I'm having an issue with C# XAML & WinUI3. I am attempting to foreach files:
[ { "path": ".cache",
"type": "DIRECTORY"
},
{ "path": "Cargo.lock"
},
{ "path": "Cargo.toml"
} ]
and then add them to the MenuItems. I get this error:
Exception thrown: 'System.NullReferenceException' in Project.dll Object reference not set to an instance of an object.
If anyone can help quickly, I would appreciate that.
I tried searching other SO posts & attempting ChatGPT. But nothing helped.
CODE:
private void AddNavItems(Google.Protobuf.Collections.RepeatedField<Api.File> files)
{
foreach (var file in files)
{
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
NavigationViewItem item1 = new NavigationViewItem();
item1.Content = file.Path;
item1.Tag = file.Path;
item1.Icon = new SymbolIcon(file.Type == Api.File.Types.Type.Regular ? Symbol.Page2 : Symbol.Folder);
nvSample.MenuItems.Add(item1);
});
}
}