Class Snapin References

Use this forum to ask questions after your subscription maintenance expires or 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.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
JDruhan
Posts: 10
Last visit: Thu Nov 23, 2017 8:00 am

Class Snapin References

Post by JDruhan »

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: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Class Snapin References

Post by davidc »

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
Last visit: Thu Nov 23, 2017 8:00 am

Re: Class Snapin References

Post by JDruhan »

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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Class Snapin References

Post by Alexander Riedel »

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: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Class Snapin References

Post by davidc »

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
Last visit: Thu Nov 23, 2017 8:00 am

Re: Class Snapin References

Post by JDruhan »

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: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Class Snapin References

Post by davidc »

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.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.