473,395 Members | 1,938 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,395 software developers and data experts.

different behaviour design time / run time

Hi Code guru's

I have created a user control which has access, and thus makes use of a shared singleton class like:
Dim MyAppSettings As DLAppSettings = DLAppSettings.GetAppSettings

This singleton class has amongst other stuff the following line of code in it:
Private m_DL_DBPath As String = System.Configuration.ConfigurationSettings.AppSett ings("DMDatabasePath")

As you guess, it must read a string containing the path. Based on this string, a connection string is build later in the code.

Now the control is placed onto a form, and when I open the form (in design time) in the editor, it seems code is executed. And the code fails because the m_DL_DBPath variable has the value nothing.

Yet everything works as it is supposed to be when compiling and running the code.

1) Why is code executing in the designer when I throw user controls on a form?
2) Does System.Configuration.ConfigurationSettings.AppSett ings work in design time?

Help is much appreciated as I am already hammering for three days on this.

eMKa
Jul 21 '05 #1
10 1894
Hello eMKa,

Thanks for your post. As I understand, the problem you are facing is that
your application works when running without debugger, while it fails when
starting from VS .NET. Please correct me if there is any misunderstanding.
I think more information is needed before moving forward:

Where does your config file locate, the projects' folder?
Could you post a simple project which is able to reproduce the problem?

I look forward to hearing from you.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #2
Dear HuangTM,

No, that's not exactly correct.
My program runs correctly if compiled and executed outside VS
But it also runs fine when being debugged in VS.
The strange thing is that when I open a form in the editor which contains the user control, then code seems executed (no idea why!) I ams sure because I put msgboxes in the code, and they are appearing, hence code is being executed.

I am trying to reproduce the problem in a small project, because the current project is big and complex.
Jul 21 '05 #3
Hi,

I have not received it yet. Could you please send it to me at
ti******@microsoft.com?

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #4
I did send you an example last Friday. To be sure I have send it again today. B.t.w. can't you attach files to posts?
Jul 21 '05 #5
Hi,

Thanks for your sample. I tested on my side, however, I am not able to
reproduce the problem. The Path is read properly, and I only get the
following message box:
"Configuration file problem -- [DDbs][SetDatabases] Got path=D:\Visual
Studio Projects\DT\DT.mdb"

For further investigation, I suggest you to use FileMon to check whether or
which .config file was loaded .

FileMon
http://www.sysinternals.com/ntw2k/source/filemon.shtml

I look forward to your response.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #6
Hi,

Thanks for your response. I checked your project again, I noticed that you
get the appsettings in the New of the constructor of DCtrl. You know, this
function is generated by WinForm Designer and will be used in the Designer.
To work around this problem, I suggest you to move the following code from
New() to Init() method:

MyAppSettings = DAppSettings.GetAppSettings
MyDBs = DDbs.GetDDbs

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #7
Hi TiM

Thanks for bringing this up. Actually I moved the code to the ‘new’ as an experimnt. Usually I do not put code up there. Originally I had put it in the declaration section (in the Dctrl user-control class) like this;
Dim MyAppSettings As DAppSettings = DAppSettings.GetAppSetting
Dim MyDBs As DDbs = DDbs.GetDDb

Which gives the same (error) result. Also the ‘Init’ function was put there as an experiment and as a last resort to get rid of the error messages during design-time (like you also suggested). I feel an ‘Init’ function is not a good way of practicing OO-programming. Because now I must assure that the ‘Init’ function is called in the Form Load event of each and every form that is hosting the control. Do you agree

The point is that I am not trying to get rid of the error; I am trying to understand what is happening and why it is happening. My argument is: Why does it work at runtime and not at design-time. And what is actually happening at design-time? Why is code executed at design time? And why does it work if I move these lines to the ‘Init’ function

Hope you can give me some clues

Marti

Jul 21 '05 #8
Hi ,

Since this issue is closly related to winform design time behavior, Tim has
transferred this issue to me. I'd like to confirm if I have understood your
scenario correctly.
You have a component which in its constructor will read
ConfigurationSettings.AppSettings collection to get the path setting from a
.config file. the path setting could be get correctly in run-time
regardless in or not in the debugger, however you could not get the value
if put the component onto form in design-time. If there is any
mis-understanding, please feel free to correct me.

I could reproduce the behavior described above on my system, after some
investigation, I found this is because the .NET configuration system always
try to load the .config file with the same name as the executable name
from the Application Base, when the component are created in design-time,
it's actually running in the AppDomain of Vs.NET IDE, so that it tries to
retrieve the corresponding data from
"<path_to_devenv.exe>\devenv.exe.config"
here, the Application Base is where the app start from
and the entry assembly name is devenv.exe
Of course by default devenv.exe.config does not contain "appSettings"
section and your settings, that's why you could not get the corresponding
settings.

Does it answer your question?
If you have anything unclear about my reply, please feel free to reply this
thread.

By the way, we have a special group for design-time programming in windows
forms, you may post design-time issues to that group next time.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.

Jul 21 '05 #9
Dear Ying-Shen Yu and Tim

Thanks for explaining this. It is perfectly clear answer. I expected that the config file would be (temporarily) copied to that directory automatically. Also I have been experimenting with copying the config file to the bin directory, but that did not help either, so I got confused and wanted to know what was going on. I will try copying it to the right spot tomorrow. This issue should be resolved then

Thanks again

Marti

Jul 21 '05 #10
Dear Ying-Shen and Ti

OK, I can confirm that putting the information in the devenv.exe.config does indeed work
This is of course not a "good programming practice" and a potentially confusing solution. It is something that could be improved in the next version of Visual Studio. E.g. it would be better if the application's own config file was copied to this location during design time.

Thanks again for explaining this feature

Martin
Jul 21 '05 #11

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

Similar topics

137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
23
by: Dufe | last post by:
Hello all: To deal with the problem of differing user screen resolutions, I've explored: 1) making the pages in PHP, 2) having different pages on the same page and selecting the proper one via...
8
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at...
4
by: | last post by:
I have earlier used an HttpModule that did URL rewrites on the BeginRequest event. Now I am trying to use the same module in a different application on a new and upgraded machine (winxp sp2). ...
29
by: Charles Law | last post by:
Further to my issue about user controls, I have a problem with DesignMode. Here is the project hierarchy: MainApp |_ Project1 |_ SubProject (UserControl) SubProject has a default constructor...
11
by: eMKa | last post by:
Hi Code guru's I have created a user control which has access, and thus makes use of a shared singleton class like: Dim MyAppSettings As DLAppSettings = DLAppSettings.GetAppSettings This...
14
by: Robben | last post by:
Hi All, I have an integer pointer with value 10, but it returns a different return value after the preincrement and post increment. I will be very thankful if somebody can give an explanation...
9
by: horizon5 | last post by:
Hi, my collegues and I recently held a coding style review. All of the code we produced is used in house on a commerical project. One of the minor issues I raised was the common idiom of...
16
by: Stefano Sabatini | last post by:
Hi all, I'm facing this design problem. I have a table which defines the behaviour of an Object in a given state according to the type of event it is receiving. So for each couple...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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,...

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.