简体   繁体   中英

NHapi PipeParser throws exception in Azure Function

I have a .net core 3.1 Azure Function which is using the latest version of NHApi (3.0.4). The following lines of code throws an exception when running locally:

var pipeParser = new PipeParser();
var messageObject = pipeParser.Parse(messageString);

The exception is the following:

The type initializer for 'NHapi.Base.PackageManager' threw an exception. NHapi.Base: The type initializer for 'NHapi.Base.PackageManager' threw an exception. NHapi.Base: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Looking at my build folder in bin\Debug.netcoreapp3.1, i can see a System.Configuration.ConfigurationManager.dll. However i need to copy this file to bin\Debug.netcoreapp3.1\bin for the error to go away. It seems that this assembly doesn't get copied to the \bin subfolder (which contains all the other referenced assmblies) by default. Does someone know why this is the case? Short of adding some post build step to do this file copy, what's the solution?

It looks like you are missing the System.Configuration.ConfigurationManager reference, auburg provided a link to help you include it in your azure function.

How do you copy files into Azure Function bin folder?

Downloading NHapi you will get a set of assemblies to reference in you .Net solution. It contains the set of assemblies like ( NHapi.Base.dll , NHapi.Model.V21.dll & …)

The NHapi.Base assembly contains the tools and classes By using this we can parse and generate the HL7 messages . The base classes are used for the class structures in the implementation of the different HL7 versions. Tooling contains the parsers for piped and XML messages and the validators used with parsing. Those tools contains the exception definitions and logging tooling.

String msg = @"MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3|\n QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||";

// get a new instance of the pipeparser to parse the piped message
PipeParser parser = new PipeParser();
try
{
    //parse will return an abstract message
    IMessage mssg = parser.Parse(msg);
    
    // Cast the abstract message to the right type
    // Other examples will show how to determine the type
    // of message if this is unknown
    
    QRY_R02 qryR02 = m as QRY_R02;
    Console.WriteLine(qryR02.QRD.GetWhoSubjectFilter(0).IDNumber.Value); 
}
catch (exception ex)
{
    // handle the exception here
}

After receiving the message pipeparser parse the message. Use the exception handling to catch any HL7 Exception if anything went wrong while parsing the message. check documentation here

Refer here for moving your files and assemblies in to function bin folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM