Open threerog opened 11 months ago
on dnSpy 6.4.0 im able to edit method (C#), probably you have unresolved assemblies
on dnSpy 6.4.0 im able to edit method (C#), probably you have unresolved assemblies Sorry, the previous description was incorrect. I have updated the correct issues title
original code
logger.Warn($"*****{obj.Id}*****{flag}");
dnSpy decompiled code
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(10, 2);
defaultInterpolatedStringHandler.AppendLiteral("*****");
defaultInterpolatedStringHandler.AppendFormatted(obj.Id);
defaultInterpolatedStringHandler.AppendLiteral("*****");
defaultInterpolatedStringHandler.AppendFormatted<bool>(flag);
logger.Warn(defaultInterpolatedStringHandler.ToStringAndClear());
When modifying the method and compiling, dnSpy reports an error
CS4012 Parameters or locals of type 'DefaultInterpolatedStringHandler' cannot be declared in async methods or async lambda expressions.
What's even more strange is that I tried to delete the code related to the DefaultInterpolatedStringHandler
in dnspy, concatenated it with $""
, and after dnspy compiled it normally, I reloaded the DLL file. However, dnspy did not decompile the code that was just concatenated with $""
into the DefaultInterpolatedStringHandler
dnspy seems to only decompile the code containing $""
concatenation in the DLL compiled by VS into the DefaultInterpolatedStringHandler
, without processing the DLL compiled by dnspy itself
Decompilation of interpolated string handler into original expression is not supported yet, because of old decompiler engine. And after editing it becomes normal because dnSpy probably compiled it into older string.Format("*****{0}*****{1}", obj.Id, flag)
P.S. in my app dnSpy compiled it into DefaultInterpolatedStringHandler
and it doesn't show it as original $"'
string
+1 to this issue, found it too, but it is not deal breaker. dnSpyEx can display async property vs original one which cant is already a blessing. TY to authors.
My current workaround is to open ILSpy along side and copy cleaner decompiled code from there when recompiling method.
The compiled result was ok-ish, and result back into DefaultInterpolatedStringHandler
.
(Screenshot: decompiled code from dnSpyEx and ILSpy)
This will be fixed properly when the decompiler engine is updated to the latest ILSpy version. Currently, the workaround suggested by @wappenull is one of the better ways to get the C# editor working well with modern code.
dnSpyEx version
6.4.1
Describe the Bug
After decompiling the code with $"{xxxx}" string concatenation in the original code, it is not possible to edit the code and recompile it through dnSpy. The name 'defaultInterpolatedStringHandler' does not exist in the current context
How To Reproduce
$"{xxxx}"
Expected Behavior
.
Actual Behavior
.
Additional Context
No response