SCENARIO
I am using .Net Maui 9.0 Preview, Blazor Hybrid Web App.
I need to initiate some code before the project starts (or in parallel) but it must display on home page after fetching it from some files.
This code must work as Maui App (for Android, iOS, Mac) and as a Web App.
That is why, I am initiating the services in the MainLayout.razor.cs ( I added MainLayout.razor.cs) file, because I didn't find any where else to start (entrypoint to the apps)!?!
THE PROBLEM
Couple of tasks which must be completed first, It is working fine on Maui Apps side. But it gives an error when running it on Web App.
ERROR
Microsoft.Maui.ApplicationModel.NotImplementedInReferenceAssemblyException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
(Full Log is attached) ErrorLog.txt
Full Code (solution) is attached MauiApp5.zip
CODE
public class MyFileAccess
{
private string jsonDataFileName = "Resources/Raw/languages.json";
public async Task<ObservableCollection<T>> ReadJsonDataAsync<T>()
{
ObservableCollection<T>? genericTypeList = new();
Debug.WriteLine(FileSystem.AppDataDirectory);
var isExist = await FileSystem.Current.AppPackageFileExistsAsync(jsonDataFileName);
if (isExist)
{
var stream = await FileSystem.Current.OpenAppPackageFileAsync(jsonDataFileName);
var reader = new StreamReader(stream);
var contents = await reader.ReadToEndAsync();
genericTypeList = JsonSerializer.Deserialize<ObservableCollection<T>>(contents);
}
return genericTypeList!;
}
}
The documentation link suggests that it is part of Microsoft.Maui.Storage (and includes Maui.Essentials). Not sure what (which assembly) am I missing?