Object reference error when publishing multiple objects
I created a custom module called Trainers, and I created a public wcf service that allows them to be queried. I then built one trainer by hand, and it was successfully output by the wcf service when I accessed it.
I then uploaded the 396 records we currently have directly into the backend. They did not automatically publish, and so when I accessed the wcf service, I again saw JSON for the single trainer I had created by hand earlier.
Then, I selected all of the new trainer records and used the "More actions" > "Publish" option to publish them simultaneously. Upon accessing the wcf service, I received an "Object reference not set to an instance of an object" error in JSON, and no objects at all.
I then UN-published all of the records except the initial, working record. Accessing the wcf service again gave me an object reference error.
I then deleted ALL of the records EXCEPT the initial, working, record and queried the service. I saw JSON for that object.
So then I uploaded all 396 records again and this time published only one of them by clicking on the record, going into its edit page, and clicking publish. Accessing the wcf service gave me JSON for the (now two) published objects.
I randomly selected another 3 or 4 records and published them in the same manner - went into each individual record and hit publish - and was able to see JSON for all of them.
Then, I selected two records simultaneously and chose "More Options" > "Publish". The wcf service gave me an object reference error and no JSON. Unpublishing these two records individually (clicking into the record, clicking "unpublish") left me with the error. I then deleted the two records I'd published simultaneously and the wcf service again gave me JSON for all of the individually published records.
Here is the object reference error recorded in the logs.
Timestamp: 3/27/2013 8:00:05 PM
Message: HandlingInstanceID: cd9b9ac0-3b57-4745-ba3c-044b195cc6b4
An exception of type 'System.NullReferenceException' occurred and was caught.
Type : System.NullReferenceException, mscorlib, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : SitefinityWebApp
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : System.String Mantra(Telerik.Sitefinity.Model.IDynamicFieldsContainer)
HResult : -2147467261
Stack Trace : at SitefinityWebApp.Mvc.Models.TrainerAccess.Mantra(IDynamicFieldsContainer trainer) in c:\inetpub\wwwroot\corp\Mvc\Models\TrainerAccess.cs:line 48
at SitefinityWebApp.Mvc.Models.TrainerModel..ctor(IDynamicFieldsContainer trainer) in c:\inetpub\wwwroot\corp\Mvc\Models\TrainerModel.cs:line 160
at SitefinityWebApp.Mvc.Models.TrainerAccess.GetTrainersFromModule() in c:\inetpub\wwwroot\corp\Mvc\Models\TrainerAccess.cs:line 24
at SitefinityWebApp.Services.TrainerService.TrainerIndex() in c:\inetpub\wwwroot\corp\Services\TrainerService.cs:line 32
at SyncInvokeTrainerIndex(Object , Object , Object )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object inputs, Object& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
MachineName : HQ-V-STUART
TimeStamp : 3/27/2013 8:00:05 PM
FullName : Telerik.Sitefinity.Utilities, Version=5.1.3450.0, Culture=neutral, PublicKeyToken=b28c218413bdf563
AppDomainName : /LM/W3SVC/6/ROOT-1-130088878598857997
WindowsIdentity : IIS APPPOOL\new_corp
Requested URL : 172.16.50.115:8083/.../trainers
Title:Enterprise Library Exception Handling
App Domain: /LM/W3SVC/6/ROOT-1-130088878598857997
Process Name: c:\windows\system32\inetsrv\w3wp.exe
Please help me not have to manually publish 396 records.
What you describe seems to be related to a problem with the service, not the items (if you're publishing them through the UI). You can check in the database if there is anythign specific about the problematic items. They should have a live (status 2) and a master (status 0) record. You can also check the following articles about RESTful services and Sitefinity:
Another thing you may want to try is publish all items with the API and see if you're able to access them with your service afterwards.
I went digging around in the database as you suggested and noticed that before a record was published, it had a few fields that were null, that were NOT null (even though they were empty) in a record that had been individually published. Upon publishing individually (clicking into the record and clicking the publish button), these fields were all changed from null to empty, and the service populated successfully. If the record was published by clicking the checkbox and choosing "more actions > publish", then the fields remained null and the service threw the object reference error.
Note that the empty/null fields are NOT marked as required in the custom module.
So the difference is that when Sitefinity publishes records en masse, it does not convert empty fields from null to empty ("" for a string); however, when a record is 'edited', even if none of the fields are changed, and then published, all empty fields are converted from null to empty automatically.
I changed the upload script to populate each of the offending fields with an empty string rather than simply not set them. This allowed me to publish a 2 records simultaneously; however when I attempt to publish 3 or more, I receive "Detail":"Input string was not in a correct format." as an error. Do you have any idea to what this error may be referring? I've tried multiple times and it seems to be an issue with the number of simultaneous records that I've tried to publish, and not the individual records themselves.
I found the Input String error - fields that were set to be numbers that were empty were failing to be parsed properly. I added try/catch to my Access class to return 0 if the parse fails.
What you're experiencing is quite unusual and specific, because it's related to a custom service. Did you fix the behavior with your last modifications?Greetings,
The last modification did fix the second error, so everything is working now.