After trying serveral things out, I finally tracked down the issue.
It seems that when getting asking for common assembiles, Windows prioritized the ones bundled with Powershell 7.0 (maybe versions 6.x as well) instead of the ones included by .Net framework itself. But by design they do not always behave in the same way
https://github.com/dotnet/runtime/issues/29823, particularly with WinForms. There are also several open issues related to the TypeHandler in net core 3.x which may be related.
Maybe a possible fix is fiddling around with the TargetFramework attribute and/or the assembly conversions to force referencing the correct assemblies.
However, the quickest way to solve the issue is to simply uninstall Powershell 7.0.x (6.x), this allows both scripts to compile.
The following issues were also resolved:
- Slow Settings UI
- Visual Basic scripting being completely broken
As a sidenote, I tried the latest 7.0.2 release but the issue persisted. However, after upgrading to 7.1 preview, which is based on .Net 5 (both include fixes regarding references and the TypeHandler), everything kept working ok.