CodexBloom - Programming Q&A Platform

PowerShell not recognizing newer .NET Core types in custom module when using class-based design

👀 Views: 1650 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-03
PowerShell .NET Core module

I'm attempting to set up I recently switched to I'm performance testing and I've been banging my head against this for hours..... I'm trying to create a PowerShell module that utilizes .NET Core 3.1 types, specifically `System.IO.FileInfo`, within a class-based design. However, when I try to instantiate a `FileInfo` object, I get the following behavior: `want to find type [System.IO.FileInfo]: verify that the assembly containing this type is loaded.` I've ensured that I'm running PowerShell 7.3, which should support .NET Core types, but I'm still working with this scenario. Here's a simplified version of my module code: ```powershell class MyFileHandler { [System.IO.FileInfo] $FileInfo MyFileHandler([string]$filePath) { $this.FileInfo = [System.IO.FileInfo]::new($filePath) } [string] GetFileDetails() { return $this.FileInfo.FullName } } ``` When I execute the following commands in my script: ```powershell Import-Module MyModule $handler = [MyFileHandler]::new('C:\temp\testfile.txt') $handler.GetFileDetails() ``` I expected to receive the full path of the file, but instead, I get the type behavior mentioned above. I've also checked that the `System.IO.FileInfo` type is available in my environment by running `[AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq 'System.IO.FileSystem' }`, and it is present. What could be causing this scenario? Is there a specific way to ensure that .NET Core types are recognized within my module's scope? Any advice would be greatly appreciated. What am I doing wrong? This is my first time working with Powershell stable. For context: I'm using Powershell on Windows 11. Any pointers in the right direction? My development environment is Windows 11. I'd love to hear your thoughts on this.