Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new-object - cannot find type VNVDTrafficFilterPolicyConfig - verify assembly containing this type is loaded #1

Open
JulianCeaser opened this issue Jan 12, 2018 · 11 comments
Assignees

Comments

@JulianCeaser
Copy link

JulianCeaser commented Jan 12, 2018

When I am using this module in my script and calling the script from the commandline I am getting the following error.

New-Object : Cannot find type [VNVDTrafficFilterPolicyConfig]: verify that the assembly containing this type is loaded.
At C:\Program Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\GetItems.ps1:22 char:4
+             New-Object -Type VNVDTrafficFilterPolicyConfig -Property  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

This only happens when I am calling the script from the windows console or powershell but does not occur when I am running the script from within powershell ISE.

I have found that the offending line is

Get-VDSwitch -name $VDSwitchName | Get-VDPortGroup -name $VDPortGroup | Get-VNVDTrafficFilterPolicyConfig

Why is this happening and how could I solve this ?

For testing I am running this small test script, after installing vNugglets.VDNetworking.

import-module vNugglets.VDNetworking
Connect-VIServer -Server $serverip -Protocol https -User $username -Password $pass
get-vdswitch -name $vswitch | get-vdportgroup -name $vport | get-vnvdtrafficfilterpolicyconfig
@mtboren mtboren self-assigned this Jan 12, 2018
@mtboren
Copy link
Member

mtboren commented Jan 12, 2018

Greetings, @JulianCeaser-

All good in the ISE PS console, but not in a "regular" PowerShell session, you say.

So, as we can see from the error message, that custom type ([VNVDTrafficFilterPolicyConfig]) seems to not be accessible in the sessions in which you are having the issue.

In efforts to troubleshoot, could you please, in both the ISE PS console and a PowerShell.exe console:

  • Check that any of the other custom types are available in each session. Something like:
PS C:\> [VNVDTrafficRuleset]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VNVDTrafficRuleSet                       VNVDBase



PS C:\> [VNVDTrafficRule]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VNVDTrafficRule                          VNVDBase

Are the given sessions able to find these other types, and you get returns like this?

@JulianCeaser
Copy link
Author

JulianCeaser commented Jan 13, 2018

ISE PS console

PS C:\Users\Administrator> [vnvdtrafficrule]

IsPublic IsSerial Name                                     BaseType                                                                                                                    
-------- -------- ----                                     --------                                                                                                                    
True     False    VNVDTrafficRule                          VNVDBase                                                                                                                    

PS C:\Users\Administrator> [vnvdtrafficruleset]

IsPublic IsSerial Name                                     BaseType                                                                                                                    
-------- -------- ----                                     --------                                                                                                                    
True     False    VNVDTrafficRuleSet                       VNVDBase      

PS C:\Users\Administrator> [vnvdtrafficfilterconfig]
Unable to find type [vnvdtrafficfilterconfig].
At line:1 char:1
+ [vnvdtrafficfilterconfig]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (vnvdtrafficfilterconfig:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Powershell.exe

PS C:\Users\Administrator> [vnvdtrafficruleset]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VNVDTrafficRuleSet                       VNVDBase

PS C:\Users\Administrator> [vnvdtrafficrule]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VNVDTrafficRule                          VNVDBase

PS C:\Users\Administrator\Documents> [vnvdtrafficfilterconfig]
Unable to find type [vnvdtrafficfilterconfig].
At line:1 char:1
+ [vnvdtrafficfilterconfig]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (vnvdtrafficfilterconfig:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

When calling powershell.exe from command prompt

C:\Users\Administrator>powershell.exe [vnvdtrafficruleset]
Unable to find type [vnvdtrafficruleset].
At line:1 char:1
+ [vnvdtrafficruleset]
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (vnvdtrafficruleset:TypeName)
   [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

C:\Users\Administrator\Documents>powershell.exe [vnvdtrafficrule]
Unable to find type [vnvdtrafficrule].
At line:1 char:1
+ [vnvdtrafficrule]
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (vnvdtrafficrule:TypeName) [],
    RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

C:\Users\Administrator\Documents>powershell.exe [vnvdtrafficfilterconfig]
Unable to find type [vnvdtrafficfilterconfig].
At line:1 char:1
+ [vnvdtrafficfilterconfig]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (vnvdtrafficfilterconfig:TypeN
   ame) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

I am trying to automate the script using task scheduler so being accessible from the command prompt is pretty important to me. Please inform me how I can help you debug.

@JulianCeaser
Copy link
Author

Does the powershell script need to have
Import-Module vNugglets.VDNetworking
?

If I do add it and call the script I get this error for

Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\GetItems.ps1:13
char:2
+     [OutputType([VNVDTrafficFilterPolicyConfig])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

@mtboren
Copy link
Member

mtboren commented Jan 13, 2018

Hello-

Thanks for the debugging efforts, and for providing the output here.

A couple of things:

  • the error that you reported in your troubleshooting response of Unable to find type [vnvdtrafficfilterconfig] is due to testing an incorrect type name -- the actual typename is VNVDTrafficFilterPolicyConfig (notice the "Policy" part in the type name). So, I imagine that in those two sessions (ISE, PowerShell.exe), you would have success when using that actual typename, like:
PS C:\> [VNVDTrafficFilterPolicyConfig]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VNVDTrafficFilterPolicyConfig            VNVDBase
  • As for, "Should the PowerShell script have an Import-Module vNugglets.VDNetworking statement in it?" -- for best and most predictable behavior, yes, we should explicitly import the modules that our scripts need.

But, that does not explain the behavior that you showed in which there are Multiple ambiguous overloads found for ".ctor"....

To continue the troubleshooting, let us try launching your script with PowerShell.exe with the "-NoProfile" argument to PowerShell.exe. So, put the necessary Import-Module statements into the test .ps1 script, then invoke it from command prompt like:

C:\>powershell.exe -NoProfile -Command & c:\myscripts\MyGetTrafficFilterStuff.ps1

@JulianCeaser
Copy link
Author

  1. After doing correction in the two sessions I did get the correct answer.
PS C:\Users\Administrator> import-module vNugglets.VDNetworking
PS C:\Users\Administrator> [VNVDTrafficFilterPolicyConfig]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VNVDTrafficFilterPolicyConfig            VNVDBase

  1. After making the changes it still did not help.
    C:\>powershell.exe -NoProfile -Command & c:\myscripts\MyGetTrafficFilterStuff.ps1
C:\Users\Administrator>powershell.exe -noprofile -command Documents\test.ps1
Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\GetItems.ps1:13
char:2
+     [OutputType([VNVDTrafficFilterPolicyConfig])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\GetItems.ps1:48
char:2
+     [OutputType([VNVDTrafficRuleSet])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\GetItems.ps1:111
char:2
+     [OutputType([VNVDTrafficRule])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\NewItems.ps1:319
char:2
+     [OutputType([VNVDTrafficRule])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\SetItems.ps1:17
char:2
+     [OutputType([VNVDTrafficRuleSet])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Multiple ambiguous overloads found for ".ctor" and the argument count: "1".
At C:\Program Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\vNug
glets.VDNetworking_SupportingFunctions.ps1:23 char:2
+     [OutputType([VNVDTrafficRuleSet])]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest


Name                           Port  User
----                           ----  ----
192.168.9.236                  443   VSPHERE.SECEON\Administrator
New-Object : Cannot find type [VNVDTrafficFilterPolicyConfig]: verify that the
assembly containing this type is loaded.
At C:\Program
Files\WindowsPowerShell\Modules\vNugglets.VDNetworking\1.1.0\GetItems.ps1:22
char:4
+             New-Object -Type VNVDTrafficFilterPolicyConfig -Property  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentExcepti
   on
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewOb
   jectCommand

@mtboren
Copy link
Member

mtboren commented Jan 18, 2018

Thanks for continuing to troubleshoot this.

As for some more details about when/where this is happening:

  • what is the means by which that Documents\test.ps1 script is loading modules? Can you share that portion of the script (or, the whole of a script that is giving these symptoms)? Share nothing confidential, of course, just any "sterilized" code that you can share will be helpful
  • on what subset of Windows machines is this happening for you (all machines, some machines, server OS / desktop OS only, etc.)?

Matt

@JulianCeaser
Copy link
Author

Sure this is what is in test.ps1

import-module vNugglets.VDNetworking
Connect-VIServer -Server 192.168.xxx.xxx -Protocol https -User xxxxxx -Password xxxxx
get-vdswitch -name 'vdswitch vds' | get-vdportgroup -name 'vmnet1' | get-vnvdtrafficfilterpolicyconfig

I am running this on Windows Server 2012 R2 virtual machine.

PS C:\Users\Administrator> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.10586.117
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.117
CLRVersion                     4.0.30319.34014
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@mtboren
Copy link
Member

mtboren commented Jan 23, 2018

Thanks for that. I've been trying to reproduce the error, and am failing so far (including on a Win2012R2 VM w/ that same WMF5.0 PowerShell version). Meanwhile, another question for you: is this happening on all of your Win2012R2 machines, or just some, or just this one?

@Nick-Andreev
Copy link

"using module vNugglets.VDNetworking" instead of "Import-Module vNugglets.VDNetworking" solved it for me, according to Import-Module page on MSFT site:

If the module includes class and enum definitions, use using module at the beginning of your script. This import the scripts, including the class and enum definitions. For more information, see about_Using.

Reference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7

@mtboren
Copy link
Member

mtboren commented May 26, 2020

Thanks, @Nick-Andreev -- that's an important and subtle tidbit.

@JulianCeaser :

  1. are you still having these issues?
  2. does using the statement using module vNugglets.VDNetworking instead of Import-Module vNugglets.VDNetworking at the start of your script work around / solve the issue?

And, if we haven't already enjoyed this help topic, there is the abou_Using topic available via Get-Help or online at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_using?view=powershell-7

@Nick-Andreev
Copy link

Nick-Andreev commented May 27, 2020

You are not alone in this. It seems that classes in PowerShell have been broken for a while and it might be wise to avoid them, until they work out what to do with this long list of issues: PowerShell/PowerShell#6652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants