cancel
Showing results for 
Search instead for 
Did you mean: 

Exception thrown by UFsession.Mom.askMom in NX9

I wrote a vb .net script to extend the TCL interpreter for postbuilder.  

The program works well on NX7.5 but the same program does not work on NX9.0. 

 

Here is the code, uggsFn is the entry point: 

Private Shared Ufs As UFSession = UFSession.GetUFSession()
Private Shared theSession As Session = Session.GetSession()
  
Public Shared Function uggsFn(param As String) As Integer

        MsgBox("Hello")
        Dim mom_id As IntPtr = IntPtr.Zero
        
        Ufs.Mom.AskMom(param, mom_id)

        Return 0
End Function

 

The code is extremely simple.  MessageBox is shown in NX when the dll is used by the post builder. But

Ufs.Mom.AskMom(param, mom_id)

gives me error in NX9 but works find in NX7.5. 

 

The exception thrown reads as following:

Caught exception while running: uggsFn
System.InvalidCastException: Conversion from string "?/r??" to type 'Long' is not valid. ---> System.FormatException: Input string was not in a correct format.
   at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDecimal(String Value, NumberFormatInfo NumberFormat)
   at Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value)

Any idea why this is happening?

 

I am running Windows 10 and I tried the program on windows 7 64-bit too. Same result. 

 

Thanks in advance

 

Steph

3 REPLIES

Re: Exception thrown by UFsession.Mom.askMom in NX9

Esteemed Contributor
Esteemed Contributor

This has changed to the following:

 

Dim MOM_ID As IntPtr = IntPtr.Zero
theUFSession.Mom.AskMom(Runtime.InteropServices.Marshal.StringToHGlobalAuto(Args(0)), MOM_ID)
Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: Exception thrown by UFsession.Mom.askMom in NX9

Hi Stefan,

Thank you for your reply. To be clear, do you mean I need to write my function like this?

 

    Public Shared Function uggsFn(Args() As String) As Integer

        MsgBox("Hello")

        Dim mom_id As IntPtr = IntPtr.Zero

        Dim paramPt As IntPtr = CType(param, IntPtr)
 Ufs.Mom.AskMom(Runtime.InteropServices.Marshal.StringToHGlobalAuto(Args(0)), mom_id)
 
        Return 0
    End Function

Re: Exception thrown by UFsession.Mom.askMom in NX9

Genius
Genius

The askMom Method was changed in NX9.

See attached image from the NX9 Release Notes