3

I'm trying to execute a query on a custom list. I'm receiving a generic error that isn't helping me track down the problem.

Error Message:

Exception from HRESULT: 0x80131904

Stacktrace:

   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()       

Relevant Code:

var timeHoursAgo = DateTime.Now.AddHours(ModifiedHours * -1);

string query = Camlex.Query().Where(
    x => (string)x["IsAccessGranted"] == "Yes" &&
    (DateTime)x["Modified"] >= timeHoursAgo)
    .ToString();

var caml = new CamlQuery();
caml.ViewXml = string.Format("<View>{0}</View>", query);

Which produces a caml query like the following:

<View><Query>
  <Where>
    <And>
      <Eq>
        <FieldRef Name="IsAccessGranted" />
        <Value Type="Text">Yes</Value>
      </Eq>
      <Geq>
        <FieldRef Name="Modified" />
        <Value Type="DateTime">2016-11-07T11:15:52Z</Value>
      </Geq>
    </And>
  </Where>
</Query></View>

What are some causes of this error I should look for?

1 Answer 1

4

I've found that multiple people have received the same error when using incorrect datatypes.

So, after verifying the data types of the fields being queried directly in the Caml query, I noticed IsAccessGranted is a Yes/No field which is more of a boolean type field than a string. After modifying the query as follows:

string query = Camlex.Query().Where(
                    x => (int)x["IsAccessGranted"] == 1 &&
                    (DateTime)x["Modified"] >= timeHoursAgo)
                    .ToString();

Which produced the following caml:

<View><Query>
  <Where>
    <And>
      <Eq>
        <FieldRef Name="IsAccessGranted" />
        <Value Type="Integer">1</Value>
      </Eq>
      <Geq>
        <FieldRef Name="Modified" />
        <Value Type="DateTime">2016-11-07T11:22:47Z</Value>
      </Geq>
    </And>
  </Where>
</Query></View>

The error no longer occurs as I'm treating the Yes/No field as boolean integer values. Bottom line, this error appears to occur often when data types are not handled correctly.

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.