DataAnnotation.ValidationContext failure

563 views
Skip to first unread message

David Downey

unread,
Mar 30, 2016, 4:58:26 PM3/30/16
to FHIR DOTNET
We are using the Spark core libraries with a Couchbase back-end and I've run into a snag upgrading spark.  I recently upgraded from a non Unity version of spark to the latest:  0.90.5-beta2.  I have everything set up such that GETs work just fine, but any PUT fails with the built in System.ComponentModel.DataAnnotations...  For some reason the "object instance" being sent to the ValidationContext constructor is null.  I must not have something set up correctly.  Has anyone else run into this unlikely cornercase?  Are there any obvious gotchas that I am missing?  I realize I am not giving you a ton of information.  I was just trying this question first to see if anything constructive comes out of it.

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "Value cannot be null.\r\nParameter name: instance",
  "ExceptionType": "System.ArgumentNullException",
  "StackTrace": "   at System.ComponentModel.DataAnnotations.ValidationContext..ctor(Object instance, IServiceProvider serviceProvider, IDictionary`2 items)\r\n   at System.ComponentModel.DataAnnotations.ValidationContext..ctor(Object instance)\r\n   at System.Web.Http.Validation.Validators.DataAnnotationsModelValidator.Validate(ModelMetadata metadata, Object container)\r\n   at System.Web.Http.Validation.DefaultBodyModelValidator.ShallowValidate(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable`1 validators)\r\n   at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable`1 validators)\r\n   at System.Web.Http.Validation.DefaultBodyModelValidator.Validate(Object model, Type type, ModelMetadataProvider metadataProvider, HttpActionContext actionContext, String keyPrefix)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}


David Downey

unread,
Mar 31, 2016, 2:40:09 PM3/31/16
to FHIR DOTNET
Is anyone working on Spark using the .NET DataAnnoation validation?  I didn't intentionally turn this on.  Perhaps it is on by default.  Any clues/ideas/help would be appreciated.  

martijn....@gmail.com

unread,
Apr 4, 2016, 7:06:39 AM4/4/16
to FHIR DOTNET
My first impression is that this has to do with invalid content. The error is in the fhir API. https://www.nuget.org/packages/Hl7.Fhir.DSTU2/
If you post the resource content here, that you're trying to PUT, or give us some other reproducable steps, we can investigate it.

Martijn
Spark Lead Developer.

David Downey

unread,
Apr 4, 2016, 9:11:41 AM4/4/16
to FHIR DOTNET
Here is the resource content:

{
  "id": "postmanDavid1",
  "resourceType": "Patient",
  "language": "eng-US",
  "meta": {
    "versionId": "sparkPostmanManualTest123456789",
    "lastUpdated": "2015-08-19T19:53:17.982+00:00"
  },
  "name": [
    {
      "use": "official",
      "text": "David",
      "family": [
        "Actual"
      ],
      "given": [
        "David A"
      ],
      "prefix": [
        "Mr."
      ],
      "suffix": [
        "Bacon........."
      ]
    }
  ],
  "telecom": [
    {
      "system": "phone",
      "value": "+19196735158",
      "use": "mobile"
    },
    {
      "system": "phone",
      "value": "+31201234567",
      "use": "home"
    },
    {
      "system": "email",
      "value": "bac0...@mm.st",
      "use": "home"
    }
  ],
  "gender": "male",
  "birthDate": "1978-02-06",
  "deceasedBoolean": false,
  "address": [
    {
      "use": "home",
      "line": [
        "Roundhouse Lane"
      ],
      "city": "Morrisville",
      "postalCode": "27560",
      "country": "USA"
    }
  ],
  "maritalStatus": {
    "coding": [
      {
        "system": "http://hl7.org/fhir/v3/MaritalStatus",
        "code": "M",
        "display": "Married"
      }
    ]
  },
  "multipleBirthBoolean": false,
  "active": true,
  "extension": [
    {
      "valueString": "{\"ticks\": 635936000000000000,\"offsetTicks\": -1200000000}"
    },
    {
      "valueInteger": "1"
    }
  ]
}

I paused working on my 0.90.5-beta2 branch and rolled back to a master with 0.90.2-beta2.  I accidentally left the ValidationContext breakpoints active and saw that in earlier versions ValidationContext is indeed being hit and the object instance is not null.  Even when I purposefully PUT invalid fhir objects using 0.90.2-beta2, it doesn't run into this null object instance in ValidationContext issue.  

David Downey

unread,
Apr 5, 2016, 8:34:22 AM4/5/16
to FHIR DOTNET
I used this link to enable .NET debugging:


Then I copied and pasted every error encountered from startup to PUT.  I attached the file to this entry.  



NetErrors.txt

David Downey

unread,
Apr 6, 2016, 4:31:02 PM4/6/16
to FHIR DOTNET
We found the error.  Somewhere along the way a call in Global.asax was removed 

config.AddFhir();

With all the code changes needed to bring 0.90.2-betax up to 0.90.5-beta2 it somehow slipped through the cracks.  I now have a better idea how important this call is.  
Reply all
Reply to author
Forward
0 new messages