Version: Unity 6.4 Alpha (6000.4)
LanguageEnglish
  • C#

CurrentAssemblies.GetLoadedAssemblies

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static IReadOnlyList<Assembly> GetLoadedAssemblies();

Returns

IReadOnlyList<Assembly> A collection of assemblies.

Description

Gets the assemblies Unity has loaded into the current execution context.

Use CurrentAssemblies.GetLoadedAssemblies to get a list of currently loaded assemblies that can be used for reflection purposes. This is a safer alternative to .NET's AppDomain.CurrentDomain.GetAssmblies in the Unity context. Unity uses the AssemblyLoadContext mechanism for code reload, which means assemblies can be loaded and unloaded at runtime. AppDomain.CurrentDomain.GetAssemblies returns a list of all loaded assemblies, which may include assemblies in the unloaded state and lead to exceptions and logical errors in the Editor code.

using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.Assemblies;

public class LoadedAssemblyInfo { [MenuItem("Test/Get Loaded Assembly Info")] static void GetLoadedAssemblyInfo() { var sb = new StringBuilder(); sb.AppendLine("Currently loaded assemblies are:");

foreach (var assembly in CurrentAssemblies.GetLoadedAssemblies()) { sb.AppendLine(assembly.FullName); }

Debug.Log(sb.ToString()); } }