File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/Microsoft.PowerShell.ConsoleHost/host/msh Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #nullable enable
5
+
6
+ using System ;
7
+ using System . IO ;
8
+ using System . Runtime . Loader ;
9
+ using System . Runtime . InteropServices ;
10
+
11
+ namespace Microsoft . PowerShell
12
+ {
13
+ /// <summary>
14
+ /// Provides helper functions to faciliate calling managed code from a native PowerShell host.
15
+ /// </summary>
16
+ public static class NativeHost
17
+ {
18
+ /// <summary>
19
+ /// Load an assembly in memory from unmanaged code.
20
+ /// </summary>
21
+ /// <param name="data">
22
+ /// Unmanaged pointer to assembly data buffer
23
+ /// </param>
24
+ /// <param name="size">
25
+ /// Size in bytes of the assembly data buffer
26
+ /// </param>
27
+ [ UnmanagedCallersOnly ]
28
+ public static void LoadAssemblyData ( IntPtr data , int size )
29
+ {
30
+ byte [ ] bytes = new byte [ size ] ;
31
+ Marshal . Copy ( data , bytes , 0 , size ) ;
32
+ Stream stream = new MemoryStream ( bytes ) ;
33
+ AssemblyLoadContext . Default . LoadFromStream ( stream ) ;
34
+ }
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments