Nebulae Spiral

Spiralling Golden… and maybe blogging about code.

Archive for the ‘exceptions’ tag

RPC_E_ATTEMPTED_MULTITHREAD

with one comment

Exception information:
Exception type: COMException
Exception message: Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0×80010102 (RPC_E_ATTEMPTED_MULTITHREAD))

ooh yah baby. this ones a doozy.

If you’re running into this in your sharepoint development journey, you have well bypassed the open site / open list / get list item / do stuff with it stage and have moved into the world of creating object representations of your list items, probably databinding that object off the list item to work with it, then populating the listitem columns from the object before saving it. IMHO, this is a nice, clean and managable way of development, BUT you could run into a couple roadblocks. this one looks a tad daunting but its an easy one to get around.

My scenario uses 3 lists. Registrations, Organizations, and Solutions. An Organization has an owner (registration) and 0-many solutions. I know, I know, the organization should be a property of the registration, but i digress…

so i have an organization object. this object has a bunch of fancy properties – address, phone number, etc, etc, and also an Owner and a List<Solution> . During the databind of this object from the listitem, I attempted to set these objects and received the RPC_E_ATTEMPTED_MULTITHREAD error – if you google this error, which you probably have since you landed here, you’ll see some answers that will have you believe that you need to implicitly dispose of the SPSite, SPWeb – you may even be tempted to add a GC.Collect in there.

This didn’t – and still doesn’t – make a whole lot of sense to me because the access to the list item was wrapped in a using statement which of course only works with types that inherit from IDisposable, and will be disposed of when you exit the using statement, right? Right? so you would think that after you access that list item and leave the using statement, the SPSite is disposed of and youre good to go… which is not really the case and I don’t know the intricacies of it all but I do know how to bypass this problem and the answer is – Lazy Loading. yes, serious.

back to my databind…
as I am binding all the properties from the listitem i just retrieved and I try to set the owner which would have to go access that site and get that list item from the registrations list, create a new owner object from that item, the RPC_E_ATTEMPTED_MULTITHREAD error gets thrown. the same when I’m trying to populate the Associated Solutions. If you move the code to populate these properties into the public accessor ( the getter ) so that the property is loaded when it is accessed instead of when the object is databound – poof! problem solved.

If this doesn’t solve your problem, or you’re seeing this error in Sharepoint without having the structure i described above or some format of it, drop me a line and we can figure it out.

cheers,
trinity
err, neb

Written by Nebulae

September 4th, 2008 at 10:02 am

Posted in code

Tagged with , , ,