Unhelpful HRESULT error messages in .NET
Open
@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:

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
- Create a new WinUI app
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.