-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
This issue has been moved from a ticket on Developer Community.
[severity:I'm unable to use this version] [regression] [worked-in:net 6]
When you use the short format $"{sample}" to concatenate/format a string with variables you get this if is inside a try/catch
I have this piece of code:
[Fact]
public void NullReferenceException()
{
var cname = "component";
var callerName = "caller";
var message = "message";
string text = null;
string textFormat = null;
string textNRE = null;
textNRE = $"{cname}.{callerName}: {message}"; // this works fine ;0
try
{
text = cname + "." + callerName + ": " + message;
textFormat = string.Format("{0}.{1}: {2}", cname, callerName, message);
textNRE = $"{cname}.{callerName}: {message}"; // this throws the NullReferenceException
}
catch (Exception exp)
{ }
}
The given exception message is:
Object reference not set to an instance of an object.
Stack trace:
at System.Buffer.Memmove(Byte& dest, Byte& src, UIntPtr len)
at System.Runtime.CompilerServices.DefaultInterpolatedStringHandler.AppendFormatted(String value)
at framework.POCs.NullReferenceException() in /Users/jmrpineda/Projects/GitHub/PinedaTec.eu/InGameServices/arn/arn.test/framework/POCs.cs:line 63
I marked this issue as stopper due I have a lot of lines using this try/catch and short string format
If you need additional info, please ask me
thanks, regards
Original Comments
Feedback Bot on 11/17/2022, 06:08 PM:
(private comment, text removed)
Josema R. Pineda on 11/17/2022, 11:15 PM:
(private comment, text removed)
Josema R. Pineda on 11/18/2022, 00:13 AM:
(private comment, text removed)
Feedback Bot on 11/29/2022, 08:59 AM:
(private comment, text removed)
Feedback Bot on 11/29/2022, 11:48 AM:
(private comment, text removed)
Original Solutions
(no solutions)