Odd Noob Issue

Jun 7, 2013 at 1:22 PM
I was looking to use ShowUI in place of Primal for some simple user facing scripts but ran into an issue. The environment in question is Server 2003 with PowerShell 2 and ShowUI 1.4.

When I use PowerGUI to develop the interface and import the module I have no issues (aside from a previously report "long" initial import time for x86 PowerShell).

When I use PowerShell.exe or the Windows PowerShell ISE to create scripts, the module importation fails mid-import. Some cmdlets are available, but none after the failure point.

import-Module showui
_Exception calling "FixSerialization" with "0" argument(s): "Request failed."
At \acct.upmchs.net\etg\CitrixRemote\PowerShell\MODULES\showui\ShowUI.psm1:137 char:38
  • [ShowUI.XamlTricks]::FixSerialization <<<< ()
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodException_
Any ideas on what may be causing this?
Coordinator
Jun 7, 2013 at 1:51 PM
That's really weird -- don't think anyone's ever had a failure with FixSerialization before.
What version of .Net do you have available: 3.0 or 3.5 or 4.0 or 4.5?
Can you dig into the StackTrace or InnerException properties on the $Error to figure out what really failed?
Aug 23, 2013 at 8:18 AM
Edited Aug 23, 2013 at 10:54 AM
Looks like I have the exact same issue (running on Windows 7, PowerShell 3 and ShowUI 1.4).
If I start PowerShell as admin it works fine and I find all ShowUI Functions and Cmdlets, but as a normal user I only find the Functions and no Cmdlets.
Maybe that can give a clue to what went wrong...

Import-Module ShowUI gives the following error from a normal user:

Import-Module : Could not load file or assembly 'file:///H:\data\WindowsPowerShell\Modules\ShowUI\GeneratedAssemblies\ShowUI.CLR4.0.30319.1008.dll' or one of its dependencies. Operation is
not supported. (Exception from HRESULT: 0x80131515)
At H:\data\WindowsPowerShell\Modules\ShowUI\ShowUI.psm1:111 char:24
  • $importedModule = Import-Module $CommandsPath, $CoreOutputPath -PassThru
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException
    • FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
Unable to find type [ShowUI.XamlTricks]: make sure that the assembly containing this type is loaded.
At H:\data\WindowsPowerShell\Modules\ShowUI\ShowUI.psm1:137 char:1
  • [ShowUI.XamlTricks]::FixSerialization()
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (ShowUI.XamlTricks:TypeName) [], RuntimeException
    • FullyQualifiedErrorId : TypeNotFound

Looking in the Modules\ShowUI folder I find this file:
ShowUI.CLR2.0.50727.4963.dll, but not this:
ShowUI.CLR4.0.30319.1008.dll as mentioned in the error.

In the ShowUI.psm1 file I find these lines:
$CommandsPath = "$psScriptRoot\GeneratedAssemblies\ShowUI.CLR$($psVersionTable.clrVersion).dll"
$CoreOutputPath = "$psScriptRoot\GeneratedAssemblies\ShowUICore.CLR$($psVersionTable.clrVersion).dll"
Since the value of $psVersionTable.clrVersion is not matching the value in the filename, it gives an error...
But why is all working fine when I run PowerShell as admin ?
I guess its the same files involved and $psVersionTable.clrVersion holds the same value ??
Coordinator
Aug 23, 2013 at 5:09 PM
H Drive eh?

I'm having a hard time figuring what went wrong here (and since you obviously read code) let's start with this: part of the PSM1 should look like this:
if ((Test-Path $CommandsPath, $CoreOutputPath) -notcontains $False) {
    $importedModule  = Import-Module $CommandsPath, $CoreOutputPath -PassThru
} else {
It shouldn't be trying to load the assemblies unless it's already verified they exist!

The "Operation Not Supported" reminds me vaguely of the errors we used to get (in PowerShell 2) when the assemblies are in a network location, but that's not supposed to be an issue in PowerShell3 because it moved to .Net 4 (which changed the security policy)...

In any case, let's try this:
  1. If you have customized any Styles (in StyleSystem\Styles), back them up
  2. Manually delete all the files from that "GeneratedAssemblies" folder (just in case)
  3. Run: Import-Module ShowUI -Min 1.4 -Force -Args Clean
The -Args Clean will remove styles and assemblies, and should recompile them.

Let me know if that solves the problem or not. :-)
Aug 26, 2013 at 8:02 AM
Hi,

Thanks for your help and suggestions. I've tried it, but didn't solve the problem :-(
The same files was recompiled:
ShowUI.CLR4.0.30319.1008.dll
ShowUI.CLR4.0.30319.1008.pdb
ShowUICore.CLR4.0.30319.1008.dll
ShowUICore.CLR4.0.30319.1008.pdb

and ended up in a simular error:

PS H:> Import-Module ShowUI -Min 1.4 -Force -Args Clean
Import-Module : Could not load file or assembly 'file:///H:\data\WindowsPowerShell\Modules\ShowUI\GeneratedAssemblies\ShowUI.CLR4.0.30319.1008.dll' or one of
its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At H:\data\WindowsPowerShell\Modules\ShowUI\ShowUI.psm1:129 char:28
  • $importedModule = Import-Module $CommandsPath, $CoreOutputPath -PassThr ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException
    • FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
Unable to find type [ShowUI.XamlTricks]: make sure that the assembly containing this type is loaded.
At H:\data\WindowsPowerShell\Modules\ShowUI\ShowUI.psm1:137 char:1
  • [ShowUI.XamlTricks]::FixSerialization()
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (ShowUI.XamlTricks:TypeName) [
      ], RuntimeException
    • FullyQualifiedErrorId : TypeNotFound
PS H:>
Coordinator
Aug 26, 2013 at 4:50 PM
So yeah, I'm not quite sure why this is happening on .Net4, but I think probably you're having problems because H: is a network drive, and not allowed (it's supposed to be allowed, in .Net4, but anyway) ... you need to change your app.config (the PowerShell.exe.config that you edited to get it to use .net4 in the first place) to allow remote assemblies. Something like this:
<configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" />
   </startup>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>
The startup/supportedRuntime makes it load .net4 ... the runtime/loadFromRemoteSources lets it load assemblies from network paths (which is supposed to be the default in .net 4, but maybe if you did useLegacyV2RuntimeActivationPolicy="true" that turns it off, I'm not sure, but LegacyV2RuntimeActivation is required to let some binary modules like BitsTransfer and SQLPS continue working.