Yet another Visio interop programming problem

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, Alex.Davies, melvyn.harbour

Yet another Visio interop programming problem

Postby Roger Billsdon » Tue Aug 03, 2010 11:43 am

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
Roger
Roger Billsdon
 
Posts: 9
Joined: Sat Jul 31, 2010 8:10 am
Location: Cambs, UK

Postby slaphead99 » Wed Aug 04, 2010 1:59 pm

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.
slaphead99
 
Posts: 92
Joined: Wed Mar 10, 2010 2:27 pm

Postby Paul.Martin » Fri Aug 06, 2010 12:21 am

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?
Paul.Martin
 
Posts: 83
Joined: Wed Feb 03, 2010 11:20 am
Location: Cambridgeshire

Postby slaphead99 » Fri Aug 06, 2010 2:46 pm

Just to tie-up this and your other post- are you processing any 3rd party assembly with smartassembly? Is rare that this ever works.
slaphead99
 
Posts: 92
Joined: Wed Mar 10, 2010 2:27 pm

Postby Roger Billsdon » Fri Aug 06, 2010 7:07 pm

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
Roger
Roger Billsdon
 
Posts: 9
Joined: Sat Jul 31, 2010 8:10 am
Location: Cambs, UK

Postby slaphead99 » Mon Aug 09, 2010 5:11 pm

I'm pretty sure smartassembly doens't touch any threading logic or thread primitives. I still wonder if there's any serialization going on...
slaphead99
 
Posts: 92
Joined: Wed Mar 10, 2010 2:27 pm


Return to SmartAssembly 5

Who is online

Users browsing this forum: No registered users and 0 guests