Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Tools and Features
Advanced Topics
 Reflection and Dynamic Class Loadin...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Obfuscator -- Dotfuscator Community Edition by PreEmptive Solutions 
Reflection and Dynamic Class Loading 

Reflection and dynamic class loading are extremely powerful tools in the .NET architecture. This level of runtime program customization prevents Dotfuscator from infallibly determining whether it is safe to rename all types loaded into a given program.

Consider the following (C#) code fragment:

public object GetNewType() { 
   Type type = Type.GetType( GetUserInputString(), true ); 
   object newInstance = Activator.CreateInstance( type ); 
   return newInstance; 
} 

This code loads a type by name and dynamically instantiates it. In addition, the name is coming from a string input by the user! (Or a runtime database, or another program, etc.)

There is obviously no way for Dotfuscator to predict which type names the user will enter. The solution is to exclude the names of all potentially loadable types (note that method and field renaming can still be performed). This is where manual user configuration (and some knowledge of the application being Dotfuscated) plays an important role.

Often the situation is less serious. Consider a slight variation:

public MyInterface GetNewType() { 
   Type type = Type.GetType( GetUserInputString(), true ); 
   object newInstance = Activator.CreateInstance( type ); 
   return newInstance as MyInterface; 
} 

Now it is immediately obvious that only a subset of types need to be excluded: those implementing MyInterface.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker