added label "ResourceKey" to trace details when resource is not found #3493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2956
Summary of issue
When targeting .NET Framework, not finding a
ResourceDictionary
key namedsomeKey
causesto be written to
PresentationTraceSources.ResourceDictionarySource
, but when targeting .NET Core, that message is onlyContribution
This branch contributes a fix. I want to explain both why it is a fix and why (I think) it is the correct fix.
A fix
The change adds
"ResourceKey"
to a string array. That array is later passed intowpf/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/AvTrace.cs
Lines 256 to 261 in b152272
as the
labels
argument. With the code currently inmaster
, the relevant arguments for the cases in question arelabels = new string[] { "Resource not found" }
andparameters = new object[] { "someKey" }
.Confusingly, the first argument in that array is the same as the
message
argument, so the first entry inlabels
is ignored in this function. As the comment points out,note: labels start at index 1, parameters start at index 0
. Then the body of this for-loop is never executed.wpf/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/AvTrace.cs
Lines 281 to 287 in b152272
With my change, the relevant arguments are
labels = new string[] { "Resource not found", "ResourceKey" }
andparameters = new object[] { "someKey" }
.The body of the for-loop executes once to append
; ResourceKey='someKey'
totraceBuilder
.Correct fix
No unintended consequences
A concern with any bug fix is that it doesn't only fix the bug in question but also has some unintended consequence. I don't think my change has any unintended consequences. The line I changed alters the definition of
TraceResourceDictionary.ResourceNotFound
. According to my searches, the only two references to that property are these two, which both lead to the code to which I linked in the previous section and the behavior I described there.wpf/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs
Lines 1147 to 1158 in b152272
Comparison with .NET Framework source
I tried to analyze the same code in .NET Framework and statically verify what I know to be true via testing, which is that .NET Framework does not contain the bug in question. I didn't quite succeed though. Considering the reference source, I tracked down the same two calls to
TraceResourceDictionary.ResourceNotFound
, but I wasn't able to findTraceResourceDictionary
in the reference source.Generated?
I am concerned that the change I made is in a file that is in a folder called
Generated
. Did I edit generated code?