Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

CurrentAssemblies.LoadFromBytes

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 Assembly LoadFromBytes(byte[] rawAssembly);

Parameters

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

Returns

Assembly The loaded assembly.

Description

Loads an assembly from a byte array that is a Common Object File Format (COFF)-based image.

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

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); } }

Declaration

public static Assembly LoadFromBytes(byte[] rawAssembly, byte[] rawSymbolStore);

Parameters

Parameter Description
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

Assembly The loaded assembly.

Description

Loads an assembly from a byte array that is a Common Object File Format (COFF)-based image, including symbols for the assembly.

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

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); } }