I have a function that initializes a custom taxonomy control, as below (not in myControl.js)

function initMyControl() {
    if (something is true) {
        var context = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
        $(controlId).myControl({ arrayOfOptions }, context);

Inside myControl.js I save the context in a global variable when I extend jQuery

$.fn.myControl = function (options, ctx) {
    spContext = ctx;

I use spContext in several places in my javascript code, but when I come to an execution of where I want execute a query in relation to my control, I hit the Exception in the title.

this.NewTerm = parent.createTerm(label, myControl.LCID, id);
spContext.executeQueryAsync(Function.createDelegate(myControl, myControl.termAddSuccess),
    Function.createDelegate(myControl, myControl.termAddFailed));

When I try to run executeQueryAsync I get the exception Sys.InvalidOperationException: The object is used in the context different from the one associated with the object, even though the context is the same.

How come this is happening, and what is a possible workaround?

  • This is a late reply. Just want to know your findings on this. I too have come across this error with CSOM C#, whenever i try to use client object in different context than it's associated with. My understanding is any single client object(LisItem,User etc) is associated with only the clientcontext it's loaded from and it's not supposed to be used in different context(e.g Update a client object from different context). In your case, you said you are using only one context. That makes me suspicious and proves my understanding on this exception incorrect. Can you please confirm if you got the er Oct 29, 2015 at 2:52


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.