Resolving PowerShell V3 ISE error with Invoke-Sqlcmd

The PowerShell ISE is much improved in V3, needless to say I am really enjoying writing scripts with this tool! It is however, not without hiccups.

I was trying to run the Invoke-Sqlcmd cmdlet when I got the following error in the PowerShell ISE

Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

Basically just means PowerShell has support for side-by-side runtime, and we need to specify an activation policy in a config file. The config file name must be placed in the same directory as your exe file, and must be named the same as your exe file, plus a .config extension.

Solution

1.Create a config file for the powershell_ise.exe called powershell_ise.exe.config and place this in the PowerShell directory:
C:WindowsSystem32WindowsPowerShellv1.0

2. Add the following to your powershell_ise.exe.config file:


<?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <startup useLegacyV2RuntimeActivationPolicy=”true”> <supportedRuntime version=”v4.0″ /> </startup> <runtime> <generatePublisherEvidence enabled=”false” /> </runtime> </configuration>

Thanks to Richard Fennel’s post “Mixed mode assembly is built against version ‘v2.0.50727’ error using .NET 4 Development Web Server”, which helped me fix this issue.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s