-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ModelBinding fails with Error ... Patient is abstract .... could not be instantiated and populated #2583
Comments
The text "The collection type" is suspicous. It's not a collection.,,,,,wait a second.... Yes, every resource is an I guess this means that in the list of converters installed in the service, there's a (default) converter installed that serializes collections BEFORE our own special FHIR serializer is called. Which is entirely possible. That's probably it. Not yet a solution, but we could start to experiment by wiping the |
I do regret letting Base (and subclasses) implement IReadOnlyDictionary<> directly. We've seen a few frameworks thrown off by this, much like the serializer here. Also, for example, the Visual Studio debugger shows resources as key value pairs in its enumerable viewer. Could we explore the idea of having an indirect implementation, i.e. having an |
@ewoutkramer I tried the following. (see below) This should put your converter first. I put a breakpoint to see the number of savedConverters. It is 0. Hence this did not change anything.
|
Ok, so that would have been too easy ;-) Still, it's clear to me that our converter, which should handle all resources, is not called, but some more generic converter now handles it, and throws this error. |
I found it. This is what our code in /// <summary>
/// Initialize the options to serialize using the JsonFhirConverterFactory, producing compact output without whitespace.
/// </summary>
public static JsonSerializerOptions ForFhir(this JsonSerializerOptions options, FhirJsonConverterFactory converter)
{
var result = new JsonSerializerOptions(options)
{
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};
result.Converters.Add(converter);
return result;
} In other words, we don't modify the original |
If I am correct, then a workaround could be to capture the results of
|
This workaround is working:
Will there be a fix in the SDK ? |
Yes, for sure. With this confirmed, we can fix it. I have given this issue the bug label now. |
I believe it should be something like this, we should create new converter, otherwise it is throwing error original Collection was modified error.
|
project-file
<PackageReference Include="Hl7.Fhir.R5" Version="5.3.0" />
startup.cs
controller-action
Error :
System.NotSupportedException: The collection type 'Hl7.Fhir.Model.Patient' is abstract, an interface, or is read only, and could not be instantiated and populated. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
Any suggestions ?
The text was updated successfully, but these errors were encountered: