I have a class library project which is attached to a main project and in this class library project I have a class named SQSQueueScheduler.cs under this class I have written the below code
Contacts contact = (Contacts)ConfigurationManager.GetSection("bolteContactConfiguration");
if (contact != null)
{
className = contact.ClassName;
Type myclass = Type.GetType(className);
objContacts = (Contacts)Activator.CreateInstance(myclass);
}
The Contacts here is a base class through which I want to create the instnace of derived class ChildContacts dynamically. This base class is present in class library project and the derived class in main website. The value of variable className is Child.ChildContacts(AIST is the namespace and AISTContacts is the name of class). Here I am getting the Null value in myClass variable. The code I have written in web.config of the main project is
<section name="bolteContactConfiguration" type="TDNBolte.Contacts,3DN Bolte" requirePermission="false"/>
<bolteContactConfiguration name ="Contacts" className="Child.ChildContacts"/>
Here 3DN Bolte is the name of assembly of class library project.
I would like to ask, is there a way to get the type of class present in main website(ChildContacts) through the code written in a class(SQSQueueScheduler) of class library project?
1- Your Assembly class library project name: "3DN Bolte" is consisted of two words seperated with space which can be misleading at copmile, so try to change the name to a combined one like: "3DN_Bolte".
2- Instead of getting ClassName which only has name of class and lacks specified name or namespace, use GetType().ToString() to have class name following namespace:
3-In a nutshell, your code could look like this: