I am not sure what the project team will have to say to this, but your construct will never work for intellisense in PowerShell Studio.
Generally, you would embed C# code like described here: https://dandraka.com/2018/11/12/powersh ... -inline-c/
I have not tried this with PowerShell Studio and I do not know if THAT would work, I will leave that to the team.
Your construct separates the code in the here string and uses a variable as an argument to Add-Type.
In order for that to be resolved, the script MUST run. Any use of a variable in that scenario can ONLY be resolved at runtime,
as the variable has no content unless you execute the code.
The ISE can only do that when you run that script first. Not when you just load it.
The requirement to actually run a script to get intellisense is quite dangerous and a security risk. You should not have to do that and the ISE trains users to just run a script to see intellisense.
That leads to users running scripts without considering security implications. We will not ever require you to run code just to see members. It is too dangerous and can be misleading.
We have seen editors that run PowerShell code in the background WITHOUT user interaction to provide better intellisense. It sure looks like magic but is an immense security risk.
Just imagine you get that malware script emailed, you want to see what makes it tick and your editor just runs its code internally to provide intellisense. Its a nightmare.
The second part to this is that by running code and not clearing the runspace between subsequent script executions, you get a contaminated runspace.
See here: https://www.sapien.com/blog/2022/04/25/ ... -avoid-it/
Your different output is quite likely the result of runspace contamination.
It is incredibly difficult to get reproducible results in the ISE because of that. I am not saying that the ISE is bad, it just was not designed for script development really.
In your example load the script and run it in the ISE.
Now rename ClassLibrary1 to MyClassLibrary and Class1 to MyClass
but leave this line intact:
Run it. Your output is the same, it works fine, even though Class1 no longer even exits in your code.
still gives you intellisense for something that is no longer there.
It will work all day and night until you restart the ISE, making you think your code works fine. But it'll fail any place else.
This is perfectly fine for some 15 line scripts, where you can easily see and understand what is going on. If your script gets into the hundreds or thousands of lines while dot sourcing code and using modules, this is not an easy situation.
I hope this explanation helps to illustrate this effect.