问题描述:

I am having an issue where the SelectedIndexChanged event is not firing on my System.Windows.Forms.ComboBox object when it should, but only on my computer. It works fine on everyone else's computer.

When I run GetType().assembly on the object my computer shows .Net 4.0, but 2.0 on everyone else's.

How can I force the object to 2.0?

Here is the relevent assembly import:

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null

网友答案:

PowerShell automatically loads the assembly from the same .Net version that PowerShell runs in. So pointing to a v2.0 assembly might still force it to load a v4.0 assembly.

Since your loading a v4.0 assembly, your probably not using PS1, but rather PS3 or 4, Then the easy solution would be to simply run PowerShell in 2.0 mode by using:

powershell.exe -version 2
网友答案:

Are you sure you are using PowerShell v1? That should be CLR v2 and not load .Net 4.0 assemblies. Your code should load the 2.0 assembly. If that is not the case, then your powershell v1 is configured to load CLR v4. That or you are using PowerShell v3 or higher.

Try $PSVersionTable and see what it reads.

If it reads PSVersion 1 or 2 then undo the change to PowerShell that made it use CLR v4. If it reads a higher version then there is no way. .Net framework assemblies will always load the 4.0 version.

In any case I don't expect it to explain your event not firing.

Update

As Graimer notes, you could however have newer PowerShell versions load as older versions, including older CLR versions.

相关阅读:
Top