Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

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

rawAssembly

A byte array that is a COFF-based image containing an assembly.

Returns

Type

Description

AssemblyThe 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
Assembly.Load
, assemblies loaded with this API are guaranteed to work correctly with code reload. Also unlike
Assembly.Load
, this API prevents assemblies with the same AssemblyName from being loaded.
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 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

rawAssembly

A byte array that is a COFF-based image containing an assembly.

rawSymbolStore

A byte array that contains the symbols for the assembly.

Returns

Type

Description

AssemblyThe 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
Assembly.Load
, assemblies loaded with this API are guaranteed to work correctly with code reload. Also unlike
Assembly.Load
, this API prevents assemblies with the same AssemblyName from being loaded.
This 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); }}