Tenuki5's picture

Using XmlSerializer with OpenTK ends up in MDA ContextSwitchDeadlock in exactly 60 seconds

Project:The Open Toolkit library
Category:bug report

I was trying to use XmlSerializer to read/write XML files. After a while I have discovered issue, described in the title. After thorough investigation I have narrowed the issue to the following code:

using System.Xml;
using System.Xml.Serialization;

class Dummy {};

Later, somewhere in code execute:
XmlSerializer serializer = new XmlSerializer(typeof(Dummy));

Allow the application to run for 60 seconds after above code line is executed and you should get MDA ContextSwitchDeadlock exception. I have tested this in empty opentk-1.0-beta-2\QuickStart.sln and could reproduce this issue.

Work-around is to disable the exeption via: Debug->Exceptions->Managed Debug Assistants->ContextSwitchDeadlock (in Visual Studio 2008).

Please let me know if you need additional testing or info. Thanks.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


I have seen this MDA come up before, but I haven't been able to find a valid cause. According to msdn, "The most probable cause is that a single-threaded apartment (STA) thread is not pumping messages." This is not the case here, as the UI thread is pumping windows messages regularly.

According to the same link, this MDA may be falsely raised when "An application creates COM components from STA threads either directly or indirectly through libraries." which is quite interesting. What happens if you decorate the Main method with [MTAThread]?

the Fiddler's picture


Status:open» confirmed
Tenuki5's picture


Using [MTAThread] attribute is actually seems to eliminate this exception! I'm wondering is this fixing the issue and not just masking by putting the problem on separate thread? I must admit even using [STAThread] with the exception (just disabling it) everything (XML, Rendering, Updated, etc.) works perfectly, no detectable memory leaks, very reasonable CPU usage, etc. It looks like false alarm to me.

Yet XmlSerializer itself, in pure C# (without OpenTK) does not generate this exception.

Thanks a lot for your reply! I like [MTAThread] attribute many times more than disabling the exception.

the Fiddler's picture


Status:confirmed» closed