|
so do you mean that I can not add an app.config in my class library project ?
|
|
|
|
|
Correct. If you have the class library goo.dll, then it will not use the goo.dll.config file for its appSettings.
I haven't used .NET 2.0 and do not know if they have expanded support for this to Class Libraries. Maybe someone else on the board can answer that.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I am using 1.1 and it allows me to add app.config
On the other hand, how can i pick up the connectionstring from a datalayer?
Thanks
|
|
|
|
|
I apologize. I don't understand what you mean by it "allows [you] to add app.config" and "pick up the connection string from a data layer."
If you need a configuration string that exists outside your application, you can always just roll your own config file, open it, parse it, and use the values that you find inside it. Or, you could store it in the registry. Or, use the AssemblySettings class to which I linked a couple of posts ago. You don't have to use the .config framework here. I think it would be great if you could....
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
In the class library project, I can go to add new item and add an app.config file.
|
|
|
|
|
Just because you can add it to the project does not mean that your code can use it automatically. Sorry that you got misdirected by the IDE.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
ok, so let me get this correct.
I should not be adding a app.config in my class library project, because even if i do, it will not work.
Is this correct?
Thanks
|
|
|
|
|
Yes.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
ok, now I understand this one.
I am used to using web.config in asp.net
Now i am using windows forms on the client and a datalayer as another project. How can I get the connection string in the datalayer?
Is there a similar method to that in the web.config and using system.configuratioin.appsettinigs, etc...?
Thanks
|
|
|
|
|
If I understand this correctly, you have the following:
Client Application: Windows Forms Application
Data Layer Library: Class Library
If you use the classes from the Data Layer Application in the Client Application, then you can use the .config file distributed with the Client Application. For example, your Client Application's executable is aCoolClientApp.exe. You have a .config file distributed with it named aCoolClientApp.exe.config. Your Data Layer Library will read its appSettings from aCoolClientApp.exe.config.
For example, I have an Windows Forms solution named WindowsApplication4 and a Class Library named ClassLibrary1. They contain the following, respectively:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication4
{
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
DataLayer.Data data = new DataLayer.Data();
Text = data.GetMySetting();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
using System;
namespace DataLayer
{
public class Data
{
public Data() {}
public string GetMySetting()
{
return System.Configuration.ConfigurationSettings.AppSettings[ "MySetting" ];
}
}
}
And, finally, I create the WindowsApplication4.exe.config file with the following contents.
<configuration>
<appSettings>
<add key="MySetting" value="I love C#" />
</appSettings>
</configuration> Now, the call in DataLayer.Data.GetMySetting() will read the setting in WindowsApplication4.exe.config and return it.
Does that help?
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
When you refer to WindowsApplication4.exe.config
Is that the app.config ?
If so then where is it located?
On the client?
Thanks
|
|
|
|
|
Yes, WindowsApplication4.exe.config is the .config file for the Windows Forms application because the name of the application is WindowsApplication4.exe.
It is located in the same directory as WindowsApplication4.exe.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
ok, so now I will place my appsetting lines in the app.config in the clinet side.
|
|
|
|
|
That should work for you. Hope all turns out well. Happy coding.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
This is now clear.
The whole picture is that I have a client layer with the forms and now tha app.config file (for the connection string).
This client layer now connects to the business layer.
The business layer connects to the webservice and the webservice connects to the datalayer where the connection string is required.
How do I get the connectioinstring into the datalayer ?
Thanks
|
|
|
|
|
If I understand this correctly, you have the following architecture.
Client Application <-> Business Layer <- INTERNET -> Web Service <-> Data Layer
Windows Forms App Class Library Web Service Class Library The assemblies you have will use the following .config files:
- Client Application
- uses the <applicationName>.exe.config file for the client application
- Business Layer
- uses the <applicationName>.exe.config file for the client application
- Web service
- uses the web.config file for the Web service
- Data Layer
- uses the web.config file for the Web service
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you. I can now use the connection string inside my n-tier application.
|
|
|
|
|
I am happy to hear that. Happy coding!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I'm having a problem that is really driving me nuts. The setup heres a little complicated, so please bare with me:
I have a dll that contains a class, let's call it Manager, it's job is to search a directory, find other dlls and search them for classes that implement a certain interface, lets call it ICalc. It uses Assembly.LoadFrom to do this. It maintains a list of all the classes it finds that implement ICalc (in an arraylist of Type objects) and returns information about those classes (name and version) to the client program. Manager also has a method, let's call it GetCalc, that will instantiate and return an object that implements ICalc of a type requested by the caller. So far so good, and this seems to work okay.
Now I have another dll that contains a class, lets call it MyCalc that implements ICalc. When MyCalc is instantiated it must instantiate a few other objects that are related to its function. Among these are a class that contains some settings, lets call it MySettings. These settings are actually serialized to the disk and deserialized again by MyCalc using a static method in MySettings, something like:
public static MySettings LoadSettings(string filename)
Hopefully, you are still following this. Now, I create a simple C# console application to test this out and everything works fine - great!! But here's the problem, I'm trying to use LabView[^] as the client for the Manager Dll and this is were I run into trouble. For some reason the deserialization no longer works and chokes with an "Invalid Cast" exception. Basically the line:
MySettings setting = (MySettings) MyFormatter.Deserialize(MyStream)
Doesn't work.
Does anybody have any clue why this might be? I'm really confused by this. I have a guy (a LabView developer) waiting for my DLL and I can't figure this out!
|
|
|
|
|
No direct idea what happens but you could find out by checking the type before casting:
object o = MyFormatter.Deserialize(MyStream);
Console.WriteLine(o.GetType().Fullname);
This probably gives you a hint on whats going wrong.
|
|
|
|
|
Thanks for your reply. I have checked the type of the object returned from deserialization and it is the correct type as far as I can tell. I think the problem is rooted in how the assemblies are being loaded but I'm having a hard time getting to grips with it.
|
|
|
|
|
Hi all,
I have developed a dll in Win32. That dll finds the updated regions
of the desktop and then post these regions data to a C# application
using PostThreadMessage(). But problem is here i m not so much use to
with C# so i havent any idea how can i get it from the Application
message queue of my C# application.
Thanx
|
|
|
|
|
Has somebody used VTAPI ACTIVE X CONTROL in c# application ?
If "yes", can tells me how do it ?
Bye from Italy !
|
|
|
|
|
Is there a simple function to return a boolean value whether someone is connected to a network and/or the internet?
Thanks
Brent
|
|
|
|
|
u do one thing that on network(If it is LAN then) ping to each node.
and if it give response(means node) then it is connected else not
if u have difficulty that how to ping node in .net u can mail me
prakash_paghdal@gmail.com
|
|
|
|