Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;无法加载文件或程序集';展示中心'&引用;azure函数使用Gembox.Document时出错_C#_.net_Azure_Pdf_Gembox Document - Fatal编程技术网

C# &引用;无法加载文件或程序集';展示中心'&引用;azure函数使用Gembox.Document时出错

C# &引用;无法加载文件或程序集';展示中心'&引用;azure函数使用Gembox.Document时出错,c#,.net,azure,pdf,gembox-document,C#,.net,Azure,Pdf,Gembox Document,我目前使用Gembox.Document从PDF文档中读取内容。我有一个包含所有内容的类库和一个引用它的自托管.NETCore3.1服务。我用PDF数据查询服务,它用内容进行响应。我现在想将此功能移到azure功能(v3),但遇到以下错误: 无法加载文件或程序集的PresentationCore,版本=4.0.0.0, 区域性=中性,PublicKeyToken=31bf3856ad364e35'。系统不能 查找指定的文件 为了简化它,我只将基本部分移动到azure函数中,您可以在下面看到: p

我目前使用Gembox.Document从PDF文档中读取内容。我有一个包含所有内容的类库和一个引用它的自托管.NETCore3.1服务。我用PDF数据查询服务,它用内容进行响应。我现在想将此功能移到azure功能(v3),但遇到以下错误:

无法加载文件或程序集的PresentationCore,版本=4.0.0.0, 区域性=中性,PublicKeyToken=31bf3856ad364e35'。系统不能 查找指定的文件

为了简化它,我只将基本部分移动到azure函数中,您可以在下面看到:

public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    ComponentInfo.SetLicense("FREE-LIMITED-KEY");
    ComponentInfo.FreeLimitReached += (sender, args) => args.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;

    try
    {
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        ParseRequest data = JsonConvert.DeserializeObject<ParseRequest>(requestBody);

        StringBuilder sb = new StringBuilder();

        using (var ms = new MemoryStream(data.Data))
        {
            // Load document from file's path.
            var document = DocumentModel.Load(ms, LoadOptions.PdfDefault);

            foreach (var childElement in document.GetChildElements(true, ElementType.Paragraph))
            {
                sb.AppendLine(childElement.Content.ToString());
            }
        }

        return new OkObjectResult(sb.ToString());
    }
    catch (Exception e)
    {
        return new OkObjectResult("Unable to read document");
    }
}
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
SetLicense(“自由限制密钥”);
ComponentInfo.FreeLimitReachedAction+=(发送方,args)=>args.FreeLimitReachedAction=FreeLimitReachedAction.ContinueAsTrial;
尝试
{
string requestBody=等待新的StreamReader(req.Body).ReadToEndAsync();
ParseRequest data=JsonConvert.DeserializeObject(requestBody);
StringBuilder sb=新的StringBuilder();
使用(var ms=newmemoryStream(data.data))
{
//从文件路径加载文档。
var document=DocumentModel.Load(ms,LoadOptions.PdfDefault);
foreach(document.GetChildElements中的var childElement(true,ElementType.段落))
{
sb.AppendLine(childElement.Content.ToString());
}
}
返回新的OkObjectResult(sb.ToString());
}
捕获(例外e)
{
返回新的OkObjectResult(“无法读取文档”);
}
}
这是azure功能的限制吗?我读过一些相互矛盾的东西,这些东西表明它可以也不能做,因为它使用的是WPF dll。作为记录,GemBox网站提供了一个在azure函数中创建PDF文档的示例:。所以我不明白为什么我也看不懂

谢谢

编辑1:

根据mu88的评论,我已将.csproj文件更改为以下文件,但没有任何帮助


GemBox.Document
存在此问题(它可能依赖于.net Framework组件),但
GemBox.Pdf
工作正常,如下所示

我使用
GemBox.Pdf
nuget和下面的函数对它进行了测试,它可以在部署的函数app中创建和加载Pdf

创建PDF:

[FunctionName(“Function1”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
SetLicense(“自由限制密钥”);
使用(var document=new PdfDocument())
{
//添加一个页面。
var page=document.Pages.Add();
//写一篇课文。
使用(var formattedText=new PdfFormattedText())
{
Append(“helloworld!”);
page.Content.DrawText(格式化文本,新的PdfPoint(100700));
}
var fileName=“Output.pdf”;
var options=SaveOptions.Pdf;
使用(var stream=new MemoryStream())
{
保存(流、选项);
返回新的FileContentResult(stream.ToArray(),“application/pdf”){FileDownloadName=fileName};
}
}
}

下载PDF:

[FunctionName(“Function3”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequest请求,
ILogger日志)
{
SetLicense(“自由限制密钥”);
尝试
{
StringBuilder sb=新的StringBuilder();
使用(var文档=PdfDocument.Load(请求正文))
{
foreach(document.Pages中的变量页)
{
sb.AppendLine(page.Content.ToString());
}
}
返回新的OkObjectResult(sb.ToString());
}
捕获(例外e)
{
返回新的异常结果(e,true);
}
}

我向GemBox支持部门求助,他们的回应是:

不幸的是,GemBox.Document使用WPF来读取PDF文件。所以 即使你可以在Azure函数上编写PDF文件,恐怕你 我看不懂

但是,我还应该指出,GemBox.Document中的PDF阅读器永远不会 离开测试阶段,它的使用受到限制。欲了解更多信息, 请检查这一部分

相反,我建议你试试GemBox.Pdf,看看它的 例子。使用GemBox.Pdf,您可以在Azure上读写Pdf文件 功能

最后,从长远来看,我们计划替换当前的(内部) PDF阅读器(BETA版)和PDF writer在中的实现 文档中包含了更新的实现 Pdf,而不更改GemBox.Document的公共API。但是 今年不会这样做,以后我也不能说 此时此刻


唉,使用GemBox.Document是不可能的。。但是。

只是为了确定:您是否正在使用
true
?@mu88请查看更新,我尝试了您的建议,但没有帮助。我对azure了解不多,但如果azure函数中默认不提供WPF dll,这是有意义的,因为它是服务器组件,WPF是UI框架。可能会将所有这些dll与主dll一起显式复制。感谢您的回复。恐怕我们没有GemBox.Pdf的许可证,只有GemBox.Doc的许可证