I am using the Windows Diagram control to generate image files from diagrams that are generated through code in batch. However, I have problems because it turns out that the application that initiates my program is using a multiple threading apartment model (MTA). When I create a STA thread, I can only generate one diagram. Subsequent attempts to create diagrams errors.
The application works great when attached to a form for testing or from a console using a single threaded apartment (STA). I do not have a diagram control on a form. I use a self-contained class that creates a diagram control, draws the diagram and then saves the image.
When the class is then accessed through an external assembly, which is a console command, errors start occurring. I cannot seem to work through these errors because they are too deep into "Syncfusion.Diagram.Base".
The errors all start with the threaded apartment state. If the console command has a state of STA, no issues occur. However, if the state is MTA the problems start. I cannot control the state and it will be set to MTA. Below is a description of what has taken place.
I simply do not know what to do next. Any advice on what to do next will be appricated. I attached a demostration of the issue with a readme file that contains the specific errors.
- ROUND ONE -
The first time my class was created by the console command. I received “DragDrop registration did not succeed" (ERROR 1 - in readme.txt. Research tells me the source of this error is related to Windows Forms when the thread apartment state is in MTA mode.
- ROUND TWO -
I then spun a new STA thread to create the image. This worked fine for the first pass. However, if more than one diagram is created an Object Not Set error occurs. In other words, if I attempt to create a second instance of the diagram control, then I get an "Object reference not set to an instance of an object." (ERROR 2 - in readme.txt) on the following line of code.
Dim diagram = New Syncfusion.Windows.Forms.Diagram.Controls.Diagram
This error occurs regardless of how I attempt to dispose or set the diagram object to nothing, so a brand new instance of the object can be created from scratch. I attempted to clear out the diagram object from memory and start a new thread. Still get the error.
- ROUND THREE -
I attempted to keep the diagram control object declared and reuse it on the second pass. On the first pass the process worked fine. However once again on the second pass it errors. However, now the error is in the symbol not the diagram control. There are various "Object reference not set to an instance of an object" errors (ERROR 3 - in readme.txt) when adding label or nodes to the symbol. I have gotten further because I have a diagram object to use, but I cannot work with the symbols. DiagramTestLibrary.zip