Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundException #4

Open
kfrancis opened this issue Feb 3, 2023 · 20 comments
Open

FileNotFoundException #4

kfrancis opened this issue Feb 3, 2023 · 20 comments

Comments

@kfrancis
Copy link

kfrancis commented Feb 3, 2023

We have just an English and a French, but in trying to use this project we're getting an exception:

.UseLocalizationResourceManager(settings =>
{
    settings.AddResource(AppResources.ResourceManager);
    settings.RestoreLatestCulture(true);
});

This is the exception:
{System.IO.FileNotFoundException: File name: 'CabMdMobile.Maui.resources' at System.Reflection.Assembly.Load(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext) at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(Assembly assembly, CultureInfo culture, Version version, Boolean throwOnFileNotFound)}

Not really sure why it's having a problem. The files are in the same place as your example, have the same name "AppResources", the settings for the files in the csproj seem to be the same as your sample as well.

@SirJohnK
Copy link
Owner

SirJohnK commented Feb 3, 2023

Strange. I have tried to recreate this, but I can not find any scenario where I get that exception.
Closest I have come is when using File based ResourceManager with AddFileResource.
Almost seems like the Resources file (DLL) has not been created. If that is the case, clean and rebuild should fix it.

If not, Try to recreate resources files.

  • Remove all resx files
  • Create new "Resources File" with the "Add New Item" Template(!) and name it "AppResources.resx"
  • Create a second "Resources File" with the Template(!) in the same location with the name "AppResources.fr.resx"
  • Add the Original texts in the first file and the French texts in the second file.
  • Verify "UseLocalizationResourceManager" settings.

This should work!

@kfrancis
Copy link
Author

kfrancis commented Feb 6, 2023

Actually, looks like it might be a MAUI bug. dotnet/maui#7443 (comment)

@SirJohnK
Copy link
Owner

SirJohnK commented Feb 6, 2023

Oh, it sounds like your problem. Does it work if you disable the "Fast Deployment" setting? (I need to verify my sample project and see if I get it!)

@arahmancsd
Copy link

This is happening to me with this package in Windows 10 VS 2022 17.5.3. However, the same project compiles and works fine in MAC.

The sample project also doesn't work in Windows but works in MAC.

@SirJohnK
Copy link
Owner

@arahmancsd , so to understand.

  • You successfully compile sample project in VS2022 in Windows?
  • You deploy/run sample project with "Windows Machine" as target and you get "FileNotFoundException" on the resource file?
  • If not, please describe every step.

@arahmancsd
Copy link

arahmancsd commented May 17, 2023

@arahmancsd , so to understand.

  • You successfully compile sample project in VS2022 in Windows?
  • You deploy/run sample project with "Windows Machine" as target and you get "FileNotFoundException" on the resource file?
  • If not, please describe every step.

@SirJohnK thanks,
I am getting this error when running my project in Windows targeting Android and iOS.
Surprisingly, I unchecked System.Exception from Debug menu and the project is working.
Additionally, if you continue (F5) with the exception, the project keeps working.
In both scenarios, the resource manager works fine.

In terms of exception, it is the same as stated in the question.

I have no idea at the moment If I can have a release build with that exception, but can check that later.

@SirJohnK
Copy link
Owner

SirJohnK commented May 17, 2023

@arahmancsd , I am really trying, but I can not recreate this issue!

  • Let's focus on the sample application from this repository!
  • Remove all local versions.
  • Fork/download the latest version of this repo.
  • Build entire solution and try to launch sample app with Android target.
  • What happens? (Please be detailed in your description! Emulator, Device, API level etc.)

My setup:

  • Windows 10
  • Visual Studio 2022, v17.5.5
  • Android Emulator, Pixel 5, Android 12.1 / API 32
  • Hardware Device, Zebra, Android 10 / API 29

@arahmancsd
Copy link

@SirJohnK to give you a bit more detail. Here is an exception happening in the AddResource function in the forked sample project.

{System.IO.FileNotFoundException: File name: 'LocalizationResourceManager.Maui.Sample.resources' at System.Reflection.Assembly.Load(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext) at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(Assembly assembly, CultureInfo culture, Version version, Boolean throwOnFileNotFound)}

My setup is;

Windows 10 v22H2 b:19045.2965
Visual Studio 2022, v17.5.3
Android Emulator: Pixel 5 Android 13.0 / API 33

Screenshot 2023-05-17 155550

Untitled

@SirJohnK
Copy link
Owner

@arahmancsd , this is really strange!

