Sharepoint Content Deployment results in "Value cannot be null"
We were working on a publishing site and had couple of custom field types and controls also as part of our custom development. We were doing Content Deployment to publish our Sharepoint 2007 (MOSS) authoring site to the Publishing site. While doing so typically we were getting following errors:
1. VALUE CANNOT BE NULL
OR
2. Object reference not set to an instance of an object
After carefully looking at the custom developed features we found that some of the custom code was using SPCONTEXT and that code was getting executed during Content Deployment (How did we find this: We attached the owstimer.exe service on the server and ran our custom code in the debug mode).
The problem was with the code of the custom field type was relying on the usage of SPContext object and this object can only be used inside a http request to a sharepoint site. Hence it will always fail during the content deployment (as OWSTIMER.EXE will always have SPContext null) and where no SPContext object exists. We resolved this issue by checking for value of SPContext i.e. we introduced SPContext != null before executing the code and we got over that issue.
Make sure to restart the OWSTIMER service after you re-deploy the changed code. Always remember that HTTPContext will not exists while doing the Content deployment and if you have any custom code that directly relies on SPContext will tend to fail and hence the content deployment also.
Hope this helps someone.