public static void AddClientTypeAssembly(Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } ScriptTypeMap.EnsureInited(); ScriptTypeMap.AddClientProxyAssembly(assembly); }
private static void AppDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { Assembly loadedAssembly = args.LoadedAssembly; //Edited for .NET Core //object[] customAttributes = loadedAssembly.GetCustomAttributes(typeof(ClientTypeAssemblyAttribute), false); var customAttributes = loadedAssembly.GetCustomAttributes <ClientTypeAssemblyAttribute>(); if (customAttributes != null && customAttributes.Count() > 0) { ScriptTypeMap.AddClientProxyAssembly(loadedAssembly); } }
private static void Init() { ScriptTypeMap.LoadClientTypeAssemblies(); //Edited for .NET Core //Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); //AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(ScriptTypeMap.AppDomain_AssemblyLoad); //Assembly[] array = assemblies; //for (int i = 0; i < array.Length; i++) //{ // Assembly assembly = array[i]; // try // { // object[] customAttributes = assembly.GetCustomAttributes(typeof(ClientTypeAssemblyAttribute), false); // if (customAttributes != null && customAttributes.Length != 0) // { // ScriptTypeMap.AddClientProxyAssembly(assembly); // } // } // catch (Exception) // { // } //} // The above code seems to loop all loaded assemblies to check for the ClientTypeAssemblyAttribute // The below is how I have rewritten it for .NET Core // NOTE: I can't find a way to hook to something similiar to AppDomain.CurrentDomain.AssemblyLoad var currentAssembly = Assembly.GetEntryAssembly(); var currentAssemblyClientTypeAttributes = currentAssembly.GetCustomAttribute <ClientTypeAssemblyAttribute>(); var currentAssemblyReferencedAssemblies = currentAssembly.GetReferencedAssemblies(); foreach (var assemblyName in currentAssemblyReferencedAssemblies) { try { var assembly = Assembly.Load(assemblyName); var customAttributes = assembly.GetCustomAttributes <ClientTypeAssemblyAttribute>(); if (customAttributes != null && customAttributes.Count() != 0) { ScriptTypeMap.AddClientProxyAssembly(assembly); } } catch (Exception) { } } }