Unable to resolve reference to profile

552 views
Skip to first unread message

Giorgi Chubinidze

unread,
Jun 29, 2021, 5:02:06 PM6/29/21
to FHIR DOTNET
Hi everyone.
I am trying to follow Let's Build .Net June 2021 session 2 exercise for building a simple validator tool. I installed all the necessary packages however, I am still getting the following error:
 "Unable to resolve reference to profile 'http://hl7.org/fhir/StructureDefinition/Patient'"
Any help would be appreciated. 
Code:
var jsonSerializationSettings = new FhirJsonSerializationSettings { Pretty = true };
patient.ToJson(jsonSerializationSettings);
var resolver = ZipSource.CreateValidationSource();
var settings = ValidationSettings.CreateDefault();
settings.ResourceResolver = new CachedResolver(resolver);
var validator = new Validator(settings);
var outcome = validator.Validate(patient);
Console.WriteLine($"Success: {outcome.Success} \n{outcome.ToJson(jsonSerializationSettings)}");



Ewout Kramer

unread,
Jun 30, 2021, 3:42:33 AM6/30/21
to FHIR DOTNET
Your code looks OK.  Maybe something went wrong unpacking the specification.zip file, which contains those profiles (and which are installed the first time you call the validator on the ZipSource.CreateValidationSource).

To check, can you go to you `%TEMP%` folder (if you're on window, sorry I don't know where the temp dirs are on other systems), and remove everything that starts with 'FhirArtifactCache' ?

If that does not remedy your problem, can you take a look at your temp file again, and inside the new newly created `FhirArtifactCache....` directory to see if has any content at all?

Can you check a zip file called `specification.zip` is present in the directory from which you run your app/unit-test etc?

Op dinsdag 29 juni 2021 om 23:02:06 UTC+2 schreef Giorgi Chubinidze:

Giorgi Chubinidze

unread,
Aug 17, 2021, 1:51:42 AM8/17/21
to FHIR DOTNET
Hello again, 
I am getting back to this issue several months later because it took me several days of debugging to solve the above-mentioned issue. I believe a lot of people who might share the similar issue can benefit from reading this. 
I am working on MacOS and therefore, the suggested fix did not really help me so I came up with my own fix.
The problem was the following: Even despite following the instructions carefully, my validator did not really "see"/recognize a specification folder and it was giving me this error: "Unable to resolve reference to profile 'http://hl7.org/fhir/StructureDefinition/Patient'"
The situation became even more confusing when I shared the code with my teammates and the same code was working (successfully validating the resource) on their machines (also Macs) while I was still getting the same error. I am still not 100% sure what was happening but I believe this issue was because the cache was getting corrupted after several validation requests. 
Here is the fix that I found: 

Instead of using ZipSource.CreateValidationSource(), manually extract specification folder from specification.zip and put it in the project folder. Then, set directory resolver for this specification instead of zipsource:
var resolver = new DirectorySource(specificationPath, true);
Finally, use this resolver in the CachedResolver like this: settings.ResourceResolver = new CachedResolver(resolver);

Full code: 
var jsonSerializationSettings = new FhirJsonSerializationSettings { Pretty = true };
patient.ToJson(jsonSerializationSettings);
var resolver = new DirectorySource(specificationPath, true);
var settings = ValidationSettings.CreateDefault();
settings.ResourceResolver = new CachedResolver(resolver);
var validator = new Validator(settings);
var outcome = validator.Validate(patient);
Console.WriteLine($"Success: {outcome.Success} \n{outcome.ToJson(jsonSerializationSettings)}");


In case you are interested in importing us core profiles and/or other profiles, manually download them in the project and wrap them in the MultiResolver similar this: 

var resolver = new DirectorySource(specificationPath, true);
var usCoreResolver = new DirectorySource(usCorePath, true);
var settings = ValidationSettings.CreateDefault();
settings.ResourceResolver = new CachedResolver(new MultiResolver(resolver, usCoreResolver));

var validator = new Validator(settings);


Thank you and hope this helps!
Reply all
Reply to author
Forward
0 new messages