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

Enabling "PublishSingleFile" may causes "ResourceManager.Current" to throw an error #9836

Closed
NXY666 opened this issue Jul 14, 2024 · 3 comments
Labels
area-ProjectSystem team-Markup Issue for the Markup team

Comments

@NXY666
Copy link

NXY666 commented Jul 14, 2024

Describe the bug

When I tried to enable "PublishSingleFile" and attempted to publish it as a single executable file, an error occurred when accessing ResourceManager.Current:

Unable to find the specified file.
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32)
   at ABI.Windows.ApplicationModel.Resources.Core.IResourceManagerStaticsMethods.get_Current(IObjectReference)
   at Windows.ApplicationModel.Resources.Core.ResourceManager.get_Current()
   at Demo.MainWindow..ctor() in E:\Projects\Demo\MainWindow.xaml.cs:line 17

Steps to reproduce the bug

  1. Enable the PublishSingleFile option in win-x64.pubxml
  2. In the constructor of MainWindow, write the following code:
public partial class MainWindow
{
    public MainWindow()
    {
        string filePath = @"D:\demo.txt";

        try
        {
            var curr = ResourceManager.Current;
        } catch(Exception e)
        {
            File.WriteAllLines(filePath, [e.Message, e.StackTrace]);
        }
    }
}
  1. Open this window on OnLaunched:
    protected override void OnLaunched(LaunchActivatedEventArgs args)
    {
        MWindow = new MainWindow();
        MWindow.ExtendsContentIntoTitleBar = true;
        MWindow.Activate();
    }
  1. Publish, then run the exe and check the output errors in the root directory of the D drive:
Unable to find the specified file.
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32)
   at ABI.Windows.ApplicationModel.Resources.Core.IResourceManagerStaticsMethods.get_Current(IObjectReference)
   at Windows.ApplicationModel.Resources.Core.ResourceManager.get_Current()
   at Demo.MainWindow..ctor() in E:\Projects\Demo\MainWindow.xaml.cs:line 17

Expected behavior

No response

Screenshots

No response

NuGet package version

Windows App SDK 1.5.5: 1.5.240627000

Packaging type

Unpackaged

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

This is the code mentioned above:
Demo.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jul 14, 2024
@lhak
Copy link

lhak commented Jul 16, 2024

I think the ResourceManager from the Microsoft.Windows.ApplicationModel.Resources namespace will work with single file publishing.

@codendone codendone transferred this issue from microsoft/WindowsAppSDK Jul 18, 2024
@codendone codendone added area-ProjectSystem team-Markup Issue for the Markup team and removed needs-triage Issue needs to be triaged by the area owners labels Jul 18, 2024
@NXY666
Copy link
Author

NXY666 commented Jul 20, 2024

I think the ResourceManager from the Microsoft.Windows.ApplicationModel.Resources namespace will work with single file publishing.

Thank you very much!

After replacing it with the ResourceManager you mentioned, it worked. I spent several months looking for a solution. 😂

@Scottj1s
Copy link
Member

@NXY666 Thanks for reporting this, and @lhak thanks for the solution. Closing issue as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ProjectSystem team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

4 participants