Before asking the question that I want to ask, let me introduce you to my problem.
My company works on a website that we are developing in ASP.NET MVC. One of the pages needs to display an image showing a directed graph (the graph is created using the Microsoft.Glee graph library). The method that creates the graph is given below:
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;
}
}
I am not the original writer of this code, i.e. it was written by another programmer in my company, so I can't really justify the decisions made in the code.
Anyway, the problem that I have is the following: when I test the page locally, the image is created successfully and is displayed on the page. However, when I deploy the website (we are using Windows Azure for hosting), I get the following exception:
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()
I suppose that this is some memory issue, but can you tell me what do you think about it and what might be the cause of the problem? Searching the web didn't really help me.
Thanks in advance.