I am developing a console application abc.exe. I have another assembly called abc.xyz.dll. Both the applications are in same solution
Structure
abc
--abc
----abc.exe
--abc.xyz
----abc.xyz.dll
I want to dynamically load the abc.xyz.exe assembly in the console application abc.exe where the name of assembly is mentioned in app.config file
<appSettings>
<add key="modelType" value="abc.xyz.Worker,abc.xyz" />
</appSettings>
I have tried
string assembName = ConfigurationManager.AppSettings.Get("modelType");
type = Type.GetType(assembName);
but it returns null. I do not want to load the assembly in GAC or specify the path in environment variable.
Please help me with a solution.
I am trying to solve below problem
Develop a console application which would probe a given model class at runtime, and ask the user to fill the object.
The model class, as part of our assignment, is a simple class as shown below:
[Model(DisplayName = "Employee")]
public class Worker
{
[Display(Name = "Employee ID")]
public int WorkerId { get; set; }
[Display(Name = "Full Name")]
public string Name { get; set; }
[Display(Name = "Date of Birth")]
public DateTime DateOfBirth { get; set; }
[Display(Name = "Salary")]
public decimal Remuneration { get; set; }
}
Create an assembly named ‘DynamicConsole.Core.dll’, and create an attribute ‘Model’ with ‘DisplayName’ property.
o In Visual Studio, use code snippet ‘attribute’ for the recommended pattern.
Create another assembly named ‘Organization.Domain.dll’, and create model class Worker as shown above.
o You would need to add references to ‘DynamicConsole.Core.dll’ and ‘System.ComponentModel.DataAnnotations.dll’ to resolve references of ‘Model’ and ‘Display’ attributes.
Create a console application ‘DynamicConsole.exe’.
o This application will pick the model type from app.config, and ask the user to fill in the required details.
(key="modelType", value="FullyResolvedTypeName, AssemblyName")
o You would need to add references to ‘DynamicConsole.Core.dll’ and ‘System.ComponentModel.DataAnnotations.dll’ to resolve references of ‘Model’ and ‘Display’ attributes.
o Don’t add reference to ‘Organization.Domain.dll’ as it should be picked from
app.config during runtime.
<appsettings>
<add key="modelType" value="Organization.Domain.Worker, Organization.Domain">