Unable to find custom class cross files

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION 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.
This topic is 7 years and 4 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
claussen
Posts: 19
Last visit: Mon Jan 29, 2024 10:40 am

Unable to find custom class cross files

Post by claussen »

Product, version and build: PSS2016 5.2.129
32 or 64 bit version of product: 64
Operating system: Win 10 Ent 1511
32 or 64 bit OS: 64
PowerShell Version: 5.0.10586.494

Hi,

I have a project in which all of my files are set to Build:Include and CommandExtension:True... However, when I reference a custom class from another file, PSS thinks it is an error because it cannot find it. Within the same file, there is no problem. Is there any hope of it finding the class...and even utilizing PrimalSense?
Code: [Select all] [Expand/Collapse] [Download] (CustomClass1.ps1)
  1. class CustomClass1 {
  2.  <# blah blah #>
  3. }
Code: [Select all] [Expand/Collapse] [Download] (OtherFile.ps1)
  1. $var = [CustomClass1]::new()   # This line errors stating it cannot find the type [CustomClass1].
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Unable to find custom class cross files

Post by davidc »

Without seeing the project it is hard to tell what is happening. I suspect that the instantiation line is being called before the class is declared in the script. The order in which the file is merged into the final script may be the cause.
David
SAPIEN Technologies, Inc.
User avatar
claussen
Posts: 19
Last visit: Mon Jan 29, 2024 10:40 am

Re: Unable to find custom class cross files

Post by claussen »

Unfortunately this is simply happening in PSS before I ever export the file. I have edited the psproj file (moving lines up and down) to ensure the classes are loaded first when I do deploy the script (which, when I export, class instantiation works as expected).

When in PSS, if I go to any of the files listed after Password.ps1 (as shown in the psproj file below), PSS doesn't know that [Password] is a type which is defined in Password.ps1. The [Password] class definition actually references [PasswordProperties], and PSS thinks it doesn't exist. Upon deployment, everything works properly.

If I instantiate a new instance of [Password] in the Password.ps1 file, the type is recognized. Anywhere else, PSS doesn't recognize it.

It doesn't actually harm anything, however its disconcerting to see red squigglies under my code :)
Code: [Select all] [Expand/Collapse] [Download] (MyProject.psproj)
  1. <Project>
  2.   <Version>1.1</Version>
  3.   <FileID>929fbe82-a396-4d52-bbaa-b1f0d67e59f8</FileID>
  4.   <ProjectType>0</ProjectType>
  5.   <Folders>
  6.     <Folder>Functions</Folder>
  7.     <Folder>Classes</Folder>
  8.     <Folder>Classes\Base</Folder>
  9.     <Folder>Classes\DASL</Folder>
  10.     <Folder>Functions\Logging</Folder>
  11.   </Folders>
  12.   <Files>
  13.     <File ReferenceName="" Build="0">Startup.pss</File>
  14.     <File ReferenceName="Call-PasswordProperties_ps1" Build="0" CommandExtension="True">Classes\Base\PasswordProperties.ps1</File>
  15.     <File ReferenceName="Call-Password_ps1" Build="0" CommandExtension="True">Classes\Base\Password.ps1</File>
  16.     <File ReferenceName="Call-NameParts_ps1" Build="0" CommandExtension="True">Classes\Base\NameParts.ps1</File>
  17.     <File ReferenceName="Call-DASLRecord_ps1" Build="0" CommandExtension="True">Classes\DASL\DASLRecord.ps1</File>
  18.     <File ReferenceName="Call-AccountAttributes_ps1" Build="0" CommandExtension="True">Classes\Base\AccountAttributes.ps1</File>
  19.     <!-- other files... -->
  20.   </Files>
  21. </Project>
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Unable to find custom class cross files

Post by davidc »

Are you getting syntax errors? The syntax checker is limited to the current file contents only. That is why the syntax checker doesn't "see" the other class.
David
SAPIEN Technologies, Inc.
User avatar
claussen
Posts: 19
Last visit: Mon Jan 29, 2024 10:40 am

Re: Unable to find custom class cross files

Post by claussen »

Ah ok. That would be the explanation. I apologize, I should have uploaded a screenshot first:
2016-11-10_11-44-22.png
2016-11-10_11-44-22.png (14.53 KiB) Viewed 1774 times
I assumed the Command Extension file property would treat user-defined classes the same as user-defined functions and allow reference/PrimalSense across the project.

Perhaps this can be considered a feature request?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Unable to find custom class cross files

Post by davidc »

Yes, cross-file syntax coloring and PrimalSense for classes in on our TODO list.
David
SAPIEN Technologies, Inc.
This topic is 7 years and 4 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.