Why does this work without any problem for me and most other users?
The only thing I can come up with is that is something is different with your setup.

  • Try to update to the latest version of VS 2022 (Currently 17.5.5)
  • Try to disable the Android "Fast deployment" options setting for the sample project. (see image)

image

Hope it helps!

@arahmancsd
Copy link

@SirJohnK I have the latest VS and latest workloads. The release also crashes at startup in iOS, couldn't check it in Android yet. My project is XF upgraded to MAUI.

@SirJohnK
Copy link
Owner

SirJohnK commented Jun 4, 2023

@arahmancsd , do you still have the same issue with the sample project from this repo, built with VS2022 on Windows?

@arahmancsd
Copy link

@SirJohnK I am experiencing the same error attached earlier with the latest VS 2022 on Windows 10.

@SirJohnK
Copy link
Owner

SirJohnK commented Jun 8, 2023

@arahmancsd , can you clone or fork the library and test to add it to your solution and remove/comment out the verification row?

resource.GetString(string.Empty);

I added that row for file verification and maybe(!) sometimes the file is not accessible at that time.
If this works, I will update the library att remove or move the check.

@FrankVDL2471
Copy link

Disabling fast deploy does not work for me.
Any solution for this ?

@SirJohnK
Copy link
Owner

@FrankVDL2471 , I would really like to get to the bottom of this! Unfortunately I have never been able to recreate this issue.

  • Can you build and run the sample project?
  • and/or can you create and recreate this in a test project, that you can share?
  • What is your exact setup when getting this issue? (Build machine, target OS, device/emulator/simulator, Langague settings etc)

@FrankVDL2471
Copy link

FrankVDL2471 commented Oct 23, 2023 via email

@SirJohnK
Copy link
Owner

SirJohnK commented Oct 24, 2023

@FrankVDL2471 , ok.

  • Could you please try to analyze what is the difference between your project and new Maui project?
  • How did you create / convert your project? If possible, be specific so I can try to recreate this.
  • Any chance you could try to recreate the steps you made in your project in a new project that has the same problem and that you can share?

@FrankVDL2471
Copy link

FrankVDL2471 commented Oct 26, 2023

It seems the issue might be a bit bigger.
Just found out that when running my code on an actual device, also the resourcedictionaries for the styles are triggering the same error.

I've removed all the resx files from my project , but still get the same error.
In my log I can see this

Loaded assembly: /data/data/com.notokenapp.sjwing/files/.__override__/System.Text.Encoding.Extensions.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly nl-BE/System.Private.CoreLib.resources.dll
[monodroid-assembly] open_from_bundles: failed to load assembly nl-BE/System.Private.CoreLib.resources.dll
[monodroid-assembly] open_from_bundles: failed to load assembly nl-BE/System.Private.CoreLib.resources.dll
[monodroid-assembly] open_from_bundles: failed to load assembly nl-BE/System.Private.CoreLib.resources.dll
**System.IO.FileNotFoundException:** ''

[monodroid-assembly] open_from_bundles: failed to load assembly nl/System.Private.CoreLib.resources.dll
[monodroid-assembly] open_from_bundles: failed to load assembly nl/System.Private.CoreLib.resources.dll
[libc] Requested dump for pid 20232 (tokenapp.sjwing)

@monsterkeks
Copy link

monsterkeks commented Nov 14, 2023

As additional info to @SirJohnK - we're facing the same issue in every localized (multi-project) solution. That issue is only happening to us, when deploying in DEBUG Mode to a physical device. When deploying to an emulator, without the setting Break When Thrown for CLR Exceptions, the problem occurs, but is transparent. Disabling Fast Deployment doesn't solve that problem. Out commenting the probing neither:

public bool AddResource(ResourceManager resource)
{
    try
    {
        //Verify access by attempting to get empty string
        //resource.GetString(string.Empty);

        //Access attempt was successful!
        resources.Add(resource);

        //Return successful status
        return true;
    }
    catch (Exception)
    {
        //Access attempt was not successful!
        return false;
    }
}

For debugging we copied the LocalizationResourceManager into our project. It looks, like it happens when resolving the resource in the GetValue-method:

image

Everything is there and loaded correctly, but under the hood, that exception is thrown. I've found a bunch of related Maui issues, but none of them gave us workaround for that. This one is the most likely related and merged to 7.0.1xx, but doesn't solve the problem. Currently we're on Maui 7.0.101.

For us this is quite anoying, because we've to debug on a physical device for network related stuff, which isn't available on an emulator.

@LeoJHarris
Copy link

Just started facing the same issue: **System.IO.FileNotFoundException:** glad this has been resolved and will be waiting on the new release 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants