Windows 7/8 .Net considerations

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
R1Johnny
Posts: 37
Last visit: Mon Dec 12, 2022 7:15 am

Windows 7/8 .Net considerations

Post by R1Johnny »

Good evening everyone.
Just thought I'd comment on a situation that I came across recently. Probably already acknowledged but here's my version.
:)
Environment:
OS: Script written in Win8. Run against Win7
PoSH Version: Win8-PoSH v3, Win7-PoSH v2. All native modules.

Issue: GUI Scripts configured under Windows 8 and PowerShell
Studio 2012 would not load the .Net Load Assemblies
properly when Run on Windows 7 / PowerShell V2.

I recently configured 2 nested forms with the second triggered by the first under certain circumstances. I had to modify the code at "region Import the Assemblies" for both forms in order for the script to work in both PowerShell environments: V3 and V2.

I was seeing errors related to loading the .Net background necessary to run the script in different OSs. I built the script in Windows 8 but I wanted to ensure that PowerShell V2 would also work.
I had .Net loaded from 3.5 to 4.5 on the Windows 7 OS. Still error'd out that it couldn't find the files associated with the .Net references to the following:

#region Import the Assemblies
#----------------------------------------------
[void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
#endregion Import Assemblies




To make it to work in Windows 7 (PoSH V2) I had to change the version numbers of all these .Net references.

The code listed above is AFTER the modification. Initially, every reference to the version was 4.0.0.0. I changed these values to 2.0.0.0 with the notable exception of the "Load System Core" toward the bottom of the version references. I changed that to version 3.5 based on the values observed in the same script processed in Windows 7, PowerShell V2, PowerShell Studio 2012

The script ran fine in both Win7 and 8 after this mod. .
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows 7/8 .Net considerations

Post by jvierra »

Yes you can't load 4.0 assemblies under PosH V2. This is the expected behavior.

Install V3 on Windows 7 to get full functionality or target V2 in PowerShell Studio.
This topic is 10 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked