I am creating a web application that will be used by external users who will be able to save data onto crm database. The application is a timesheet where users register the amount of hours they have worked as well as dates, etc. A timesheet has 0-* TimesheetLine (information about hours worked and so on).
I'm using Early bounding to save data on DB, but I am receiving a NullReferenceExpection for some reason. At first I thought I wasn't able to save a new record due to missing of foreign key but even after passing such data the error keeps occurring. I tested saving a different record, to see whether crm service connection was working and I could record data without a problem. For instance, I am able to create a new record of timesheet (even without passing any data), but am not able to create a new record of timesheetline. I keep on receiving the NullReferenceException and do not know why such error is happening.
I have few questions regarding such error, possible solutions and also I would like to know whether I need to use multiple requests? So far, I have tried the following approaches:
- Retrieve timesheet to obtain its information and create a new timesheetLine passing the foreign key reference appropriately.
- Save a timesheetLine without any reference to timesheet
Below exception trace:
Microsoft.Xrm.Sdk.SaveChangesException was unhandled by user code HResult=-2146233088 Message=An error occured while processing this request. Source=Microsoft.Xrm.Sdk StackTrace: at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges() at TimesheetSample.Controllers.TimesheetController.SaveTimesheetLine(TimesheetViewModel timesheetLineVm) in c:\Users\Demerson.Herculano\Documents\AES Projects\TimesheetSample\TimesheetSample\Controllers\TimesheetController.cs:line 161 at TimesheetSample.Controllers.TimesheetController.New(TimesheetViewModel timesheetVm) in c:\Users\Demerson.Herculano\Documents\AES Projects\TimesheetSample\TimesheetSample\Controllers\TimesheetController.cs:line 110 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() InnerException: System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> HResult=-2146233087 Message=System.NullReferenceException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #FB5F14A6 Source=mscorlib Action=http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteOrganizationServiceFaultFault StackTrace: Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChange(OrganizationRequest request, IList`1 results) InnerException:
Thanks in advance,
Demerson