InterpolatedStringHandlerArgumentAttribute("") is not correctly taken into account when the receiver is a struct #58514
Labels
4 - In Review
A fix for the issue is submitted for review.
Area-Compilers
Bug
Feature - Interpolated String Improvements
Interpolated string improvements
Milestone
Version Used:
Visual Studio v17.0.4
Steps to Reproduce:
The issue occurs when a you define a method on
struct
, that expects to receive anInterpolatedStringHandler
, and when you specify[InterpolatedStringHandlerArgument("")]
for the arguments:Basically, depending on how you call
StructLogger.Log
and on how you compiled the code (!), the valuelogger
in theDummyHandler
constructor can be either the default value forStructLogger
, or a previously created value, but not the one on which you actually calledLog($"...")
. I believe this is a compiler issue, because of the behavior difference between debug and release mode, and because the issue clearly looks to be present in the IL code when you decompile the generated dll (but I am less familiar with that so I won't try to point it out directly).I wrote a test case to demonstrate the issue, you just have to compile the code as a single file console project and run it. It is enclosed at the bottom of this message. It is also interesting to note that the behavior is not the same in debug and release.
Expected Behavior:
Output the following:
Actual Behavior:
In debug, you get:
And in release, you get (note the discrepancy between the logger id passed to the DummyHandler constructor and the one actually used to issue the log line):
Test case file content
The text was updated successfully, but these errors were encountered: