I encountered the same issue when compiling from a Mac Book Pro Intel Processor.
String interpolation using $ throws System.NullReferenceException on .Net7
We have in my team just upgraded to .net 7 from 6, but we have run into a issues with string interpolation using
$"Text {sample}"
We are all developing on Intel Macbook Pro's using both Visual Studio or JetBrains Rider. But since the upgrade to .net7, im getting an error:
System.NullReferenceException: Object reference not set to an instance of an object. at System.Buffer.Memmove(Byte& dest, Byte& src, UIntPtr len) at System.Runtime.CompilerServices.DefaultInterpolatedStringHandler.AppendStringDirect(String value)
Example:
private async Task<bool> GetSapUpdatedTimeStamp(Guid id, long newSapTimeStamp)
{
var sqlGet = $@"SELECT timestamp FROM Orders WHERE OrderId = '{id.ToString()};";
var dbSapDate = await _connection.QueryFirstOrDefaultAsync<long?>(sqlGet);
return dbSapDate;
}
In the example above it fails on the sqlGet line, if i run it in Windows it does not throw an exception, neither did it in .net 6 on both Mac or Windows. It only happens on .net7 and on Mac OS(Intel or M1 Mac's). I have tried both in Jetbrains Rider and Visual Studio. I have tried with different ways and it still fails on string interpolation ala like below:
public async Task Consume(ConsumeContext<SapUpdatedEvent> context)
{
_logger.LogInformation($"Order id: {context.Message.OrderId} notificationid: {context.Message.NotificationId}");
}
In both examples are there NO values that are NULL.
Any idea how to fix this issue.