gpt4 book ai didi

c# - Azure 上的 Microsoft.Glee.GraphViewerGdi.GViewer 引发异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:25:34 28 4
gpt4 key购买 nike

在问我想问的问题之前,让我先向您介绍一下我的问题。

我的公司正在开发一个使用 ASP.NET MVC 开发的网站。其中一个页面需要显示一张图像,该图像显示有向图(该图是使用 Microsoft.Glee 图库创建的)。创建图表的方法如下:

private bool CreateGraph(XDocument document, string graphPath)
{
try
{
if (document.Descendants("Nodes").Count() == 0)
return false;

Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");

string id, parent;
foreach (var node in document.Descendants("Nodes"))
{
id = node.Attribute("Id").Value;
parent = node.Attribute("Parent").Value;

Microsoft.Glee.Drawing.Edge edge = graph.AddEdge(parent, id);

edge.TargetNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
edge.SourceNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.Circle;
}

Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Glee.GraphViewerGdi.GraphRenderer(graph);
renderer.CalculateLayout();
Bitmap bitmap = new Bitmap((int)graph.Width, (int)graph.Height, PixelFormat.Format32bppPArgb);
renderer.Render(bitmap);
bitmap.Save(graphPath);

return true;
}
catch
{
throw;
}
}

我不是该代码的原始编写者,即它是由我公司的另一位程序员编写的,因此我无法真正证明代码中所做决策的合理性。

无论如何,我遇到的问题是:当我在本地测试页面时,图像创建成功并显示在页面上。但是,当我部署网站时(我们使用 Windows Azure 进行托管),出现以下异常:


The type initializer for 'Microsoft.Glee.GraphViewerGdi.GViewer' threw an exception.
System.TypeInitializationException: The type initializer for 'Microsoft.Glee.GraphViewerGdi.GViewer' threw an exception. --->
System.ComponentModel.Win32Exception: Error creating window handle.
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.CreateGraphicsInternal()
at System.Windows.Forms.Control.CreateGraphics()
at Microsoft.Glee.GraphViewerGdi.GViewer.GetDotsPerInch()
at Microsoft.Glee.GraphViewerGdi.GViewer..cctor()
--- End of inner exception stack trace ---
at Microsoft.Glee.GraphViewerGdi.GViewer..ctor()
at Microsoft.Glee.GraphViewerGdi.GraphRenderer.CalculateLayout()

我认为这是一些内存问题,但是您能告诉我您对此有何看法以及问题的原因可能是什么?网络搜索并没有真正帮助我。

提前致谢。

最佳答案

不,这不是内存问题。问题是 Glee 库似乎需要一个窗口句柄来完成其工作,这在本地调试时工作正常,因为您已登录到服务器并有一个打开的窗口终端来生成句柄。

但是,当在服务器上运行时,它很可能与网络服务等用户或未登录到 Window 终端的特定用户关联,因此没有关联的桌面来创建 window 。

您的代码运行所在的服务器可能具有中等信任度,并且不允许创建窗口句柄。我对 Azure 的了解不够,不知道情况是否如此。

编辑:

看来您需要在 Azure 上启用完全信任

http://blogs.msdn.com/b/windowsazure/archive/2009/03/18/hosting-roles-under-net-full-trust.aspx

在您的服务定义文件中,您需要添加:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyService"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole" enableNativeCodeExecution="true">
<InputEndpoints>
<InputEndpoint name="HttpIn" protocol="http" port="80" />
</InputEndpoints>
</WebRole>
</ServiceDefinition>

关于c# - Azure 上的 Microsoft.Glee.GraphViewerGdi.GViewer 引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12693041/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com