Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
InMemoryAssemblyLoader.cs
Go to the documentation of this file.
1using System;
4
6
7public static class InMemoryAssemblyLoader
8{
9 private static bool IsSupported { get; } = InitializeIsSupported();
10
11
12 private static bool InitializeIsSupported()
13 {
14 if (!AppContext.TryGetSwitch("System.Runtime.InteropServices.EnableCppCLIHostActivation", out var isEnabled))
15 {
16 return true;
17 }
18 return isEnabled;
19 }
20
21 public static void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assemblyPath)
22 {
23 if (!IsSupported)
24 {
25 throw new NotSupportedException("This API is not enabled in trimmed scenarios. see https://aka.ms/dotnet-illink/nativehost for more details");
26 }
27 string text = Marshal.PtrToStringUni(assemblyPath);
28 if (text == null)
29 {
30 throw new ArgumentOutOfRangeException("assemblyPath");
31 }
32 AssemblyLoadContext assemblyLoadContext = new IsolatedComponentLoadContext(text);
33 assemblyLoadContext.LoadFromInMemoryModule(moduleHandle);
34 }
35}
static void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assemblyPath)
static bool TryGetSwitch(string switchName, out bool isEnabled)
Definition AppContext.cs:74
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition Marshal.cs:652
Assembly LoadFromInMemoryModule(IntPtr moduleHandle)