Xamarin & XPO System.NotSupportedException: Encoding 1252 data could not be found. Make sure you have correct international codeset assembly installed and enabled.

Xamarin & XPO System.NotSupportedException: Encoding 1252 data could not be found. Make sure you have correct international codeset assembly installed and enabled.

You know that moment when you are about to deliver your next mobile app, everything is working fine in your development environment but once you release the app to your customers you start getting errors like the one below

You think, what happened? everything was running fine on my development environment. Well, lets said that when you compile your Xamarin application the main goal of the compiler and the linker is reduced the size of the app, so a lot of things get stripped out of the final release.

Some of the things that are stripped out of the final release are the code pages and that can cause crashes in your app not because your code depends on them but because of some nugets or third-party libraries do.

So to avoid having the exception “System.NotSupportedException: Encoding 1252 data could not be found. Make sure you have correct international codeset assembly installed and enabled” you just need to explicitly add code page to your application

For iOS projects, include it by checking west under Project Properties -> iOS Build -> Internationalization:

 

For Android projects, include it by checking west under Project Properties -> Android Build -> Linker -> Internationalization:

For visual studio for windows here are the screenshots

iOS

Android

The credit goes to this post, that saved my life fixing this error StackOverflow

 

Xamarin Forms UWP / UAP Broad File System Access (Permissions)

For a long time now, I have wanted to access the file system when I create a Xamarin Forms UAP/UWP application but that was actually impossible … till now. After the Windows 10 build 17134 update its possible to access the broad file system, the approach is not straight forward.

To gain access to the file system in your Xamarin Forms UAP/UWP application follow these steps

1) Go the properties of your UAP/UWP application and check the targeting, the minimum should be at least 16299, what I recommend is 171344

You can also change the targets unloading the project and editing the csproj file

2) In your solution explorer edit your Package.appxmanifest by selecting it and press F7, looking the file from the top should look like the image below

Add this namespace xmlns:rescap=”http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities and update the IgnorableNamesSpaces like this IgnorableNamespaces=”uap mp rescap” after the changes your file should look like the image below

3) Lookup for the capabilities node in the manifest and add a new capability  <rescap:Capability Name=”broadFileSystemAccess” /> your capabilities section should look like the image below

4) Rebuild your application, then select it on the solution explorer, right click over it and click on deploy, this will register the application in your OS

5) on your Windows OS go to settings>File system privacy settings and you will see all the UAP/UWP applications that are registered  in your OS and have access to the file system, here you can allow/deny the access to the file system in general or by application

6) now everything is ready for your app to access the file system, but there is a little catch, in most cases, you cannot use the classes in system.io to access the file system you have to use Windows.Storage.Storagefolder below is a code snippet that illustrates how to use such class

public async void GetDirectories(string sDir)
{
    
    var folder = await StorageFolder.GetFolderFromPathAsync(sDir);   
    foreach (var file in await folder.GetFilesAsync())
    {
        Debug.WriteLine(file.Name);
        
    }

}

 

I have created a sample app using these steps, you can download the source from GitHub