Class Snapin References

Use this forum to ask questions before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
User avatar
JDruhan
Posts: 10
Joined: Thu May 25, 2017 11:22 am

Class Snapin References

Post by JDruhan » Wed May 31, 2017 10:38 am

When building a class with PowerShell Studio 2017 [5.4.140 / x64] ..

The class references Microsoft.SharePoint.PowerShell Snapin objects but the snapin is not actually loaded in the class. This means the PowerShell Studio shows (!) errors when using referencing Microsoft.SharePoint.PowerShell types.

Is there any way to add a reference to this class that says it uses Microsoft.SharePoint.PowerShell and treat all cmds as if this snapin is loaded?

User avatar
davidc
Posts: 5889
Joined: Thu Aug 18, 2011 4:56 am

Re: Class Snapin References

Post by davidc » Wed May 31, 2017 11:16 am

Can you upload a sample script demonstrating the issue?

https://www.sapien.com/support/upload

Thank you,
David
SAPIEN Technologies, Inc.

User avatar
JDruhan
Posts: 10
Joined: Thu May 25, 2017 11:22 am

Re: Class Snapin References

Post by JDruhan » Wed May 31, 2017 11:40 am

Done.

For more details .. as mentioned above the class utilizes the SharePoint snapin however the snapin isn't actually loaded via the class (its loaded in another script prior to the class being instantiated. So it is understandable that PowerShell Studio does not recognize the types being used.

But there should be some way to tell PowerShell Studio that the [Microsoft.SharePoint.PowerShell] snapin is added elsewhere and to accept all properties / types and method from that module.

User avatar
Alexander Riedel
Posts: 6952
Joined: Tue May 29, 2007 4:43 pm

Re: Class Snapin References

Post by Alexander Riedel » Wed May 31, 2017 11:47 am

Topic moved by moderator. Please always post in the forum best suited for your question to avoid delays and ensure proper responses.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
davidc
Posts: 5889
Joined: Thu Aug 18, 2011 4:56 am

Re: Class Snapin References

Post by davidc » Wed May 31, 2017 3:00 pm

I loaded the same file within the ISE and got the same result. When PowerShell checks the syntax of the file, it attempts to validate the types the class is dependent on.

Currently, PowerShell Studio runs its syntax check independent of the session / runspace. In addition, PowerShell Studio resets the runspace every time you run a script in order to prevent dependencies on modified variables and to ensure the script will run correctly from start to finish.
David
SAPIEN Technologies, Inc.

User avatar
JDruhan
Posts: 10
Joined: Thu May 25, 2017 11:22 am

Re: Class Snapin References

Post by JDruhan » Thu Jun 01, 2017 6:53 am

Hi David,

That makes sense. This presents a number of challenges as the software reports problems where no actual problems exist, there is no PrimalSense and finally you can't retrieve and help for functions your using.

It would be great if PowerShell Studio allowed you to insert a reference snapin/module for your project which supersedes the class check of available modules. This would allow you to develop classes far more effectively.

User avatar
davidc
Posts: 5889
Joined: Thu Aug 18, 2011 4:56 am

Re: Class Snapin References

Post by davidc » Thu Jun 01, 2017 8:14 am

We will investigate this further and see what our options are.

FYI, for PrimalSense purposes, you can reference .NET assemblies directly in PowerShell Studio using Ribbon->Home->Edit->Assemblies. If you are working with a ps1, I recommend using an Add-Type statement with the Path parameter pointing to the assembly on disk. This will trigger the PrimalSense to load the assembly (This will not change the syntax check error).
David
SAPIEN Technologies, Inc.