Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

XamlParseException

Greetings from Michigan,

In my application, I'm placing a meter control onto the second tab of a tab control.  The application appears to build fine, but when I run it, it throws a "XamlParseException" exception.  The exception appears to only occur with the Meter, Gauge, and Tank controls.  All standard VS controls work fine.  Again, it only appears when I place the control within the tab control (second tab).  I have tried all of the simple/easy things that I know of, rebuild, Clean, restart VS, restart machine, etc.  I am uploading the entire solution in a zip file to Mediafire, so if anyone can help me out, I would be very grateful.  I require to place a meter control within the groupbox on the second tab of the tab control.  See images and solution file.  I'm new to XAML and WPF and this is my first WPF application.

 

Thank you

 

Solution File from Mediafire

 

Exception1.jpgException2.jpg

 

0 Kudos
Message 1 of 7
(2,733 Views)

Hi Mmaker,

 

What version of Visual Studio and Measurement Studio are you using? Also, what operating system are you using as well?

 

When I ran your code, I got the following error:

 

XAML Error Capture.PNG

 

If you try and make a new application, and add one of the controls you listed (just the control, no extra logic) does the same behavior occur?

Applications Engineering
National Instruments
0 Kudos
Message 2 of 7
(2,708 Views)

It looks like you have run into the same issue as this question. There is already a task to fix this in the next version of Measurement Studio, but until then you can work around the problem by inheriting from the gauge class and returning this custom enumerator to avoid the faulty reset logic:

Class ResetableEnumeratorWrapper
    Implements IEnumerator

    Private ReadOnly getEnumerator As Func(Of IEnumerator)
    Private enumeratorValue As IEnumerator

    Public Sub New(getEnumerator As Func(Of IEnumerator))
        MyClass.getEnumerator = getEnumerator
    End Sub

    Private ReadOnly Property Enumerator As IEnumerator
        Get
            If (enumeratorValue Is Nothing) Then
                enumeratorValue = getEnumerator()
            End If

            Return enumeratorValue
        End Get
    End Property

    Public ReadOnly Property Current As Object Implements IEnumerator.Current
        Get
            Return Enumerator.Current
        End Get
    End Property

    Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
        Return Enumerator.MoveNext
    End Function

    Public Sub Reset() Implements IEnumerator.Reset
        Dim oldEnumeratorValue = TryCast(enumeratorValue, IDisposable)
        Using (oldEnumeratorValue)
            enumeratorValue = Nothing
        End Using
    End Sub

End Class

Class MyGaugeDouble
    Inherits GaugeDouble

    Protected Overrides ReadOnly Property LogicalChildren As IEnumerator
        Get
            Return New ResetableEnumeratorWrapper(
                Function()
                    Return MyBase.LogicalChildren
                End Function)
        End Get
    End Property

End Class

In MainWindow.xaml, simply replace ni:GaugeDouble with local:MyGaugeDouble to enable the workaround.

~ Paul H
0 Kudos
Message 3 of 7
(2,707 Views)

Thank you for your reply.  My OS is Windows 10.  Visual Studio 2012 Pro with Measurement Studio 2015 Enterprise.  Yes, as you describe, yesterday I tried creating a separate application with a tab control and two tabs and then adding the MS controls in question.  It compiled and ran fine.  In my "problem" application, there is not any business logic code other than declaring some variables and maybe a Class or two as I haven't done much with the code and I'm just doing the UI design right now.  I'm creating the UI in Blend, and not writing any XAML code manually.  So, I don't understand what the problem could be from my actual work application to the "test" application where the controls were fine on (??), hence asking some that are smarter than me.  🙂 .  

 

Were you able to open the application in design view or is that just the exception that was thrown when you tried running the code?  Paul posted a possible work around to my problem, but when is a new version of Measurement Studio scheduled to be released that fixes this issue?  

 

Thanks,

Don

0 Kudos
Message 4 of 7
(2,684 Views)

Paul,

 

Thank you, looks like that worked and fixed the problem!  However....apparently Blend 2012 doesn't like it and now I can't view the application XAML in Design View (Blend 2012).  This may be an inconvenience more than a problem or deal breaker.  In Blend 2017, its fine and I can view it there.  But I've had issues with attempting to view and make changes to the UI design in Blend 2017 because it doesn't have Measurement Studio installed/licensed to it.  So every so often, a control will just disappear off the design in Blend 2017 and throw an exception error until I delete the control completely off the design.  Blend is where I'm doing all of the design work, as I prefer that to writing XAML code.  

 

I certainly appreciate the help going forward so I thank you and the Measurement Studio team for that. I must say though that I'm a bit dismayed as to why these WPF controls don't work right out of the box like they should and there is required all this work around code on the developer's end to make it work (?).  It appears I'm going to have to implement the same code for the Tank and Meter controls and any other control with the same issues (Chart, graph?).  Thank you.

0 Kudos
Message 5 of 7
(2,692 Views)

Yes, I am afraid most of the Measurement Studio controls have this issue in the currently. It only occurs for more complex layouts when WPF conducts repeated element name searches, which is why it was not caught before release.

 

I have Blend 2012 on the test machine, but I could not reproduce the error you are seeing: after running the project in Visual Studio, all tabs also displayed correctly in Blend. Assuming a rebuild does not fix the issue, perhaps moving the gauge into a user control would avoid the Blend issue?

~ Paul H
0 Kudos
Message 6 of 7
(2,687 Views)

Just wanted to let you know this issue was fixed in the Measurement Studio 2019 release.

~ Paul H
0 Kudos
Message 7 of 7
(2,227 Views)