Support Forums

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.

Forum rulesDO 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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.

I have a project with a PS1 file. While editing the PS1 file I click on Assemblies and, of course, at first it starts with the default list of assemblies. I click the plus to add one, click Browse... and select the DLL file in my project's folder, then close the dialog. I click Assemblies in the toolbar again and verify that indeed the DLL has been added to the list.

I now close the project and reopen it. I go back to my PS1 file and click Assemblies and the DLL in my project's folder is no longer present in the list.

I'm doing that for when the script runs, but I was looking for PSS to provide Intellisense/primalsense to the objects while coding. Add-Type doesn't help then, or at least it doesn't seem to work similarly to putting "Import-Module blah" for getting PSS to recognize module functions while coding.

In a single coding session I can add the DLL into the assemblies list and get intellisense/primalsense for the objects from the DLL, but as soon as I close the project and reopen it later PSS does not recognize the object properties or methods until I repeat the process of adding it to the assemblies list again.

I've attached a sample project I made with a dll and the cs files I used to create it. Are you using a path like the first example by chance? If not, then can you please specify what you mean by not the same as the Import-Module support?

Yes, in code I am doing something more like in your first example since I cannot be sure the current directory is $PSScriptRoot. If I do not the assembly may not be found.

What I meant by "Import-Module support" was that when I place an Import-Module command into the code that module's exported commands are now recognized by PrimalSense. Before I add such a statement they are not. Of course, with Add-Module there is no need to specify a path since it looks in $env:PSModulePath for the module. Add-Type does not have an equivalent variable where it searches for DLLs so typically to guarantee an assembly's file is found by Add-Type it is best to compute the assembly's path and use that with Add-Type. So, basically Add-Type would need something like $env:PSAddTypePath to avoid having to computer the assembly's location in the file system.

If the "Assemblies" feature in PSS worked (for this use-case) to allow an assembly's objects to be recognized by PrimalSense then there'd be no need to rely on having the Add-Type command with a literal path in code.

Do you have a coding style recommendation that would allow PrimalSense to work and also guarantee (as much as anything can be guaranteed ) that during runtime the assembly file is located?

PS: assemblies can be loaded in other ways besides Add-Type. [Reflection.Assembly]::LoadFile(), for example. I do not think PSS would recognize assemblies loaded that way either so, again, the Assemblies feature within PSS would be the best way to go.

Also note that my project is a module project so does not have a Startup.pss file.

I tried your method of placing Add-Type -LiteralPath into the code, and while it does seem to work for getting PrimalSense to show the types and methods from the containing objects, it still feels like a kludge.

For example, I am also loading an assembly for EWS which may be different on each system so hard-coding in a path to the file would not work. So I end up doing this to get PrimalSense to work:

Also, existing code is not syntax colored correctly for the added types. For example, here your DLL_Test.ps1 when loaded and after adding a new line of code:

5-2-2017 8-46-12 AM.jpg (55 KiB) Viewed 2086 times

As you can see, existing code is syntax colored as "Text" while newly added code is syntax colored correctly as "Type", but of course if it is saved and reloaded all of it is now syntax colored wrongly as "Text" again.