473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Load Dll at Singleton

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.
Nov 18 '05 #1
4 1411
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 8 Nov 2004 00:06:49 -0800, am******@yahoo.com (Amar) wrote:
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.


Nov 18 '05 #2
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 08 Nov 2004 06:40:01 -0800, Margelos Aris <am******@yahoo.com>
wrote:
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #4
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..

Scott Allen <bitmask@[nospam].fred.net> wrote in message news:<fr********************************@4ax.com>. ..
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tim Clacy | last post by:
Is there such a thing as a Singleton template that actually saves programming effort? Is it possible to actually use a template to make an arbitrary class a singleton without having to: a)...
10
by: E. Robert Tisdale | last post by:
Could somebody please help me with the definition of a singleton? > cat singleton.cc class { private: // representation int A; int B; public: //functions
1
by: Jim Strathmeyer | last post by:
So I'm trying to implement a singleton template class, but I'm getting a confusing 'undefined reference' when it tries to link. Here's the code and g++'s output. Any help? // singleton.h ...
3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
3
by: Harry | last post by:
Hi ppl I have a doubt on singleton class. I am writing a program below class singleton { private: singleton(){}; public: //way 1
5
by: Pelle Beckman | last post by:
Hi, I've done some progress in writing a rather simple singleton template. However, I need a smart way to pass constructor arguments via the template. I've been suggested reading "Modern C++...
1
by: Franz | last post by:
Hello NG I added a new tracelog class in a existing assebley witch is located in GAC. If I try to access a methode of this new class I'll get an errormeassage like this: Could not load type...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.