-
Notifications
You must be signed in to change notification settings - Fork 4k
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
TypeLoadException
resulted by using interpolated string in PowerShell
#55609
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I believe this is a Roslyn issue. The new support for interpolated strings shouldn't enable the new lowering when arguments are dynamic (or at least not when the handler type is a ref struct). This will produce the same error: var handler = new Handler(0, 0);
handler.AppendFormatted((dynamic)5);
ref struct Handler
{
public Handler(int literalLength, int formattedCount) { }
public void AppendFormatted<T>(T value) { }
} |
The way that interpolation is designed is that we effectively do standard overload resolution to find the "best" That will work when the handler is a simple More generally I wonder if we should be warning / erroring when you attempt to mix using System;
var span = "hello".AsSpan();
dynamic index = 0;
Console.WriteLine(span[index]); |
Fixes dotnet#55609. Note that we don't attempt to warn/error for custom handlers, as we never warn/error when mixing dynamic and ref structs today. If that ever changes, we'll naturally start producing warnings here as well.
* Use string.Format when an interpolated string part is dynamic Fixes #55609. Note that we don't attempt to warn/error for custom handlers, as we never warn/error when mixing dynamic and ref structs today. If that ever changes, we'll naturally start producing warnings here as well.
I got similar/same exception when using interpolation in a partial view. VS 2022 (both in RC and RC2), NET 6 RC2 Code part in layout: Code part in partial view: Error message/exception/trace: "Message": "The generic type '<>A{00000004} 3' was used with an invalid instantiation in assembly 'whjnthmb.rov, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.", "Exception": "TypeLoadException", "Trace": " |
Description
After building PowerShell against .NET 6 Preview 7 SDK, tab completion in PowerShell throws
TypeLoadException
:Configuration
.NET 6 Preview 7 SDK on Windows 10 x64.
Regression?
Yes, from all prior versions of .NET Core.
Other information
Repro steps:
On PowerShell built against .NET 6 preview 7 SDK run the following steps:
I looked more into the issue and found that this exception is triggered by the use of a interpolated string:
var idAndName = $"{processId} - {processName}"
. The exception goes away after I replace it withvar idAndName = processId + " - " + processName;
.The interesting part is that both
processId
andprocessName
in the code are of thedynamic
type. The exception may be related to that.The text was updated successfully, but these errors were encountered: