# LoadFromBytes

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

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Assemblies](/engine/6000.7/script-reference/unityengine/assemblies.md)
* **Assembly:** UnityEngine.CoreModule

## LoadFromBytes(byte\[])

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

```csharp
public static Assembly LoadFromBytes(byte[] rawAssembly)
```

### Parameters

**** (\[byte\[]]\(https\://learn.microsoft.com/dotnet/api/system.byte)): A byte array that is a COFF-based image containing an assembly.

### Returns

| Type                                                                          | Description          |
| ----------------------------------------------------------------------------- | -------------------- |
| [Assembly](https://learn.microsoft.com/dotnet/api/system.reflection.assembly) | The loaded assembly. |

### Remarks

Unity automatically loads [script assemblies](/engine/6000.7/manual/scripting/compilation-and-code-reload/script-compilation/assembly-definition-files/assembly-definitions-intro.md) and [managed plug-ins](/engine/6000.7/manual/scripting/compilation-and-code-reload/plug-ins/managed.md). To load any other assemblies from memory, use this API. This is a safer alternative to .NET's [Assembly.Load(byte\[\])](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.load#system-reflection-assembly-load\(system-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](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyname) from being loaded.

Additional Resources: [CurrentAssemblies.LoadFromPath](/engine/6000.7/script-reference/unityengine/assemblies/currentassemblies/loadfrompath.md)

### Examples

```csharp
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.

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

### Parameters

**** (\[byte\[]]\(https\://learn.microsoft.com/dotnet/api/system.byte)): A byte array that is a COFF-based image containing an assembly.**** (\[byte\[]]\(https\://learn.microsoft.com/dotnet/api/system.byte)): A byte array that contains the symbols for the assembly.

### Returns

| Type                                                                          | Description          |
| ----------------------------------------------------------------------------- | -------------------- |
| [Assembly](https://learn.microsoft.com/dotnet/api/system.reflection.assembly) | The loaded assembly. |

### Remarks

Unity automatically loads [script assemblies](/engine/6000.7/manual/scripting/compilation-and-code-reload/script-compilation/assembly-definition-files/assembly-definitions-intro.md) and [managed plug-ins](/engine/6000.7/manual/scripting/compilation-and-code-reload/plug-ins/managed.md). To load any other assemblies from memory, use this API. This is a safer alternative to .NET's [Assembly.Load(byte\[\],byte\[\])](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.load#system-reflection-assembly-load\(system-byte\(\)-system-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](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyname) from being loaded.

This overload lets you supply symbols for the assembly, to enable a better debugging experience.

Additional Resources: [CurrentAssemblies.LoadFromPath](/engine/6000.7/script-reference/unityengine/assemblies/currentassemblies/loadfrompath.md)

### Examples

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