473,804 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1430
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\ww wroot\MyWeb\MyD ll.dll";

FileStream fs = new FileStream(asse mblyfile
,FileMode.Open, FileAccess.Read );
BinaryReader bred = new BinaryReader(fs );
Byte[] data;
try{
data = bred.ReadBytes( Convert.ToInt32 ((fs.Length)));
Assembly a = Assembly.Load(d ata);
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(Exceptio n ex){
fs.Close();
}
}

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

}

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

private void Page_Load(objec t sender, System.EventArg s e) {
if (!IsPostBack){
// DO SOMETHING
}
// SOMETHING ELSE

MethodInfo retmethod =
(MethotInfo)ECo nfig.Create().G etMethod("funct ion1");
object res = retmethod.Invok e(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 ConnectionStrin g 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\ww wroot\MyWeb\MyD ll.dll";

FileStream fs = new FileStream(asse mblyfile
,FileMode.Open ,FileAccess.Rea d);
BinaryReader bred = new BinaryReader(fs );
Byte[] data;
try{
data = bred.ReadBytes( Convert.ToInt32 ((fs.Length)));
Assembly a = Assembly.Load(d ata);
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(Exceptio n ex){
fs.Close();
}
}

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

}

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

private void Page_Load(objec t sender, System.EventArg s e) {
if (!IsPostBack){
// DO SOMETHING
}
// SOMETHING ELSE

MethodInfo retmethod =
(MethotInfo)EC onfig.Create(). GetMethod("func tion1");
object res = retmethod.Invok e(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 ConnectionStrin g 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
12481
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) explicitly make the arbitrary class's constructor and destructor private b) declare the Singleton a friend of the arbitrary class
10
2659
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
2454
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 template <class T> class Singleton : public T { public: static T * Instance();
3
2502
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 what sort of problems/issues should be considered? Also, I see that a singleton needs to be set up with certain data such as file name, database URL etc. What issues are involved in this, and how would you do this? If someone knows about the...
3
3930
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
5313
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++ Design" or similar books, but I feel there are full of clever guys here who could help me out.
1
1549
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 xxxx from assembly xxxx, Version=1.0.4850.0, Culture=neutral, PublicKeyToken=302009412214000a. I searched in ng and found some tasks, like 'do not use enums' or 'make sure you rebuild asembley before creating a new msi', 'check
3
18258
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 is, regardless of where the object is hidden, everyone needs access to it. The global point of access is the object's Instance() method. Individual users need to be prevented from creating their own instances of the Singleton.
3
1808
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 constraints/environment are as follows: 1) Everything is single-threaded during static initialization (as in prior to the open brace of main) 2) The environment may be multi-threaded during nominal program execution (within {} of main) 3) I...
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.