I would like to use [System.IO.MemoryMappedFiles] on PowerShell-7 with .NetFramework 4.8 (Release 528372) running on Windows 10 20H2;
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
and trying to load the DLL into PowerShell-7 console. My goal is to create a view of a large binary file using [System.IO.MemoryMappedFiles]::CreateFromFile().
Below is based on the "Example 3" and "Example 2" at Add-Type and seeing answers to similar questions at SO like Unable to use System.IO.Compression.FileSystem.dll
xSet-Location $PSHOME
$AccType = Add-Type -AssemblyName "System.IO.MemoryMappedFiles" -PassThru
[System.IO.MemoryMappedFiles] | Get-Member
However, on a PowerShell 7 (x64) console, the Get-Member
returns "Unable to find type" error as below.
InvalidOperation: C:\.......\PowerShell\MyTest-MemoryMappedFiles.ps1:3
Line |
3 | [System.IO.MemoryMappedFiles] | Get-Member
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to find type [System.IO.MemoryMappedFiles].
When I run $AccType = Add-Type -AssemblyName "System.IO.MemoryMappedFiles" -PassThru
, the $AccType
contains below,
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
False False EmbeddedAttribute System.Attribute
False False NullableAttribute System.Attribute
False False NullableContextAttribute System.Attribute
False False NullablePublicOnlyAttribute System.Attribute
False False Interop System.Object
False False Kernel32 System.Object
False False SECURITY_ATTRIBUTES System.ValueType
False False SYSTEM_INFO System.ValueType
False False MEMORY_BASIC_INFORMATION System.ValueType
False False MEMORYSTATUSEX System.ValueType
False True BOOL System.Enum
False False SR System.Object
False False SR System.Object
False False Win32Marshal System.Object
True True MemoryMappedFileOptions System.Enum
True True MemoryMappedFileAccess System.Enum
True False MemoryMappedFile System.Object
False False MemoryMappedView System.Object
True False MemoryMappedViewAccessor System.IO.UnmanagedMemoryAccessor
True False MemoryMappedViewStream System.IO.UnmanagedMemoryStream
True True MemoryMappedFileRights System.Enum
True False SafeMemoryMappedViewHandle System.Runtime.InteropServices.SafeBuffer
True False SafeMemoryMappedFileHandle Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
After running the Add-Type
command, when I enter
[System.IO.Memory
then enter TAB key in the PS7 console,
[System.IO.MemoryMappedFiles
is automatically completed, But when I enter (Please ignore the heading double quote below.)
" [System.IO.MemoryMappedFiles]::
and enter TAB key, nothing is completed. The pre-loaded standard library like
"[System.IO.File]::
completes the methods
[System.IO.File]::AppendAllLine(
with entering TAB key.