WMF 5.1 class fails in PSS

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 6 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

WMF 5.1 class fails in PSS

Post by jvierra »

PSS current.
W10/WMF5.1

The following code works in PS but fails to parse in PSS.
class_parse.png
class_parse.png (55.73 KiB) Viewed 1874 times

Code: Select all

using assembly System.Xml.Linq
using namespace System.Xml.Linq
class error{
    [string]$type = 'test'
    [string]$message ='new message'
    error() { }
        [XElement]ToXElement() {
        $el = New-Object XElement([XName]'error')
        $attrType = New-Object XAttribute([XName]'type'), $this.type
        $el.Add($attrType)
        $elDesc = New-Object XElement([XName] "desc"), $this.message
        $el.Add($elDesc)
        return $el
    }
}
$e = [error]::New()
$e.ToXElement()
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: WMF 5.1 class fails in PSS

Post by davidc »

It is PowerShell engine's parser is reporting this. Apparently, it doesn't take the using assembly statement into account.

FYI, in the next service release PowerShell Studio will evaluate the using assembly statement for PrimalSense and syntax coloring purposes.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: WMF 5.1 class fails in PSS

Post by jvierra »

I know that. I just wanted to see if you were aware of it. It has been somewhat annoying but ... a work in progress. Keep up the good work.

My guess is that you are missing a Net reference somewhere. On 5.1 there is no issue outside of PSS.

I just noticed that this does not work in PSS.

Add-Type -AssemblyName System.Xml.Linq
using namespace System.Xml.Linq
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: WMF 5.1 class fails in PSS

Post by davidc »

Can you elaborate on what does not work mean? Are you getting an error message? Because according to PowerShell documentation, the using statement must be at the top of the script.

If you move the Add-Type below the using statement PowerShell Studio will color the XElement type but that doesn't affect the syntax check.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: WMF 5.1 class fails in PSS

Post by jvierra »

The following works in PowerShell
aaa1.png
aaa1.png (98.43 KiB) Viewed 1839 times
but PSS shows errors:
aaaa1.png
aaaa1.png (57.27 KiB) Viewed 1839 times
This topic is 6 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.