I have recently noticed the .NET RemotingExample for NX10. I started the server code from this sample with run_managed.exe and accessed the NX session from a client. Unfortunately I always got the following status message when I tried to open a .prt file: "SM function called from the wrong thread".
Does anyone know a workaround for this problem?
Solved! Go to Solution.
That is a pretty bare-bones description, but are you calling any NXOpen from anyplace other than the main thread? Trying to do that does cause a thread error/exception, but I don't remember offhand whether it is this one.
Thank you for your reply. Here is a more precise description:
1. I compiled the Remoting Example which is located at $NXInstallDir\UGOPEN\SampleNXOpenApplications\.NET
2. I modified the NXOpenRemotingClient class (at ...\RemotingExample\Client) to open a .prt file with theSession.Parts.Open(..) via the remote NxSession object (http://localhost:4567/NXOpenSession at this time).
3. I started the Client and got the exception I have mentioned before.
Did the progam that you started in step 1 continue running? Unless you made some substantial changes to the code, it seems like it would just register a listener and then finish executing, in which case there is no session to accept connections from the client.
I did not make any changes to the server code. This is the Run() method:
public static void Run()
DoLog("In NXOpenRemotingService.Main - getting session\n");
theSession = Session.GetSession();
theUFSession = UFSession.GetUFSession();
DoLog("Starting NX Service\n");
LifetimeServices.LeaseTime = System.TimeSpan.FromDays(10000);
SoapServerFormatterSinkProvider provider = new SoapServerFormatterSinkProvider();
provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilter
// Create the IDictionary to set the port on the channel instance.
IDictionary props = new Hashtable();
props["port"] = port;
// Create a new http channel with the given provider and properties
ChannelServices.RegisterChannel(new HttpChannel(props, null, provider), false);
DoLog("Exporting Session object");
DoLog("Exporting UFSession Object");
DoLog("NX Service started on port " + port + "\n");
catch (Exception e)
serviceEnded = true;
Because of the while loop it runs until i terminate the run_managed.exe manually. I get a valid NxSession object when calling
Session theSession = (Session)Activator.GetObject(typeof(Session), "http://localhost:4567/NXOpenSession");
within the Client code. Moreover, theSession.Parts.FileNew() does not seem to be a problem. But whenever i call theSession.Parts.Open(...) with an existing .prt file path, it ends up with an exception.
It turns out that this was reported as a Problem with the the initial releases of NX10:
Description of Problem: Remoting into an external dedicated server process (no NX UI) no longer works. Multiple commands (open a part, create a new part, edit an expression) fail. The server syslog shows:
Exception in secondary thread <#>
+++ SM call for area SM system transient area 0 from wrong thread
This is a serious regression starting in NX10.
The only known work around is to use a server running in internal mode with the NX UI. This is not acceptable to my customer, please provide a fix in an NX10 release ASAP as this is holding up their being able to support their plug-in for use with NX10.
It is reportedly fixed initially in NX10.0.2, MP2, so please try that release, or any higher version of NX10.
If you do that, and you still have the problem, please log an IR with GTAC. If it has occurred again in a later release we can reopen the PR and have development look at it again. (We will want your syslog.)
I'm sorry that I didn't spot this one sooner!