Documentation

Unity Engine


Unity Engine


Incompatible .NET API reference

Understand which .NET APIs are incompatible with Unity's assembly loading and management system, and which compatible alternatives you can use instead.
Read time 2 minutesLast updated 16 days ago

Unity's runtime uses a specialized assembly loading and management system to support code reload. The UAC (Unity API Compatibility) analyzer flags several reflection APIs that are or will soon become incompatible with Unity's assembly lifecycle.

Warning code

Incompatible .NET API

Compatible Unity alternative

UAC005
AppDomain.GetAssemblies


This standard .NET API returns all loaded assemblies from all AssemblyLoadContexts (ALCs), including those that are in an unloading state. Using these stale assembly references can cause
TypeLoadException
,
NullReferenceException
, memory leaks, or Editor crashes. Unity provides
CurrentAssemblies.GetLoadedAssemblies
which only returns assemblies that are currently active and valid within Unity's managed environment, ensuring safe enumeration during all Editor states.
CurrentAssemblies.GetLoadedAssemblies
UAC006
Certain methods and events in the
AppDomain
class.

These
AppDomain
events are not properly triggered or managed in Unity's assembly lifecycle system. Subscribing to these events can result in handlers that are never called, or called at incorrect times during code reloads, leading to memory leaks or crashes. For assembly unloading notifications, use Unity's LifeCycle APIs.
Unity's LifeCycle APIs.
UAC007
Assembly.Location


Unity loads many assemblies from memory streams rather than directly from disk to avoid file locking. For these assemblies, the
Assembly.Location
property returns an empty string, breaking code that relies on file paths for loading dependencies or resources. The
Assembly.GetLoadedAssemblyPath
extension method provided by Unity tracks and returns the original source path reliably, working correctly for both disk-loaded and stream-loaded assemblies.
Assembly.GetLoadedAssemblyPath
UAC020
Assembly.LoadFile
/
Assembly.LoadFrom


These methods load assemblies outside of Unity's assembly management system. This bypasses Unity's dependency tracking, prevents proper unloading during script recompilation and code reloads, and can cause assembly version conflicts. Use
CurrentAssemblies.LoadFromPath
instead, which integrates with Unity's assembly lifecycle so assemblies can be properly tracked, reloaded, and unloaded when needed.
CurrentAssemblies.LoadFromPath
UAC023
BinaryFormatter


This serializer is deprecated in modern .NET due to critical security vulnerabilities and will not be supported in Unity's runtime environment. Use Unity's built-in serialization system,
JsonUtility
, or
DataContract
instead.
Unity serialization,
JsonUtility
,
DataContract

Code transition example

The following table provides examples of incompatible code snippets and what they can be replaced with:

Incompatible code

Replacement

Namespace

AppDomain.CurrentDomain.GetAssemblies()
CurrentAssemblies.GetLoadedAssemblies()
UnityEngine.Assemblies
AppDomain.CurrentDomain.DomainUnload
[OnAssemblyUnloading]
Unity.Scripting.LifecycleManagement
assembly.Location
assembly.GetLoadedAssemblyPath()
UnityEngine
Assembly.LoadFile(path)
CurrentAssemblies.LoadFromPath(path)
UnityEngine.Assemblies

Additional resources