How can we help you today? How can we help you today?

Bug: Wrong order of methods with ComInterop classes

Hi, I like using reflector to get source for Com-Interop assemblies generated by visual studio, so I can include them in the main codebase instead of having a dozen additional interop assemblies, and also I can throw out all the additional interfaces I don't need.

However there is one critical problem with disassembling Com-Interop code: Reflector is reordering methods and I can find no option to turn it of. Disabling optimizations doesn't help, even IL is shown in the wrong order! (There are also some other issues with duplicated properties and missing export keywords in CoClasses for the generated C# code, but IL is correct here at least and C# disassembly is easily fixed manually by a search/replace)

Let me explain why method order is an issue at all: for com-interop the methods of interfaces/classes must appear in the exact same order as in the header/typelib, otherwise the runtime ends up calling wrong methods. (DispIds don't help either, binding seems to be a direct VTable mapping)

So what I'm doing is using the IL-disasm from the framework to figure out the order of methods and reorder the code I get from reflector - which is a huge pain when there are hundreds of methods in a typelib.

One thing which is especially dangerous and easy to miss is that also for get/set methods of properties order does matter! Reflector always shows the get-method first, which is wrong, so those need to be reordered too, to match the order they appear in the IL-disasm (or the header, if I'm lucky enough to have one for the imported typelib).

It would help a lot if you could fix this (adding an option to turn of automatic ordering would be fine) - and please make sure you respect order of get/set methods of properties.

You can always compare with the IL-disasm from the dotnet framework, and if you need a sample interop dll for testing you can use quartz.dll which should be in any windows installation, get/set methods appear in both orders in the interfaces, causing exceptions if not reordered properly, since the get-method is called when you mean set... (quartz.dll is a com-wrapper for DirectShow, can be found under ActiveMovie when adding a com-reference to a project)
Zarat
0

Add comment

Please sign in to leave a comment.