Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I have written a class library file and use the dll of this file in web application
 
i write some code in this dll like generating connection string as well as appSettings in web.config file
 
but problem is that.... i want to generate this connection string and appsettings data while adding this dll in web application instead of running the application
 
so plz help me...
 
some frnz are not understand my question
let me clear..
 
when i add dll in my application it added successfully
no problem about it.
when i run my application then connection string generate in web.config

bt what happen with this...
all sessions are cleared

hence i want to generate this connection string at the time of adding this dll in application

so is there any event handler or loader is available which will help to get me result
Posted 29-Mar-13 3:04am
Edited 29-Mar-13 22:49pm
v3
Comments
ThePhantomUpvoter at 29-Mar-13 9:21am
   
Huh? What? That makes no sense at all. Why would you need to generate connection data when the application is not running at all?
Abhinav S at 29-Mar-13 9:54am
   
Do you mean you want to generate the connection string dynamically?
Shree.grace at 30-Mar-13 1:05am
   
i think you are not understand my question..
let me clear...
 
when i add dll in my application it added successfully
no problem about it.
when i run my application then connection string generate in web.config

bt what happen with this...
all sessions are cleared

hence i want to generate this connection string at the time of adding this dll in application

so is there any event handler or loader is available which will help to get me result
raza.ahmed.se at 30-Mar-13 1:53am
   
Do you want to load a dll at runtime and use its methods?
Shree.grace at 30-Mar-13 2:17am
   
ya..
but this method will execute at once when i add this dll in apllication
instead of executing this method every time when i run the application

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you want to add a dll at run time and use its methods, then you have to use dynamic loading technique already available in C#.
Namespaces:
using System.Reflection;
using System.IO; // For FileNotFoundException definition.
code:
public void myDllStuff(string myDll) // Put your dll/assembly here
{
string dllName = myDll; 
Assemly asm = null;
 
// Try to load assembly
 try{
     asm = Assembly.Load(asmName); //you can use Assembly.LoadFrom for more flexibility 
    Type[] types = asm.GetTypes(); // To get types from your dll
    noArgumentMethod(asm, "myDll.myMethod");// put your method and dll
    withArgumentMethod(asm, "myDll.myArgumentMethod", true, 1);
    }
 catch
    {
     // Can't find assembly. 
     // Put your exception code.
    }
}
public void noArgumentMethod(string asm, string methodName)
{
// below is the code to run a method from your dll which have no arguments.
    Type myMethod = asm.GetType(methodName); 
    object obj = Activator.CreateInstance(myMethod);
    MethodInfo mi = myMethod.GetMethod(methodName); //"myMethod"
    mi.Invoke(obj, null);
// the above line will run the method and perform whatsoever is within the method of dll. 
}
 
public void withArgumentMetho(string asm, string methodName, bool argument1, int argument2)
{
  // assumning two arguments
 Type myArgumentMethod = asm.GetType(methodName);//"myDll.myArgumentMethod"
 object obj = Activator.CreateInstance(myArgumentMethod);
// Invoke myArgumentMethod() with two arguments
 MethodInfo mi = myArgumentMethod("myArgumentMethod");
 mi.Invoke(obj, new object[]{argument1, argument2});
}
 
You said that you want this whole process to run only for one time, you can do this by setting a flag or saving to a file or database on server.
Hope it helps..
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 400
1 CHill60 200
2 Sergey Alexandrovich Kryukov 170
3 RyanDev 135
4 arvind mepani 120


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 30 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid