I am converting my Xamarin Forms Application to .NET MAUI.
In existing application I am using below code which is using Xamarin.iOS to fetch the config file(App.config) which is in xml format and has app settings
public string Path
{
get
{
try
{
return System.AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
}
catch
{
throw new FileNotFoundException(@"File not found.");
}
}
}
But the same code doesn't work in MAUI
I tried below approach but File.OpenRead(Path) is throwing error "Data at the root level is invalid. Line 1, position 1" App.config file is added in path Projectname/Platforms/iOS/App.config
public string Path
{
get
{
try
{
string configPath = string.Empty;
configPath = Assembly.GetEntryAssembly().Location + ".config";
AppDomain domain = System.AppDomain.CurrentDomain;
configPath = System.IO.Path.Combine(domain.SetupInformation.ApplicationBase, domain.FriendlyName + ".config");
return configPath;
}
catch
{
throw new FileNotFoundException(@"File not found.");
}
}
}
Any help is appreciated!