Exception RPC_E_SERVERFAULT(0x80010105) : While adding ArcGIS Map Service through TCP

10251
11
05-08-2013 04:05 AM
prashantk
New Contributor III
Hi all,

I am trying to add ArcGIS Map Service into ArcDesktop.I have implemented the code on ESRI command and is working fine.
Same code is not working on below scenarios,

1. Receiving data through TCP duplex communication channel(Policy server) and on message receive event,execute the add layer code..
2. Receiving data from clipbard.

On both cases i am removing manual button click event to add data.

Processing of data starts on event raised from TCP or Clipbord in Arcmap environment(C# Arcobject).

System is throwing com exception in below step.

 map.AddLayer(layer); 

Error ...
ESRI.ArcGIS.Carto 
Message = "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"


Any help would be appreciated,

Thanks,
Prashant
0 Kudos
11 Replies
RichardWatson
Frequent Contributor
Is your code executing on a worker thread?

If so then you might try executing it on the main thread.
0 Kudos
prashantk
New Contributor III
Thanks Richard,

Yes,my code is running under "Working thread with MTA ApartmentState".I tried using background worker,Timer,New thread but no success.

Could you please explain how to run worker thread into main thread in ArcMap environment.

Any help would be appreciated.

Thanks,
Prashant
0 Kudos
RichardWatson
Frequent Contributor
ArcObjects are pure COM STA, i.e. if you access them from a thread then that thread must be STA.

If that doesn't work for you then try to force calls to the main thread.  Google on ".net invoke on ui thread" to see how to do that.

Good luck!
0 Kudos
prashantk
New Contributor III
Richard,

I tried to run the code on STA thread but still getting same error while adding layer (map.addlayer(ILayer)) method.

I have started new thread with STA apartment state and i before adding to layer checked thread property using

Thread _cThread =  Thread.CurrentThread;


thread is running under ApartmentState.STA but still getting same error.I am using below code to start new thread.

  Thread _newThread = new Thread(ThreadStart);
            _newThread.SetApartmentState(ApartmentState.STA);
            _newThread.Start();
            _newThread.Join();
0 Kudos
RichardWatson
Frequent Contributor
If you can't get this to work on a worker thread then marshal the call from the worker thread to the main thread and do it there.  It is hard to provide better advice because I can't see your code.

If you don't know how to do this then Google on something like "c# invoke method on main thread".  This topic has been widely discussed so you will find that you have many options.
0 Kudos
prashantk
New Contributor III
Hi Richard,

Thanks for your quick reply.

I have created one static class with event and thread,Using this class i am invoking event the main thread.Thread is running on STA apartment state.But still getting same error.

Please find the attached sample code to reproduce the error(Invoking on UI thread not added).
In ClipBoardHandler.cs ,AddWebServiceLayer() method is throwing exception on  pMap.AddLayer(srvLayer) step.


Thanks,
Prashant
0 Kudos
RichardWatson
Frequent Contributor
I don't really understand what you are doing here.

Is the function ClipBoardHandler::ReadClipboardData called on the main thread?

If you don't know then set a breakpoint and see.  You can also get the thread identifier in code and log it.

Why are you even creating another thread in this function?  This confuses me because you create it and then wait on it.  What value did the thread add?

You are accessing IApplication from a worker thread which I believe is the source of your problem.  The fact that the worker thread is COM MTA does not help.  DO NOT PASS ArcObject across threads!
0 Kudos
prashantk
New Contributor III
I don't really understand what you are doing here.

Ans: Attached sample code is to reproduce the error.Trying to replicate real scenario with the simple code

Is the function ClipBoardHandler::ReadClipboardData called on the main thread?

Ans: Yes.To reproduce error,i have started thread MTA thread (MTA)

If you don't know then set a breakpoint and see. You can also get the thread identifier in code and log it.

Why are you even creating another thread in this function? This confuses me because you create it and then wait on it. What value did the thread add?

Ans: I am using Messaging service to communicate between web application and ArcMap.
After starting communication between Web and Desktop application,I received data in desktop application listener.Default listener method is running under MTA thread and the application starts throwing error. So i have created another thread function

You are accessing IApplication from a worker thread which I believe is the source of your problem. The fact that the worker thread is COM MTA does not help. DO NOT PASS ArcObject across threads!
Ans: In actual code i am not passing ArcObject across threads.I tried to access worker thread on main thread but no success,Still facing same problem.

Thanks,
Prashant
0 Kudos
RichardWatson
Frequent Contributor
If you can post a simple example which reproduces the problem, only uses STA threads to access ArcObjects, and does not access ArcObjects across threads (i.e. only accesses them on the thread that they were created on) then please do so.  No promises, but I'll look at it.

Sorry, but I am out of suggestions.  Sometimes it is difficult to help others via forum messages and email.
0 Kudos