microsoft / microsoft/CsWinRT

Unhelpful HRESULT error messages in .NET

Open
#1,250 13 comments 2 reactions 2 assignees View on GitHub

@mikebattista is already working on this.

Since Dec 14, 2021.

Dominant language
C#
Stars
665
Forks
134
Avg merge
1d 3h
Merged PRs (30d)
32

Description

Describe the bug
Often in .NET we get pretty unhelpful HResult errors. Example:

image

Apparently this means ERROR_MRM_RESOURCE_TYPE_MISMATCH.
It would be nice with better more helpful/meaningful error messages thrown, instead of just an HRESULT.

Steps to reproduce the bug

  1. Create a new WinUI app
  2. Add the following code:
            Microsoft.ApplicationModel.Resources.ResourceManager rm
                = new Microsoft.ApplicationModel.Resources.ResourceManager();
            for (uint i = 0; i < rm.MainResourceMap.ResourceCount; i++)
            {
                var value = rm.MainResourceMap.GetValueByIndex(i);
            }
            var ctx = rm.CreateResourceContext();
            ctx.QualifierValues.Add("scale", "100");
            var val = rm.MainResourceMap.GetValue(@"Files/Images/LockScreenLogo.png", ctx);
            var path = val.ValueAsString;
            var data = val.ValueAsBytes; // throws HRESULT 0x76D3A8B2 

Expected behavior
An error message that actually tells me what I did wrong, so I can move on and get my work done.

Version Info

NuGet package version: 0.5.5

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)

Additional context

https://task.ms/37784956

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.