Azure / nxtools

Azure Automanage Machine Configuration Linux DSC resources
Other
13 stars 11 forks source link

Implement the abstract property 'Exists' from the base type 'FileSystemInfo` #52

Open daxian-dbw opened 5 months ago

daxian-dbw commented 5 months ago

Pull Request (PR) description

The class nxFileSystemInfo needs to implement the abstract property Exists from the base type FileSystemInfo. The Exists property is an abstract property of FileSystemInfo, and a subtype has to implement it.

This Pull Request (PR) fixes the following issues

The module nxtools stops working in PowerShell v7.4.x with the following error:

At C:\Users\<user>\Documents\PowerShell\Modules\nxtools\1.4.0\nxtools.psm1:2937 char:1
+ class nxFileSystemInfo : System.IO.FileSystemInfo
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error during creation of type 'nxFileSystemInfo'. Error message:
Method 'get_Name' in type 'nxFileSystemInfo' from assembly 'PowerShell Class Assembly, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null' does not have an implementation.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TypeCreationError

The root cause of this error is a bug in PowerShell about IL code emitting for properties of a PowerShell class, which has been there for years. It didn't surface prior to .NET 8 because the older .NET runtime doesn’t do strict validation on the IL code that is dynamically emitted. Obviously, .NET 8 starts to enforce stricter validation and find that the abstract properties defined in FileSystemInfo are not properly implemented.

We will be fixing that bug with https://github.com/PowerShell/PowerShell/pull/21331. However, when testing the fix, we find loading nxtools exposes the same error, but this time, it's about Method get_Exists. It turns out FileSystemInfo has another abstract property Exists and a subtype needs to implement it. Therefore, I'm submitting this PR.

[NOTE] I'm afraid you won't be able to validate this change until after PowerShell v7.4.2 is published later this month.

Task list