value cannot be null

326 views
Skip to first unread message

Sarnam

unread,
Apr 26, 2012, 6:22:51 AM4/26/12
to mongod...@googlegroups.com
Hi,
   I am fetching data from mongodb using mongo C# driver based on some condition. but application behaving randomly. sometimes it give result or sometimes it throw an error like "Value can not be null". So can any one help me to fix this problem.

Thanks
Sarnam Singh

Robert Stam

unread,
Apr 26, 2012, 9:19:59 AM4/26/12
to mongod...@googlegroups.com
You didn't give much information, but I'm guessing that you called a method in the C# driver with a null argument when a null argument is not valid (hence the error message).

For example, the following will give the same error message you are seeing:

    Query.EQ("x", null);

The correct way to write that is:

    Query.EQ("x", BsonNull.Value);

If you look at the stack trace the top few entries should be methods in the C# driver but the first method you find that is in your code is where the error is coming from. If the stack trace has line numbers you'll know exactly what line number the error is on.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Sarnam

unread,
Apr 26, 2012, 10:44:10 AM4/26/12
to mongod...@googlegroups.com
thanks for reply. but as per my observation the problem is coming due to load, because i was doing load testing with 20-30 users hitting search query at the same time then i was running fine but when users more than 30 hitting at same time then this problem is coming and  i am pretty sure about not passing any null value because i have put if condition like :
 IMongoQuery qry = null;
            
            if (searchingName.ToLower().Trim() == "id")
                searchingName = "_id";
            int x;
            if (!string.IsNullOrEmpty(searchingValue))
            {
                if (Int32.TryParse(searchingValue, out x) == false || searchingName.ToLower().Trim() == "ipaddress")
                {


                    switch (searchingOperator)
                    {

                        case JqGridSearchOperators.Eq:
                            if (!xMLElement.Item1)
                                qry = Query.EQ(searchingName, new BsonRegularExpression("/^" + searchingValue + "$/i"));
                            else
                                qry = Query.ElemMatch("FieldList", Query.And( Query.EQ("FieldName", subFieldName), Query.EQ("FieldValue", new BsonRegularExpression("/^" + searchingValue + "$/i"))));
                            break;
                        case JqGridSearchOperators.Ne:
                            if (!xMLElement.Item1)
                                qry = Query.EQ(searchingName, new BsonDocument("$not", new BsonRegularExpression("/^" + searchingValue + "$/i")));
                            else
                                qry = Query.ElemMatch("FieldList", Query.And(Query.EQ("FieldName", subFieldName), Query.EQ("FieldValue", new BsonDocument("$not", new BsonRegularExpression("/^" + searchingValue + "$/i")))));
                            break;
                        case JqGridSearchOperators.Cn:
                            if (!xMLElement.Item1)
                                qry = Query.Matches(searchingName, new BsonRegularExpression(searchingValue, "i"));
                            else
                                qry = Query.ElemMatch("FieldList", Query.And(Query.EQ("FieldName", subFieldName), Query.EQ("FieldValue", new BsonRegularExpression(searchingValue, "i"))));
                            break;
                    }

                }
                else
                {
                    switch (searchingOperator)
                    {
                        case JqGridSearchOperators.Eq:
                            qry = Query.EQ(searchingName,x);
                            break;
                        case JqGridSearchOperators.Ne:
                            qry = Query.NE(searchingName,x);
                            break;
                        case JqGridSearchOperators.Lt:
                            qry = Query.LT(searchingName,x );
                            break;
                        case JqGridSearchOperators.Le:
                            qry = Query.LTE(searchingName,x);
                            break;
                        case JqGridSearchOperators.Gt:
                            qry = Query.GT(searchingName,x);
                            break;
                        case JqGridSearchOperators.Ge:
                            qry = Query.GTE(searchingName,x );
                            break;

                    }
                }
            }

so it would be great help if you can guide me over this issue.

Thanks
Sarnam Singh

Robert Stam

unread,
Apr 26, 2012, 10:51:46 AM4/26/12
to mongod...@googlegroups.com
Can you provide the stack trace when you are getting an ArgumentNullException?

That would help diagnose the issue.
Reply all
Reply to author
Forward
0 new messages