Increase MaxModuleNestingDepth #19777
notatechproblem
started this conversation in
Enhancements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I make extensive reuse of custom classes in my PowerShell code, so I've started using script modules as class libraries that I reference with
using module MyModule
statements. However, I've had to start grouping classes together into fewer, larger modules because having my class library modules call other class library modules very quickly results in:Cannot load the module 'MyModule.psd1' because the module nesting limit has been exceeded
It looks like the limit is hard-coded in ModuleIntrinsics.cs:
private const int MaxModuleNestingDepth = 10;
My C# skills aren't great, so I'm having a difficult time figuring out if that limit is based on technical reasons, or if it was just pulled out of the air by some developer on the PowerShell team thinking "No one will ever need to nest modules more than 10 deep!". According to blame, that line of code has been unchanged since the first commit to the PS repo in 2016.
Being able to break up my classes into smaller class library modules would be a significant improvement to my devEx, and at first glance it seems like it would be very easy to fix.
Does anyone know if there are any technical reasons preventing MaxModuleNestingDepth from being set to a number larger than 10? Or, could the value be stored instead as a customizable value that is read from powershell.config.json instead of being hard-coded?
Beta Was this translation helpful? Give feedback.
All reactions