Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
InMemoryAssemblyLoader.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.Runtime.InteropServices
;
3
using
System.Runtime.Loader
;
4
5
namespace
Internal.Runtime.InteropServices
;
6
7
public
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
}
Internal.Runtime.InteropServices.InMemoryAssemblyLoader.LoadInMemoryAssembly
static void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assemblyPath)
Definition
InMemoryAssemblyLoader.cs:21
Internal.Runtime.InteropServices.InMemoryAssemblyLoader.IsSupported
static bool IsSupported
Definition
InMemoryAssemblyLoader.cs:9
Internal.Runtime.InteropServices.InMemoryAssemblyLoader.InitializeIsSupported
static bool InitializeIsSupported()
Definition
InMemoryAssemblyLoader.cs:12
Internal.Runtime.InteropServices.InMemoryAssemblyLoader
Definition
InMemoryAssemblyLoader.cs:8
Internal.Runtime.InteropServices.IsolatedComponentLoadContext
Definition
IsolatedComponentLoadContext.cs:9
System.AppContext.TryGetSwitch
static bool TryGetSwitch(string switchName, out bool isEnabled)
Definition
AppContext.cs:74
System.AppContext
Definition
AppContext.cs:14
System.ArgumentOutOfRangeException
Definition
ArgumentOutOfRangeException.cs:9
System.NotSupportedException
Definition
NotSupportedException.cs:9
System.Runtime.InteropServices.Marshal.PtrToStringUni
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition
Marshal.cs:652
System.Runtime.InteropServices.Marshal
Definition
Marshal.cs:14
System.Runtime.Loader.AssemblyLoadContext.LoadFromInMemoryModule
Assembly LoadFromInMemoryModule(IntPtr moduleHandle)
Definition
AssemblyLoadContext.cs:242
System.Runtime.Loader.AssemblyLoadContext
Definition
AssemblyLoadContext.cs:15
Internal.Runtime.InteropServices
Definition
ComActivationContext.cs:5
System.Runtime.InteropServices
Definition
SequenceMarshal.cs:4
System.Runtime.Loader
Definition
AssemblyDependencyResolver.cs:8
System.ExceptionArgument.text
@ text
System
Definition
BlockingCollection.cs:8
System.IntPtr
Definition
IntPtr.cs:14
source
System.Private.CoreLib
Internal.Runtime.InteropServices
InMemoryAssemblyLoader.cs
Generated by
1.10.0