Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS4012 Parameters or locals of type 'DefaultInterpolatedStringHandler' cannot be declared in async methods or async lambda expressions. #278

Open
threerog opened this issue Dec 26, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@threerog
Copy link

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

@threerog threerog added the bug Something isn't working label Dec 26, 2023
@GazziFX
Copy link

GazziFX commented Dec 27, 2023

on dnSpy 6.4.0 im able to edit method (C#), probably you have unresolved assemblies

@threerog threerog changed the title The name 'defaultInterpolatedStringHandler' does not exist in the current context CS4012 Parameters or locals of type 'DefaultInterpolatedStringHandler' cannot be declared in async methods or async lambda expressions. Dec 27, 2023
@threerog
Copy link
Author

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

@threerog
Copy link
Author

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.

@threerog
Copy link
Author

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

@GazziFX
Copy link

GazziFX commented Dec 27, 2023

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

@wappenull
Copy link

+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)
image

@ElektroKill
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants