Red Gate forums :: View topic - Exception: Invalid type owner for DynamicMethod.
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

Exception: Invalid type owner for DynamicMethod.

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Wed Mar 23, 2011 3:40 pm    Post subject: Exception: Invalid type owner for DynamicMethod. Reply with quote

I am a bit lost on this one. It happened with SA5 and happens with SA6 but doesnt (of course) in the non-protected assembly.

What i get is the following:

System.ArgumentException occurred
Message=Invalid type owner for DynamicMethod.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility, Boolean transparentMethod)
InnerException:

The call stack though shows a bit more:

mscorlib.dll!System.Reflection.Emit.DynamicMethod.Init(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] signature, System.Type owner, System.Reflection.Module m, bool skipVisibility, bool transparentMethod)
mscorlib.dll!System.Reflection.Emit.DynamicMethod.DynamicMethod(string name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, bool skipVisibility)
Uniwares.Mail.Server.dll!#e.#d.#F()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceApplication()
[Native to Managed Transition]
[Managed to Native Transition]
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.#Xk(string methodName = "OnStart", object[] parameters = {object[0x00000001]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.Start()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceMain(string[] args = {string[0x00000000]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.SelfMonitoringServiceApplication<–.™>.Main2(string[] args = {string[0x00000000]})
aMandaServer.exe!–.˜.(string[] args = {string[0x00000000]})
[Native to Managed Transition]
[Managed to Native Transition]


Deobfuscating the trace:

mscorlib.dll!System.Reflection.Emit.DynamicMethod.Init(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] signature, System.Type owner, System.Reflection.Module m, bool skipVisibility, bool transparentMethod)
mscorlib.dll!System.Reflection.Emit.DynamicMethod.DynamicMethod(string name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, bool skipVisibility)
Uniwares.Mail.Server.dll!SmartAssembly.HouseOfCards.Strings.CreateGetStringDelegate()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceApplication()
[Native to Managed Transition]
[Managed to Native Transition]
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.InvokeServiceMethod(string methodName = "OnStart", object[] parameters = {object[0x00000001]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.Start()
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.ServiceApplication<–.™>.ServiceMain(string[] args = {string[0x00000000]})
Uniwares.Mail.Server.dll!Uniwares.Mail.Server.SelfMonitoringServiceApplication<–.™>.Main2(string[] args = {string[0x00000000]})
aMandaServer.exe!–.˜.(string[] args = {string[0x00000000]})
[Native to Managed Transition]
[Managed to Native Transition]

The "Uniwares.Mail.Server.ServiceApplication<–.™>" doesnt deobfuscate at all, reason unknown yet.

Any ideas where to start? This used to work before, there has been no change at all in the Uniwares.Mail.Server.dll since ages. Changes have been applied to assemblies below and above the call chain.
Back to top
View user's profile Send private message MSN Messenger
Brian Donahue



Joined: 23 Aug 2004
Posts: 6671

PostPosted: Fri Mar 25, 2011 10:54 am    Post subject: Reply with quote

Hello.

It looks like this is one of those "you can't obfuscate anonymous types" issues that can happen with LINQ to SQL. The list of all the types I know of that must be excluded are listed on the SDK Wiki. (The list may be incomplete)

The bits that can't be deobfuscated probably exist in another assembly that has been protected with SmartAssembly at obfuscation level 2 or higher (non-ASCII) because you can't use the stack decoder except with ASCII obfuscation.
Back to top
View user's profile Send private message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Fri Mar 25, 2011 1:02 pm    Post subject: Reply with quote

I wish it was LINQ to SQL or at least LINQ at all, but its not. LINQ is not used at all.

The interesting thing I found out here is that in a release version without SA the exception is another one but its swallowed by the runtime.
The runtime tries to load an serialization assembly which doesn't exist but it continues without it (who has the guts to dive into such a thing?)

Yet, after protection it turns into something completely different which worries me a bit.
Back to top
View user's profile Send private message MSN Messenger
Brian Donahue



Joined: 23 Aug 2004
Posts: 6671

PostPosted: Fri Mar 25, 2011 1:40 pm    Post subject: Reply with quote

It looks like an anonymous type -- I'm not sure about all of the .NET objects that use them, but LINQ and lambda expressions are two I know of.
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6671

PostPosted: Tue Mar 29, 2011 1:08 pm    Post subject: Reply with quote

Did you try excluding the anonymous types? Sorry I don't know which - they appear to be non-ASCII obfuscated in another assembly of yours.

In my experience all .NET apps throw a serialization exception when they look for pre-compiled "XmlSerializers" assemblies, handle the exception, and emit an "XmlSerializers" assembly dynamically.
Back to top
View user's profile Send private message
Chris.Allen



Joined: 12 Mar 2009
Posts: 591

PostPosted: Tue Mar 29, 2011 1:22 pm    Post subject: Reply with quote

Another line of attack- could you help us reproduce please? This allows us access to development resources and often speeds up resolution time dramatically. I can set you up any ftp space necessary.
Back to top
View user's profile Send private message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Tue Mar 29, 2011 11:01 pm    Post subject: Reply with quote

I guess what Brian said about the XmlSerializers is happening here (at the not protected app shows that), but what happens then with the protected app is at the moment out of my understanding.

I will be able to repro that for you but give me a few days resolver other issues first.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group