public static Type ToReflectionType()

in src/Microsoft.NET.Sdk.Functions.Generator/TypeUtility.cs [133:158]


        public static Type ToReflectionType(this TypeReference typeDef)
        {
            var loadContext = AssemblyLoadContext.CurrentContextualReflectionContext;
            if (loadContext == null)
            {
                throw new InvalidOperationException("CurrentContextualReflectionContext was null.");
            }

            var fullName = typeDef.GetReflectionFullName();
            Type t = Type.GetType(fullName);

            if (t == null)
            {
                var assemblyName = new AssemblyName(typeDef.Resolve().Module.Assembly.FullName);

                Assembly a = loadContext.LoadFromAssemblyName(assemblyName);
                t = a.GetType(fullName);
            }

            if (t == null)
            {
                throw new InvalidOperationException($"Could not load type '{fullName}'.");
            }

            return t;
        }