String interpolation using $ throws System.NullReferenceException on .Net7

Morten Starck 0 Reputation points
2023-02-02T23:08:22.8133333+00:00

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.

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Clinton Pereira 0 Reputation points
    2023-03-23T04:58:47.8166667+00:00

    I encountered the same issue when compiling from a Mac Book Pro Intel Processor.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.