LoadFromBytes
Loads an assembly from a byte array that is a Common Object File Format (COFF)-based image.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Assemblies
- Assembly: UnityEngine.CoreModule
LoadFromBytes(byte[])
Loads an assembly from a byte array that is a Common Object File Format (COFF)-based image.
public static Assembly LoadFromBytes(byte[] rawAssembly)
Parameters
A byte array that is a COFF-based image containing an assembly.
Returns
Type | Description |
|---|---|
| Assembly | The loaded assembly. |
Remarks
Unity automatically loads script assemblies and managed plug-ins. To load any other assemblies from memory, use this API. This is a safer alternative to .NET's Assembly.Load(byte[]) in the Unity context. Unlike , assemblies loaded with this API are guaranteed to work correctly with code reload. Also unlike , this API prevents assemblies with the same AssemblyName from being loaded.
Assembly.LoadAssembly.LoadAdditional Resources: CurrentAssemblies.LoadFromPath
Examples
using System.IO;using UnityEditor;using UnityEngine;using UnityEngine.Assemblies;public class AssemblyLoadingFromBytes{ [MenuItem("Test/Load Assembly From Bytes")] static void LoadAssemblyFromBytes() { var assemblyBytes = File.ReadAllBytes(@"C:\Some\Path\To\TheAssembly.dll"); var assembly = CurrentAssemblies.LoadFromBytes(assemblyBytes); Debug.Log(assembly.FullName); }}
LoadFromBytes(byte[], byte[])
Loads an assembly from a byte array that is a Common Object File Format (COFF)-based image, including symbols for the assembly.
public static Assembly LoadFromBytes(byte[] rawAssembly, byte[] rawSymbolStore)
Parameters
Returns
Type | Description |
|---|---|
| Assembly | The loaded assembly. |
Remarks
Unity automatically loads script assemblies and managed plug-ins. To load any other assemblies from memory, use this API. This is a safer alternative to .NET's Assembly.Load(byte[],byte[]) in the Unity context. Unlike , assemblies loaded with this API are guaranteed to work correctly with code reload. Also unlike , this API prevents assemblies with the same AssemblyName from being loaded.
Assembly.LoadAssembly.LoadThis overload lets you supply symbols for the assembly, to enable a better debugging experience.
Additional Resources: CurrentAssemblies.LoadFromPath
Examples
using System.IO;using UnityEditor;using UnityEngine;using UnityEngine.Assemblies;public class AssemblyLoadingFromBytes{ [MenuItem("Test/Load Assembly From Bytes")] static void LoadAssemblyFromBytes() { var assemblyBytes = File.ReadAllBytes(@"C:\Some\Path\To\TheAssembly.dll"); var symbolBytes = File.ReadAllBytes(@"C:\Some\Path\To\TheAssembly.pdb"); var assembly = CurrentAssemblies.LoadFromBytes(assemblyBytes, symbolBytes); Debug.Log(assembly.FullName); }}