|
Hi!
I'm having a problem with the AppSettingsReader class. What I want to do is to retreive a value based on a key from a "App.config" file in my application.
The problem is that when I compile the code everything is ok (no errors, no warnings), but when I run the method (see below) I get an ConfigurationException (see below) that I don't understand. The exception occurs when the code tries to instantiate the "confReader" variable:
//code snippet:
System.Configuration.AppSettingsReader confReader =
new System.Configuration.AppSettingsReader();
The method is in a System.Windows.Forms.Form class.
Can anyone help me?
Thanks in advance!
//The Exception:
"An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: This is an unexpected token. The expected token is 'EQUALS'. Line 4, position 12."
//The method:
private string GetConfigurationValue(string key)
{
string confValue="";
System.Configuration.AppSettingsReader confReader =
new System.Configuration.AppSettingsReader();
if(key=="")
{
throw new Exception("key is empty");
}
try
{
confValue = (string)confReader.GetValue(key,typeof(System.String)).ToString();
}
catch(InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
catch(ConfigurationException ex2)
{
MessageBox.Show(ex2.Message);
}
catch(Exception ex3)
{
MessageBox.Show(ex3.Message);
}
return confValue;
}
|
|
|
|
|
The error says that there is a problem with your config file, not the code.
What does your config file look like? Remember to check the "Do not treat <'s as HTML tags" at the bottom of the message window before you click Submit.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yes!
Thank You!
I spotted the error in my config file. I forgot a '=', just as the exception message said. The code works now!
Wow... Sometimes I even impress myself when I do that kind of mistakes...
Thanks again!
OKB
|
|
|
|
|
I have written a class called Call in c# using serial comms to retrieve certain data from a remote device. The class includes methods like InitializePort(), MakeCall() etc. It also includes events like GotData and CallTerminated. These events are picked up by the calling class Device and are passed on to the GUI that is calling the Device class and the GUI responds accordingly.
The Device class has events like GetData which the GUI calls.
So far all these methods do not return values. Each caller (GUI and Device) call methods and terminate exceution; they just respond to events.
Each GetData function execution takes a different time since the amount of data to be retrieved is arbitrary.
I now need to execute a number of GetData calls in sequence (as part of a loop) from the GUI (or some other class calling the Device
class methods) and therefore need to wait until each call returns a value back to me before I proceed with the next execution.
How do I do that? I am new in .Net and have no experience in multi threading or asynchrnonous programming.
Thanks in advance
Regards
Chris
Thanks and Brgds
|
|
|
|
|
Hy there,
How can I check if the ASP.NET is installed on a server machine.
Thanks,
AdoSun
|
|
|
|
|
Do you mean if the .NET runtime is installed, or if it is installed AND IIS knows about it ?
You can check the folder in the windows subdirectory for the .NET folders, and while I don't know of a way to know if IIS knows about .NET, it's fair to assume it does, and if not, you can run aspnet_regiis once you have found the folder. There are also registry keys you can use, a quick google will tell you about those. I suggest the folder thing first only because I was thinking about if you can't tell that ASP.NET is registered with IIS.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Actually is important if the IIS knows about it.
I want to check this from a C# code.
|
|
|
|
|
IIS would never KNOW about .NET being installed as IIS has nothing to do with that. You may be able to some sort of SystemInformation check as to find that information, but IIS is not the way to go about that.
|
|
|
|
|
ExpertComing wrote:
IIS would never KNOW about .NET being installed as IIS has nothing to do with that.
Very wrong. ASP.NET is registered with IIS as an ISAPI filter. Therefore, it's registered with IIS, and IIS knows about it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
There is one dirty dirty trick... Open C:\{windir}\system32\inetsrv\MetaBase.bin and look for e.g. "X - P o w e r e d - B y : A S P . N E T" string in it. Actually there are all the mappings as well, but file format is unfriendly. (okay, that's because I view it in notepad )
Idea look for it in MetaBase is from this article: http://www.codeproject.com/aspnet/teniistips.asp[^].
David
|
|
|
|
|
Hi, how can I load and unload a .dll file at runtime in my C# project. I need urgent reply plz help me. thankx
|
|
|
|
|
How do you need to load it? Do you need to read it or use it, if you need to use the .dll then there would be no point in unloading it.
|
|
|
|
|
http://www.c-sharpcorner.com/2/pr12.asp
does this help?
|
|
|
|
|
thanks for u r help, actually i am doing the same thing as mentioned in www.c-sharpcorner.com/2/pr12.asp, through this way i have to explicitly add the .dll file (component)to my project(using add reference),but i want to add(load) that component at runtime. as we do in VC++.
|
|
|
|
|
pakfari:
Use Assembly to load the dll, like so:
Assembly SampleAssembly;
string fullp = ((Full Path to the dll))
SampleAssembly = Assembly.LoadFrom(fullp);
//In order to create an Instance of it you have to grab the type of this class
//use Namespace.ClassName
Type ObjType = SampleAssembly.GetType(Namespace.ClassName);
//Create an instance of your dll here
Activator.CreateInstance(ObjType);
As far as running the Dll, there are a few ways to do it.
but this is how you would/could load it at runtime.
Hope his helps
Steve Welborn
Software Architect
|
|
|
|
|
I will just say Great!!!
It is working ok, can u tell me one more thing. How we can invoke the member functions of the Component using objType.
|
|
|
|
|
Well, this is where it can get tricky..at least for me. Because there are a few ways to do this, depending on if you want to call the function right then, or place that object in a Collections class and call it later. Hopefully someone will be able to explain it better than I can, but here goes.
This is how I executed a .dll after loading it.
Remember that when you created the Instance it passed back an object
object instance; //what Assembly.CreateInstance returns
object[] args; //Parameters to pass the function
MethodInfo method = type.GetMethod(functionname);
object returnval = method.Invoke(instance, args);
I hope this helps.
Steve Welborn
Software Architect
|
|
|
|
|
Hi,
Anybody knows how to write factory interface handler that will call multiple handlers. I'm using Sharepoint Services in my application. In this sharepoint i can able to add only one event handler. But i'm in situation that my sharepoint has to communicate with multiple event handlers. I asked this question in Sharepoint forums. They suggested that "You can write a factory interface handler that calls multiple handlers. " . But i didn't get any suggestion about factory interface handler from them.
If anybody knows how to write factory interface handler that will call multiple handlers.
Thanks in advance,
Vinoth
|
|
|
|
|
They are basically telling you the design pattern for a method that becomes your one event handler, and then farms off the event to other event handlers, based on the code in the class.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for ur information,
Could you please tell me clearly "design pattern for a method that becomes your one event handler nd then farms off the event to other event handlers, based on the code in the class".
I don't know anything about design pattern.
bye,
Vinoth
|
|
|
|
|
Google for 'design patterns'. A design pattern is basically an established design for object oriented software, it's an established way of implimenting something cleanly.
You don't need to know any more than what I said, they are telling you to write an event handler that then sends off events to all the places you want them to go.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hai guys
i'm a newbie to C#. My doubt is is 'InitializeComponent()' is somewhat similar to a constructor.
Is there any special features with 'InitializeComponent()'.
Could anyone share it with me plz.
Thanks in advance
Long Live
|
|
|
|
|
Sreenivasan Palaniappan wrote:
My doubt is is 'InitializeComponent()' is somewhat similar to a constructor.
How do you mean ?
This method is inserted by the IDE, and called to set all the properties that you set up in the forms designer. As such, you should never mess with the code here, your changes will disappear. as such, it's also a form of construction activity, I guess. But you should add any code of your own in the spot just below the call that is commented as being the right spot to do so.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No ! 'InitializeComponent()' is a common function that run in the form constructor. But in VS.NET IDE this a protected area of code !! If you try to change any line of code in this function IDE will reproduce the original codes at project rebuilds. In fact this is a scope that IDE put the design time initialization of controls and components there.
[ _ Always there is another way _ ]
|
|
|
|
|
What is an easy way to make a program that opens a port on a server and waits for a client to ask for information. How do I do that client part as well? Can your method send both text and numbers?
|
|
|
|