Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is with your idea that assembly name is a part of your class name. True you need access to your assembly, but ultimately a class name is just <code>Namespace.Class</code> name. If you provide your actual namespace along with the class, then it works. Change your method to this, perhaps:</p> <pre><code>private static T CreateInstance&lt;T&gt;(string fullyQualifiedClassName) { try { return (T)Activator.CreateInstance(Type.GetType(fullyQualifiedClassName)); } catch (Exception ex) { clsAdmFunctions.RecordException(ex); // Record error to the database MessageBox.Show("Error instantiating the object\n\nDescription : " + ex.Message, "Object Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return default(T); } } </code></pre> <p>In other words you need the namespace too if you're saving it in the database. Just save <code>class.GetType()</code> as such or <code>class.GetType().ToString()</code> after which you will see the namespace too saved. The reason is you can have classes with same name, <code>namespace1.Person</code> and <code>namespace2.Person</code> in the same assembly.</p> <p>If you need to read all the namespaces in an assembly, you can do:</p> <pre><code> foreach(var type in Assembly.WhateverAssembly().GetTypes()) //print type.Namespace; </code></pre> <p>You're stuck if you dont know the exact namespace. May be you can <strong>assume</strong> it to be </p> <pre><code>var namespace = Assembly.WhateverAssembly().GetTypes()[0].Namespace; </code></pre> <hr> <p>You need to have namespaces for your classes, doing otherwise is against .NET's design. If you really really want to have no namespaces for your Forms, you just need to specify just the class name, exclude the assembly name. Just call:</p> <pre><code>CreateInstance&lt;MyForm&gt;("MyForm"); </code></pre> <p>provided <code>MyForm</code> is <code>global</code> and the assembly is just the same. If forms are in different assembly, then load it first using <code>Assembly.Load</code> or <code>Assembly.LoadFrom</code> and then create instance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload