Skip to content

Using external types / classes in Custom PowerShell Classes (v5) results in Parsing Error #2074

@Lindmeier

Description

@Lindmeier

The Issue

I am trying to create a PowerShell-Project with my own custom PowerShell-Classes.
I use explicit type defintion for all attributes of my custom classes. For all integrated .Net-Classes there is now problem, but for other classes (for example external dll) it does not work.
It seems like, that you have to create a Wrapper script which loads the dll / Imports the module and afterwards starts the actual script project (with custom classes) by dotsourcing.

Unfortunately this workaround (Wrapper-Script) does not work out in my scenario --> A automation / orchestration engine only accepts one script...

So is there a way to fix this? The Parser should not throw an error, as you declare (using statement) that you will use classes out of this namespace. If there is something wrong with the class itself.. .this should be a runtime exception, or am I wrong?

Steps to reproduce

using namespace Microsft.ActiveDirectory.Management
#These two do not work, too 
#using module ActiveDirectory
#Import-Module ActiveDirectory

class Test
{
    [Microsoft.ActiveDirectory.Management.ADDomain] $domain;

}
 ...

Expected behavior

no Error Message

Actual behavior

At line:9 char:6
+     [Microsoft.ActiveDirectory.Management.ADDomain] $domain;
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [Microsoft.ActiveDirectory.Management.ADDomain].
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TypeNotFound

In this case with an integrated .NET class it perfectly works.

using namespace System.DirectoryServices.ActiveDirectory 

Class Test 
{ 
    [Domain] $dom = [Domain]::GetCurrentDomain() 
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions