0
votes

I followed exactly the same from the following guide:

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/text?tabs=windows

I am using code behide to call the localization class directly as the example shown and it is running fine.

But if I run it with debug mode, it will give me File IO NotFound exception saying Invalid Image. (Which I have no idea why)

The guide and google tells me I need to turn off the Fast Deployment in the Android project and which I did. And I am still getting the same exception.

I also followed the guide to try debug by loading the assembly to see if the resource file found and it located without problem.

Anyone facing the same problem?

My resources files is located in my shared .net standard 2.0 project. I am using latest Xamarin Form + Visual Studio 2017.

====================

EDIT:

I found out when it tries to load the localization string, it looks for my device language which is en-CA from dll file locate in the android/bin/debug folder: en-CA/{my project assembly name}.resources.dll

However, I only have two resources file:

  1. Neutral language, which named ClientResource.resx

  2. Japanese, which named ClientResource.ja-JP.resx

I've check all the files in debug folder, the resource dll file only exists under ja-JP/{my project assembly name}.resources.dll

So if I change my device language to Japanese, it will works fine in Debug mode. However any other language it will throw exception instead of using neutral language.

Any idea why it doesn't use neutral language?

2
Did you download this demo and test it your environment? If you will still have this error message? developer.xamarin.com/samples/xamarin-forms/… I test it in my lab running this demo, it is normal. Xamarin.forms version is 3.4.0.1008975,Visual Studio Enterprise 2017 version is 15.9.4; I running demo in android 7.0 and android 8.0 ,both of them are ok.Leon Lu - MSFT

2 Answers

1
votes

I had the exact same issue, and here is the response I got from Xamarin support:

What is happening is that the runtime does search in various locations for the requested resource until it finds a usable resource, in this case it searches for the “en-US” resources (since the device settings are “en-US”) first, then it tries “en”, and if that is not found, it goes to the default. This is why the exception happens twice. The FileNotFoundExceptions are handled by the runtime API verified by the fact that I then tested in Release mode, i.e. no debugger attached, and the app ran fine and the correct text string was displayed. This issue is because you have explicitly requested that the debugger break on the System.IO.FileNotFoundException when you enabled all of the Common Language Runtime Exceptions in the Exception Settings pane. When you do this the debugger will break whether the exception is handled ultimately or not. Therefore the solution to this issue is to uncheck the System.IO.FileNotFoundException in the Exception Settings > Common Language Runtime Exceptions section. After making the above changes, your app works as expected in debug mode.

0
votes

Like Ognjen Sujagic said, the debugger is looking for a localized version of your resx file. So if you're in the US, make a copy of your Strings.resx file and name it Strings.en-US.resx, or use whatever locality you're device is in. Then you should no longer get the exceptions.