Originally reported as VS Feedback https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1580286, bug https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1581287.
F5 the following console app (targeting net7.0), update Console.WriteLine('.'); to Console.WriteLine(':'); and apply changes (Hot Reload)
using System.Data;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
[assembly: MetadataUpdateHandlerAttribute(typeof(Handler))]
class Handler
{
static void ClearCache(Type[]? updatedTypes)
{
}
static void UpdateApplication(Type[]? updatedTypes)
{
if (updatedTypes != null)
{
Console.WriteLine("Update: " + String.Join(",", updatedTypes.Select(t => t.Name)));
var newType = updatedTypes.FirstOrDefault(t => t.Name.StartsWith("C#"));
if (newType != null)
{
C.Instance = (I)Activator.CreateInstance(newType)!;
}
}
}
}
interface I
{
Task F();
}
[CreateNewOnMetadataUpdate]
class C : I
{
public static I Instance = new C();
public static void Main()
{
while (true)
{
Instance.F();
Thread.Sleep(1000);
}
}
public void F()
{
Console.WriteLine('.');
G(() => { }); // exception
}
public void G(Action f) => f();
}
System.ArgumentException: 'Delegate to an instance method cannot have null 'this'.'
> System.Private.CoreLib.dll!System.MulticastDelegate.ThrowNullThisInDelegateToInstance() Line 570 C#
System.Private.CoreLib.dll!System.MulticastDelegate.CtorClosed(object target, nint methodPtr) Line 577 C#
ConsoleApp26.dll!C#1.F() Line 71 C#
ConsoleApp26.dll!C.Main() Line 55 C#
Originally reported as VS Feedback https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1580286, bug https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1581287.
F5 the following console app (targeting
net7.0), updateConsole.WriteLine('.');toConsole.WriteLine(':');and apply changes (Hot Reload)System.ArgumentException: 'Delegate to an instance method cannot have null 'this'.'