Have an error to use a string combined into a path to run the object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • YuJie
    New Member
    • Oct 2010
    • 1

    Have an error to use a string combined into a path to run the object

    Hello guys~

    I got problem
    this is my code:

    Code:
         MainForm mainForm = this.ParentForm as MainForm;
         string strassemblyName = string.Empty;
                
         strassemblyName = "PowerOne.Win.Order".ToString();
         //Assembly
                        
         System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName();
    
         assemblyName.Name = strassemblyName;
    
         AppDomain appDomain = AppDomain.CurrentDomain;
         System.Reflection.Assembly tmpass = appDomain.Load(assemblyName);
    
         CustomerTypeEdit form =			(CustomerTypeEdit)tmpass.CreateInstance("PowerOne.PowerOne.Win.Order.CustomerTypeEdit", true);
    
         form.Show();

    But this "form" is still null
    Who can help me to fix it?????
    Last edited by Curtis Rutland; Oct 20 '10, 03:23 PM.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    I've used the static class Activator to create instances from an assembly qualified name before.

    For example:
    Code:
    string aqn = "System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
    Type type = Type.GetType(aqn);
    int i = (int)Activator.CreateInstance(type);
    Look at how the AssemblyQualifi edName is put together. "Full.Namespace .ClassName, Assembly.Name, Version, Culture, PublicKeyToken" .

    You can find the AQN with this code:
    Code:
    Console.WriteLine(typeof(Int32).AssemblyQualifiedName);
    You just need to plug in the type of the object you're using.

    Comment

    • Subin Ninan
      New Member
      • Sep 2010
      • 91

      #3
      What are you trying to do?
      You can get path of your currently executing assembly using:

      Code:
      Assembly.GetStartUpPath();

      Comment

      Working...