Skip to content

FileNotFoundException when loading resx file #13784

Closed as not planned
Closed as not planned

Description

@williambuchanan2

Description

I have a resx file which is in a maui assembly (i.e. not the main application, but another maui assembly in the solution).

It has worked fine up until 2 days ago. Now when I try to access it I get a System.IO.FileNotFoundException.

Nothing has changed in the code surrounding it for several months so I am confused as to why the file can't be found.

Steps to Reproduce

  1. Create a maui project.
  2. Add a second maui project to the solution.
  3. Add a resx file to the second project and try to read a string from it in the first project.
  4. Error gets thrown.

Link to public reproduction project repository

?

Version with bug

7.0 (current)

Last version that worked well

7.0 (current)

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

net7.0

Did you find any workaround?

No

Relevant log output

No response

Activity

  1. added
    t/bug
    on Mar 9, 2023
  2. jfversluis commented on Mar 9, 2023

    @jfversluis
    Member

    Without any form of binlog, logs, or reproduction this will be pretty much impossible to diagnose.

    It would be super helpful if you could still try to setup a project that exhibits this behavior for you, put that in a GitHub repo so we can see how it behaves on our end. Or, at the very least, compile your app and produce a binlog file that you can give us so we can see what is going on during that process.

  3. added
    s/needs-repro
    on Mar 9, 2023
  4. williambuchanan2 commented on Mar 10, 2023

    @williambuchanan2
    Author

    Unfortunately i'm not going to be able to provide an example. I just tried to create an example app and it worked ok. The problem is something which has now happened in both our Maui apps that we have in development, and both had a similar pattern - i.e. worked ok then one day just stopped working. Even creating new res files in the main project doesn't work. It is like the build has stopped copying the files into the output.

    At the moment i'm dealing with so many Maui issues that I don't have any more time to invest in this, so i'll just stop using resource files for now.

  5. ghost added
    s/needs-attention
    on Mar 10, 2023
  6. ghost removed
    s/needs-repro
    on Mar 10, 2023
  7. williambuchanan2 commented on Mar 10, 2023

    @williambuchanan2
    Author

    Probably related, I have another XML file in the project which I set as an embedded resource, and probably around 50% of the time when I run the app I get an error saying that file isn't found. So I do a rebuild and run and then it works again for a while.

  8. drasticactions commented on Mar 14, 2023

    @drasticactions
    Contributor

    If you try the same thing from a straight .NET Android app (dotnet new android) does the same exception occur?

  9. added
    s/needs-info
    and removed
    s/needs-attention
    on Mar 14, 2023
  10. Eilon commented on Mar 14, 2023

    @Eilon
    Contributor

    Add a resx file to the second project and try to read a string from it in the first project.

    Can you share more info about how it was added? Is it added as an embedded resource? Or as a MauiAsset? Can you show the relevant part (if any) of the CSPROJ?

  11. williambuchanan2 commented on Mar 14, 2023

    @williambuchanan2
    Author

    Here is the how the file is in the project:

    <ItemGroup>
      <EmbeddedResource Update="RedSixResource.resx">
        <Generator>PublicResXFileCodeGenerator</Generator>
        <LastGenOutput>RedSixResource.Designer.cs</LastGenOutput>
      </EmbeddedResource>
    </ItemGroup>
    

    image

  12. ghost added
    s/needs-attention
    on Mar 14, 2023
  13. ghost removed
    s/needs-info
    on Mar 14, 2023
  14. Eilon commented on Mar 14, 2023

    @Eilon
    Contributor

    try to read a string from it in the first project

    And how exactly is it being read from the other project? Can you show a code snippet that shows how the project with the RESX file is being "located", as well as how the resource is being read from within it?

    For example, is the code trying to find the DLL on disk and open up the resource? Or is it following a reference via a type, and then using some resource APIs?

  15. added
    s/needs-info
    and removed
    s/needs-attention
    on Mar 14, 2023
  16. williambuchanan2 commented on Mar 14, 2023

    @williambuchanan2
    Author

    The project containing the resx file is just referenced through the 'Add Project Reference' dialog. The code is reading from the file like this:

    string sms = RedSixResource.SMS_Verify;

    I just tried changing it to MauiAsset but get the same error.

    Here is a full screen dump of the error.

    image

  17. ghost added
    s/needs-attention
    on Mar 14, 2023
  18. ghost removed
    s/needs-info
    on Mar 14, 2023
  19. Eilon commented on Mar 15, 2023

    @Eilon
    Contributor

    I tried reproducing this, but once I added a 2nd MAUI project that referenced the first, I can't even build the new 2nd project because of this error (or errors like it):

    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(352,9): warning : More than one 'MauiSplashScreen' is defined; only the first will be used.
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): warning : MAUI0000
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): warning : MAUI0000
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: System.IO.IOException: The process cannot access the file 'C:\Users\elipton\source\repos\MauiAppResourceContainer\MauiAppResourceConsumer\obj\Debug\net7.0-android\resizetizer\r\drawable-mdpi\splash.png' because it is being used by another process.
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.SkiaSharpTools.Save(String destination, SKBitmap tempBitmap) in D:\a_work\1\s\src\SingleProject\Resizetizer\src\SkiaSharpTools.cs:line 143
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.SkiaSharpTools.Resize(DpiPath dpi, String destination, Double additionalScale, Boolean dpiSizeIsAbsolute) in D:\a_work\1\s\src\SingleProject\Resizetizer\src\SkiaSharpTools.cs:line 64
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.Resizer.Rasterize(DpiPath dpi, String destination) in D:\a_work\1\s\src\SingleProject\Resizetizer\src\Resizer.cs:line 92
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.Resizer.Resize(DpiPath dpi, String inputsFile) in D:\a_work\1\s\src\SingleProject\Resizetizer\src\Resizer.cs:line 85
    2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.ResizetizeImages.ProcessImageResize(ResizeImageInfo img, DpiPath[] dpis, ConcurrentBag1 resizedImages) in D:\a\_work\1\s\src\SingleProject\Resizetizer\src\ResizetizeImages.cs:line 184 2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.ResizetizeImages.<>c__DisplayClass26_0.<ExecuteAsync>b__0(ResizeImageInfo img) in D:\a\_work\1\s\src\SingleProject\Resizetizer\src\ResizetizeImages.cs:line 86 2>C:\Program Files\dotnet\packs\Microsoft.Maui.Resizetizer.Sdk\7.0.59\targets\Microsoft.Maui.Resizetizer.targets(531,9): error MAUI0000: at Microsoft.Maui.Resizetizer.AsyncTaskExtensions.<>c__DisplayClass0_01.b__0(TSource s) in D:\a_work\1\s\src\SingleProject\Resizetizer\src\AsyncTaskExtensions.cs:line 21

    In my case both projects are MAUI Applications.

    It could be that it's not supported to have one MAUI Application project reference another Application (it's a bit of an unusual thing to do).

    What I would recommend instead is to have a MAUI Library project that contains all the shared items (such as resources, XAML files, etc.) and reference that from each of the two apps.

    Would that work for you instead?

  20. Eilon commented on Mar 15, 2023

    @Eilon
    Contributor

    Here's an amazing diagram I made:

    image

    And I tried it and it works fine: I created two MAUI App projects, and one MAUI Library project. The library project has the RESX file with the public generator in use. Each MAUI App references it and can run with the shared resources.

    This is certainly the recommended approach for sharing code between projects (as opposed to apps referencing each other).

  21. williambuchanan2 commented on Mar 15, 2023

    @williambuchanan2
    Author

    Hi. I have tried moving the resx file up into the main Maui project and I still have the same problem, so that rules out it being related to the 2nd project.

    The fact that you get build errors isn't surprising. That is just a normal every day occurrence for the build to stop working for no reason. Sometimes we have to build 5 or 6 times in a row and delete the bin and obj folders, and/or close and reopen VS to get it to build - so this is nothing new.

    Thanks for the diagram. Just to be clear - I don't have apps referencing each other. We have 2 maui apps in build at the moment and each has a multi tiered design which involves having multiple Maui assemblies in the solution. Everything else works as you would expect.

    As I mentioned above I tried to recreate this in a new project but couldn't repro it. Also, as I mentioned, it worked perfectly for several months and then just suddenly started throwing this error despite there being no changes - so I think it is not easy to reproduce. However, once it stops working it seems that it is gone for good...

  22. Eilon commented on Mar 15, 2023

    @Eilon
    Contributor

    Yeah unfortunately without a reliable way to reproduce I'm not sure how we could try to fix it. If you are able to reproduce again, it could be helpful to get an MSBuild binlog ("binary log") to see what files are being built. You can generate a binlog from a command line build (or from VS). Some more info on that here:

    https://github.com/xamarin/xamarin-macios/wiki/Diagnosis

  23. ghost locked as resolved and limited conversation to collaborators on Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform/androids/needs-attentiont/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions