locked
NullReference and Entity Relationship [FIXED] RRS feed

  • Question

  • Hi everyone,

    I have recently inherit a 2011 CRM project and so am still learning basic stuff with CRM and its services. 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 for any helpful comment.


     
    • Edited by Demerson H Monday, December 22, 2014 3:18 AM
    Monday, December 15, 2014 1:26 AM

Answers

  • Hi Everyone,

    Just letting you all know that I have fixed the problem. For some reason the dev server was corrupted somewhere. Only one entity had problem to save new records, so I ended up creating a backup from the production server and just updating the database from the dev server. I believe that also brought configs that fixed the error. I am now able to save new records anywhere.

    Thanks for all answers and if anyone experiences the same problem I will be happy to help.

    Regards,
    Demerson
    Monday, December 22, 2014 3:20 AM

All replies

  • Can you share code snippet around how are you creating TimeSheetLine records?
    Not sure how about your current approach. but I believe following should work:

    1. Create a TimeSheet record first. It should return a Guid i.e. RecordID

    2. Than using that you should be able to set entityreference for TimeSheetLine and create its record appropriately.

    Tuesday, December 16, 2014 12:27 PM
  • Hi Niraj,

    I believe my approach shouldn't be a problem as I am able to create records for other entities. I actually have just tried creating a record using the WEBAPP and strangely it is not working. At first I thought it was something to do with javascript but even after checking that, I am still receiving the same error.

    What is even more strange is that I am able to save a record while I am on the production server but whenever I am on the dev/test server it doesn't work. I think its strange since the production server is a mirror from the other ones. What do you think could be happening?

    Thanks.
    Wednesday, December 17, 2014 1:40 AM
  • Hi Demerson,

    >>What is even more strange is that I am able to save a record while I am on the production server but whenever I am on the dev/test server it doesn't work.<<

    I believe the code is correct.

    Have you checked that all fields of the entity and field type are the same as on the production server?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by George Hua Thursday, December 18, 2014 1:47 AM
    Wednesday, December 17, 2014 4:28 AM
  • Hi George,

    Yes, They are all the same including database.

    I am thinking of possible solutions. I have read that it's possible to export a managed solution as unmanaged so I am thinking of doing that and change the current solution on dev server to the same as production server to see whether the "save" will work.

    What do you think? Is this feasible? Is there another possible way out of this? 

    Thanks
    Thursday, December 18, 2014 1:58 AM
  • Hi Everyone,

    Just letting you all know that I have fixed the problem. For some reason the dev server was corrupted somewhere. Only one entity had problem to save new records, so I ended up creating a backup from the production server and just updating the database from the dev server. I believe that also brought configs that fixed the error. I am now able to save new records anywhere.

    Thanks for all answers and if anyone experiences the same problem I will be happy to help.

    Regards,
    Demerson
    Monday, December 22, 2014 3:20 AM