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 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
            {
                AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchAssemblyLoadContext).Target)!;
                *ppResult = context.ResolveUsingLoad(*pAssemblyName);
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void ResolveSatelliteAssembly(IntPtr gchAssemblyLoadContext, AssemblyName* pAssemblyName, Assembly* ppResult, Exception* pException)
        {
            try
            {
                AssemblyLoadContext context = GCHandle<AssemblyLoadContext>.FromIntPtr(gchAssemblyLoadContext).Target;
                *ppResult = context.ResolveSatelliteAssembly(*pAssemblyName);
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

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

Review comment (suggestion):
Inconsistent GCHandle usage: This method uses the non-generic GCHandle.FromIntPtr, while ResolveSatelliteAssembly (line 812) and ResolveUsingEvent (line 826) use the generic GCHandle<AssemblyLoadContext>.FromIntPtr. For consistency and type safety, this should also use the generic version like the other two methods.
```suggestion
                AssemblyLoadContext context = GCHandle<AssemblyLoadContext>.FromIntPtr(gchAssemblyLoadContext).Target;
```

Code after:
            {
                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)
        {
            try
            {
                AssemblyLoadContext context = GCHandle<AssemblyLoadContext>.FromIntPtr(gchAssemblyLoadContext).Target;
                *ppResult = context.ResolveUsingLoad(*pAssemblyName);
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }

        [UnmanagedCallersOnly]
        private static unsafe void ResolveSatelliteAssembly(IntPtr gchAssemblyLoadContext, AssemblyName* pAssemblyName, Assembly* ppResult, Exception* pException)
        {
            try
            {
                AssemblyLoadContext context = GCHandle<AssemblyLoadContext>.FromIntPtr(gchAssemblyLoadContext).Target;
                *ppResult = context.ResolveSatelliteAssembly(*pAssemblyName);
            }
            catch (Exception ex)
            {
                *pException = ex;
            }
        }