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# GetFontData在ASP.NET应用程序中返回-1(GDI_错误),但在控制台应用程序中不返回。这是什么原因造成的?_C#_Asp.net_Pinvoke_32bit 64bit_Pdfsharp - Fatal编程技术网

C# GetFontData在ASP.NET应用程序中返回-1(GDI_错误),但在控制台应用程序中不返回。这是什么原因造成的?

C# GetFontData在ASP.NET应用程序中返回-1(GDI_错误),但在控制台应用程序中不返回。这是什么原因造成的?,c#,asp.net,pinvoke,32bit-64bit,pdfsharp,C#,Asp.net,Pinvoke,32bit 64bit,Pdfsharp,我们在一个web应用程序中使用PDFSharp(GDI+构建)。在一个PDF导出器中,我们使用的是非系统truetype字体,它在我们的开发环境中工作得很好,但在生产环境中运行时会崩溃 我们的开发和生产之间的关键区别(我认为)是,我们的生产服务器运行在WindowsServer200824bit上,而我们的开发运行在200822bit上。我写了一个小测试程序来调试 try { new XFont("ocrb10", 10, XFontStyle.Regular, new XPdfFont

我们在一个web应用程序中使用PDFSharp(GDI+构建)。在一个PDF导出器中,我们使用的是非系统truetype字体,它在我们的开发环境中工作得很好,但在生产环境中运行时会崩溃

我们的开发和生产之间的关键区别(我认为)是,我们的生产服务器运行在WindowsServer200824bit上,而我们的开发运行在200822bit上。我写了一个小测试程序来调试

try
{
    new XFont("ocrb10", 10, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always));
}
catch (Exception exc) { Console.WriteLine(exc.StackTrace); }
错误消息为InvalidOperationException:内部错误。无法检索字体数据

at PdfSharp.Fonts.OpenType.FontData.CreateGdiFontImage(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.FontData..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font)
at PdfSharp.Fonts.FontDescriptorStock.CreateDescriptor(XFont font)
at PdfSharp.Drawing.XFont.get_Metrics()
at PdfSharp.Drawing.XFont.Initialize()
at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyle style, XPdfFontOptions pdfOptions)
我从源代码构建了PDFSharp,并添加了一些调试代码,以了解发生了什么。问题是对的pinvoke调用返回-1(GDI_错误)。PdfSharp的作者在错误发生的地方(搜索GDI_错误)添加了关于这一点的评论,但他也没有找到正确的解决方法

// Line 138 in FontData.cs, this GetFontData returns -1 here when 
// running as a web application on a 64bit windows host (regardles of WOW64
// being enabled or not)
int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
现在,我的问题是,当我作为控制台应用程序运行代码时,我无法在任何环境中重现此错误。我已尝试为应用程序池打开和关闭WOW64,并尝试使用自己的凭据运行应用程序池,以防出现任何与权限相关的问题,但没有效果

PDFSharp的WPF构建非常好,顺便说一句,如果我们找不到任何解决方案,我们很可能会切换到那个版本,但我真的很好奇是什么原因导致了这一点


有人能帮我做进一步的调试吗?在IIS/ASP.NET中运行的环境与在PInvokes中运行的控制台应用程序在哪些方面有所不同?

开发人员通常依赖GDI+来检索字体度量,但是:

GDI+函数和类不是 支持在Windows环境中使用 服务试图使用这些 Windows中的函数和类 服务可能会产生意外的结果 问题,如服务减少 性能和运行时异常或 错误

在FontData.cs中,我发现了以下内容:

#if GDI
100    /// <summary>
101    /// Create the font image using GDI+ functionality.
102    /// </summary>
103    void CreateGdiFontImage(XFont font, XPdfFontOptions options/*, XPrivateFontCollection privateFontCollection*/)
104    {
105      System.Drawing.Font gdiFont = font.RealizeGdiFont();
106      NativeMethods.LOGFONT logFont;
...
#如果GDI
100    /// 
101///使用GDI+功能创建字体图像。
102    /// 
103 void CreateGdiFontImage(XFont字体,XPdfFontOptions选项/*,XPrivateFontCollection privateFontCollection*/)
104    {
105 System.Drawing.Font gdiFont=Font.RealizeGdiFont();
106 NativeMethods.LOGFONT LOGFONT;
...

这就是为什么PDFSharp的GDI+版本不能在服务中工作,而WPF版本确实可以像您在问题中所说的那样工作。

PDFSharp可以使用GDI+或WPF。问题中已经说过WPF版本工作得很好:“PDFSharp的WPF版本工作得很好。”。感谢您提供的信息,我不知道服务中不支持GDI+功能。