Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs (C#)

Code before:
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void OnTypeResolve(RuntimeAssembly* pAssembly, sbyte* typeName, RuntimeAssembly* ppResult, Exception* pException)
        {
            try
            {
                *ppResult = OnTypeResolve(*pAssembly, new string(typeName));
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void OnResourceResolve(RuntimeAssembly* pAssembly, sbyte* resourceName, RuntimeAssembly* ppResult, Exception* pException)
        {
            try
            {
                *ppResult = OnResourceResolve(*pAssembly, new string(resourceName));
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void OnAssemblyResolve(RuntimeAssembly* pAssembly, char* assemblyFullName, RuntimeAssembly* ppResult, Exception* pException)
        {
            try
            {
                *ppResult = OnAssemblyResolve(*pAssembly, new string(assemblyFullName));
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void Resolve(IntPtr gchAssemblyLoadContext, AssemblyName* pAssemblyName, Assembly* ppResult, Exception* pException)
        {
            try
            {

Review comment (suggestion):
Potential null reference issue: The wrapper unconditionally dereferences pAssembly with `*pAssembly`, but the native code in appdomain.cpp:3712-3713 can pass a pointer to a NULL ASSEMBLYREF if pAssembly is NULL. However, OnResourceResolve (line 687) expects a non-nullable RuntimeAssembly parameter, not RuntimeAssembly?. This inconsistency exists in OnResourceResolve's signature compared to OnTypeResolve (line 692) and OnAssemblyResolve (line 697), which both accept nullable assemblies. Consider either: (1) changing OnResourceResolve's signature to accept RuntimeAssembly?, or (2) adding a null check in the wrapper before calling OnResourceResolve.

Code after:
                OnAssemblyLoad(*pAssembly);
            }
            catch (Exception)
            {
                // The VM does not expect exceptions to propagate out of this callback
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void OnTypeResolve(RuntimeAssembly* pAssembly, byte* typeName, RuntimeAssembly* ppResult, Exception* pException)
        {
            try
            {
                string name = Utf8StringMarshaller.ConvertToManaged(typeName)!;
                *ppResult = OnTypeResolve(*pAssembly, name);
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void OnResourceResolve(RuntimeAssembly* pAssembly, byte* resourceName, RuntimeAssembly* ppResult, Exception* pException)
        {
            try
            {
                string name = Utf8StringMarshaller.ConvertToManaged(resourceName)!;
                *ppResult = OnResourceResolve(*pAssembly, name);
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void OnAssemblyResolve(RuntimeAssembly* pAssembly, char* assemblyFullName, RuntimeAssembly* ppResult, Exception* pException)
        {
            try
            {
                *ppResult = OnAssemblyResolve(*pAssembly, new string(assemblyFullName));
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void Resolve(IntPtr gchAssemblyLoadContext, AssemblyName* pAssemblyName, Assembly* ppResult, Exception* pException)