I have a list with records uniquely identified by project numbers. This is column 5 - Col05 in my list. It works fine when I run the code, and I am getting the expected record. I can also read the values I need.

But this doesn't work on anybody else's computer. Error received is:

System.NullReferenceException: Object reference not set to an instance of an object.

I'm working with C# (.net) and Sharepoint Client COM, and using VS 2010. The above error had come earlier once, when trying to convert a SP List Item which is null to string, but there are no such columns for that record - I've checked and every column has some value.

The code I have used for this is below:

SP.ClientContext _clientcontext = new SP.ClientContext("https://mysite/");
NetworkCredential myCred = new NetworkCredential();
CredentialCache myCache = new CredentialCache();

            SP.Web _site = _clientcontext.Web;
            SP.List _list = _site.Lists.GetByTitle("myList");

            string id = "9999";

            string _viewXML = "" +
                        "<View>" +
                            "<Query>" +
                                "<Where>" +
                                    "<Eq>" +
                                        "<FieldRef Name = '_x0043_ol05'/>" +
                                            "<Value Type = 'Text'>" + id + "</Value>" +
                                        "</FieldRef>" +
                                    "</Eq>" +
                                "</Where>" +
                             "</Query>" +

            SP.CamlQuery _query = new SP.CamlQuery { ViewXml = _viewXML };

            SP.ListItemCollection _listitems = _list.GetItems(_query);


I can't figure out how it is working fine when I run it in debug mode/run with debug, but not on anybody elses. Remaining code runs fine, so its not an issue about nothing working at all, but its only this bit that is stuck

Would appreciate any help on this. Thanks in advance!

2 Answers 2


After much debugging, found that I had assigned credentials outside this code block. For some reason, it did not throw an error for invalid credentials, even though it was trying to execute a query without the valid username and password.

Throwing a null reference exception threw me off. Here's the code if it helps anybody:

            myCred.UserName = mainForm.form1Username;
            myCred.Password = mainForm.form1Password;
            myCred.Domain = "Domain";
            myCache.Add(new Uri("https://myURL/"), "NTLM", myCred);
            _clientcontext.Credentials = myCache;


Thanks a lot to @David Lozzi for your help! :)


I would bet the null reference is because the column name doesn't exist? Are you deploying the column with the same codeset, or is it manually created with the list? Grab SharePoint Manager, https://spm.codeplex.com/, or use PowerShell, and check out the internal name of the field in each of your environments.


  • Thanks for your answer, David. But I've checked the column names, and this is working code. Like I mentioned, this is working fine on my comp. But doesn't seem to work anywhere else.
    – xcentaur
    Apr 24, 2013 at 13:25
  • what do you mean when you say deploying the column with the same codeset, or manually created with list? Sorry, I am new to both C# and SP. The list already exists, and I have checked the column name/s. Also, none of the columns are null, all have some value.
    – xcentaur
    Apr 24, 2013 at 13:27
  • ok, so the lists are already made, good. How are you checking the column names? Are you checking their internal names or their external? What I'm concerned about is that your CAML field name is _x0043_ol05, while you stated it's Col05. _x0043_ is unicode for C, which might not be the same in each environment. If the field was made via SP list settings, the internal name should be Col05. I don't know why you're seeing this special character. Apr 24, 2013 at 13:37
  • yes, i've checked. it isn't working with column UI name. but its working fine with internal name. i just cross-checked the results too. its returning the record which I wanted. so this code is working, well, at least on mine. just as an aside, i created this list manually. went to sharepoint URL> created new list > manually configured the columns by clicking add column. Adding columns programmatically did not work well for me. Worked fine sometimes, didn;t work at others.
    – xcentaur
    Apr 24, 2013 at 13:44
  • If the columns are accurate, then something else is acting up. Can you debug it on the other environments? Have you confirmed that the list name is exactly the same as well? Otherwise, I'm not sure what else to look at. Apr 24, 2013 at 13:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.