I have added the reference System.Memory to a Console C# project in VS 2019 to use System.Span structure. But the following code produces an exception:
using System;
class A
{
static void Main()
{
Span<int> numbers = stackalloc int[3];
}
}
The exception message is:
Inner Exception FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
How can I solve the problem and remove the exception?