Yet another Visio interop programming problem

Roger BillsdonRoger Billsdon Posts: 14
edited August 9, 2010 12:11PM in SmartAssembly 5
Hi all

I've hit yet another Visio interop programming problem, this time with the simple Visio add layer method which works fine in the original program but in the SmartAssembly obfuscated version it crashes with:

Specified cast is not valid System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags)
at Microsoft.Office.Interop.Visio.IVLayer.Add(Shape SheetObject, Int16 fPresMems)

Does anyone have any thoughts please?

Best regards


  • I searched our whole database of calls and could not find once instance with the string "Specified cast is not valid". My instinct here is that Reflection is involved so a call-by-name is being defeated by an obfuscated method name. If that sounds like it is the case, you would need to exclude this method from being obfuscated by using the "Exclusions" feature within the Obfuscation section in the GUI.

    However, if you're sure Reflection is not involved, I'll have a big head-scrath and see if we can help further.
  • Paul.MartinPaul.Martin Posts: 83 New member
    I haven't done any Office interop work, but at a guess something is happening to the Shape struct's data members.

    Do you define the Shape struct yourself or is it part of the Microsoft.Office.Interop.Visio namespace?
    What field types are defined in the Shape struct and do any of them have a explicit cast that you have defined?
  • Just to tie-up this and your other post- are you processing any 3rd party assembly with smartassembly? Is rare that this ever works.
  • Hi both

    Many thanks for those thoughts, but I'm not processing any 3rd party assemblies or defining any shape structs. I've excluded the Microsoft.Office.Interop.Visio namespace and all of my classes that provide Visio helper functions and I've completely disabled pruning.

    All the problems seem to be related to Visio functions that affect the Visio graphical user interface. For example, the select method causes the Visio shape to be surrounded by a green selection box. With this type of operation I think Visio interop can sometimes be a bit slow and I suspect more than one thread is being used so that objects requested via interop may not have been created unless you pause to allow events on the Visio UI thread to be processed. Is it possible that the thread synchronisation has somehow been changed in the obfuscated version of the program or something?

    Sorry if this is a little garbled, but I don’t really know much about the internals of Visio or COM interop and this is just a little conjecture on my part as I'm now really clutching at straws.

    Best regards
  • I'm pretty sure smartassembly doens't touch any threading logic or thread primitives. I still wonder if there's any serialization going on...
Sign In or Register to comment.