【问题标题】:NHapi PipeParser throws exception in Azure FunctionNHapi PipeParser 在 Azure 函数中引发异常
【发布时间】:2022-01-02 00:10:10
【问题描述】:

我有一个使用最新版本 NHApi (3.0.4) 的 .net core 3.1 Azure Function。以下代码行在本地运行时会抛出异常:

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

例外情况如下:

“NHapi.Base.PackageManager”的类型初始化程序引发了异常。 NHapi.Base:“NHapi.Base.PackageManager”的类型初始化程序引发了异常。 NHapi.Base:无法加载文件或程序集“System.Configuration.ConfigurationManager,版本=5.0.0.0,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51”。系统找不到指定的文件。

查看 bin\Debug\netcoreapp3.1 中的构建文件夹,我可以看到 System.Configuration.ConfigurationManager.dll。 但是我需要将此文件复制到 bin\Debug\netcoreapp3.1\bin 以使错误消失。默认情况下,该程序集似乎不会被复制到 \bin 子文件夹(其中包含所有其他引用的程序集)。有人知道为什么会这样吗?没有添加一些后期构建步骤来执行此文件复制,解决方案是什么?

【问题讨论】:

标签: .net-core azure-functions nhapi


【解决方案1】:

下载NHapi,您将获得一组程序集供您在.Net 解决方案中引用。它包含一组程序集,例如 (NHapi.Base.dll, NHapi.Model.V21.dll & ...)

NHapi.Base 程序集包含 工具 通过使用它,我们可以解析生成 HL7 消息强>。 基类用于实现不同 HL7 版本的类结构。 工具 包含管道和 XML 消息的解析器以及用于解析的验证器。这些工具包含异常定义和日志记录工具。

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
}

pipeparser 收到消息后解析消息。如果在解析消息时出现任何问题,请使用异常处理来捕获任何 HL7 异常。检查文档here

请参阅 here 将您的文件和程序集移入函数 bin 文件夹

【讨论】:

  • 抱歉,这并不能回答我关于依赖程序集位置的问题
【解决方案2】:

您似乎缺少 System.Configuration.ConfigurationManager 参考,auburg 提供了一个链接来帮助您将其包含在您的 azure 函数中。

How do you copy files into Azure Function bin folder?

【讨论】:

    猜你喜欢
    • 2019-07-17
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    相关资源
    最近更新 更多