Load Dll at Singleton

  • Thread starter Thread starter Amar
  • Start date Start date
A

Amar

Hi,

I have created a singleton object that has a hashtable which holds
all the functions loaded from a dll in order to have access to these
functions every time i want without having to open each time the dll.
The problem is that when i do this i cannot debug my project at all,
but the project runs perfect with no error. The hashtable is filled
correct! Notice i don't want to debug the function of the hashtable
which cannot be done. I cannot debug even for eg. the load event of a
form which does not contain any code regarding my singleton.

If i change my code to read the assembly and invoke the method at
every call it works perfect.

Anyone has any idea about that??

Thanks.
 
Amar:

I'm afraid I can't follow what you are doing, exactly. Could you post
some code as an example? I don't see why using a hashtable would
prevent you from debugging. Do you get a specific error message when
this happens?
 
ok. here is my code for singleton object, i will write down only the
necessary things..

private static Hashtable assTable;

public class EConfig {
private EConfig() {
LoadSites();
}

public static EConfig Create(){
if (source == null){
source = new EConfig();
return source;
}else{
return source;
}
}

public void LoadSites(){
string assemblyfile = @"c:\Inetpub\wwwroot\MyWeb\MyDll.dll";

FileStream fs = new FileStream(assemblyfile
,FileMode.Open,FileAccess.Read);
BinaryReader bred = new BinaryReader(fs);
Byte[] data;
try{
data = bred.ReadBytes(Convert.ToInt32((fs.Length)));
Assembly a = Assembly.Load(data);
Type[] mTypes = a.GetTypes();
foreach (Type t in mTypes){
if (t.Name == "ProjectWebLib"){
foreach (MethodInfo mi in t.GetMethods()){
assTable.Add(mi.Name,mi);
}
}
}
fs.Close();
}catch(Exception ex){
fs.Close();
}
}

public object GetMethod(string methoName){
return assTable[methoName];
}

}

now with this code i can from my page for eg.

private void Page_Load(object sender, System.EventArgs e) {
if (!IsPostBack){
// DO SOMETHING
}
// SOMETHING ELSE

MethodInfo retmethod =
(MethotInfo)EConfig.Create().GetMethod("function1");
object res = retmethod.Invoke(null,new object[]{"hello"})
... and so on..
}


the problem with this is that even i put a breakpoint for example at
line 1 of IsPostBack the debugger never goes in!!!!

on the other hand if i want to call method "function1" without using the
singleton , and read every time the dll with the same code like the one
of the singleton it works great.

What i am trying to tell you is that when tha hashtable is filled with
methods i cannot debug at all. My singleton works great with all the
other stuff i am using ConnectionString and so on..

Thanks for help.
 
Hmm, that is some interesting code. I could understand if you could
not step into code that is being dynamically invoked, but I'm not sure
why debugging would not work at all. Are you sure the project settings
remain the same (like not switching between debug and release modes)
when you are not using the hastable?
 
Yes i have checked these stuff.. it is always in debug mode, to tell
you the truth i have being trying to solve this for 2 weeks now but i
cannot understand why is this hapenning it is completely "stupid" as
far it concerns .NET ...

Thanks for help anyway..
 
Back
Top