Skip to content

MetadataUpdateHandler not working in custom host #113452

@ikkentim

Description

@ikkentim

Description

When using a custom host (using nethost/hostfxr), hot reloading works as expected (tested in Visual Studio), however, the metadata update handler as specified using the [MetadataUpdateHandler(..)] attribute does not trigger.

Since hot reloading works I expected the metadata update handler to work as well. Is this intended to work or not?

Reproduction Steps

Given the following managed code, uncommenting the line of code and hitting the hot reload button in Visual Studio, causes the console output to include the added line.

using ManagedLibrary;
using System;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;

[assembly: MetadataUpdateHandler(typeof(ManagedWorker))]
namespace ManagedLibrary
{
    public class ManagedWorker
    {
        public static void ClearCache(Type[]? updatedTypes)
        {
            Console.WriteLine("ClearCache");
        }

        public static void UpdateApplication(Type[]? updatedTypes)
        {
            Console.WriteLine("UpdateApplication");
        }

        private static int _counter;

        [UnmanagedCallersOnly]
        public static void DoWork()
        {
            Console.WriteLine($"working! {_counter++}");
            // Console.WriteLine("changes made");
        }

        public static void Main()
        {
        }
    }
}

Full repro (managed+unmanaged) can be found here https://github.com/ikkentim/MetadataUpdateHandler-repro

  • Build both projects, then launch (Debug) the ManagedLibrary using the provided launch profile.

Expected behavior

Changed output to appear in the console and a combination of ClearCache/UpdateApplication to be written to the console.

(...)
working! 6
working! 7
ClearCache
UpdateApplication
changes made
working! 8
changes made

Actual behavior

Changed output appears in the console, but neither ClearCache or UpdateApplication appears in the console.

(...)
working! 6
working! 7
changes made
working! 8
changes made

Regression?

No response

Known Workarounds

No response

Configuration

Microsoft.NETCore.App 9.0.0
Windows 10

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Diagnostics-coreclrenhancementProduct code improvement that does NOT require public API changes/additionstracking-external-issueThe issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions