This project is read-only.

Null Ref Exception on JsonValueSample

Topics: Web Api
Nov 12, 2010 at 9:36 PM

I downloaded the Preview 1 code and fired up VS2010, built it and ran it. I'm especially interested in the JSON capabilities as I do a ton of mobile work and working with JSON is my main transport mechanism for data from server to device (WP7, Android, iPhone, etc).

However, when I started the JsonValueSample, the default page showed up and it has a form with a input for a name. I plugged in "John Doe" and then clicked add.

jQuery serialiazes the values as: "Name=John+Doe", which looks correct. On the server, the ContactsResource accepts the POST request, but the problem is that the parameter (JsonValue contact) is now null. Therefore, a null ref exception happens a few lines down. Therefore the result never returns, nor do I get to see how it works/etc. 

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public JsonValue Post(JsonValue contact)
            var postedContact = (dynamic)contact;
            var contactResponse = (dynamic)new JsonObject();
            contactResponse.Name = postedContact.Name;
            contactResponse.ContactId = nextId++;
            return contactResponse;

Am I doing something wrong or missing something?



Nov 12, 2010 at 9:38 PM

Glenn wanted the stack trace - 

Message: Cannot perform runtime binding on a null reference

Stack Trace:  

at CallSite.Target(Closure , CallSite , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at CallSite.Target(Closure , CallSite , Object )
   at JsonValueSample.ContactsResource.Post(JsonValue contact) in C:\Documents and Settings\dfelker\My Documents\Downloads\WCF HTTP Preview 1\Http\samples\JsonValueSample\ContactsResource.cs:line 21
   at SyncInvokePost(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

Nov 13, 2010 at 2:57 AM

Don, what browser are you using?

Nov 15, 2010 at 2:37 PM

Firefox 3.

Specs: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20101026 Firefox/3.6.12