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

Referencing web.config from another assembly

Hi,

I have a class in an assembly that references a value in web.config
like this:
<appSettings>
<add key="mykey" value="myvalue"/>
</appSettings>

string temp = System.Configuration.ConfigurationSettings.AppSett ings.Get("mykey");

This call works properly as is. However, if I call this class from
another assembly (by placing the assembly containing this class in the
calling assembly's references directory), the call fails with a
NullReferenceException. I can reference everything else in the
imported assembly, without any trouble, as you might expect.
It is almost as if an imported assembly can not read its own
web.config file.

I can abstract the values from out of the web.config and place them in
an external xml file, but I would rather not do this. I would prefer
to use the web.config. Any suggestions?

Thanks in advance,
Torrance S.

Env:
..NET IDE 2002 (v 7.0.9466)
..NET Framework 1.0 (v. 1.0.3705)
C# Web Project on W2k Pro
Nov 15 '05 #1
2 3168
You have a separate assembly in the same directory, but the separate
assembly is a separate application. The web.config is specific to the
application. The web.config file is however, simply an XML file, so you
should be able to parse it easily enough, though there is probably a
permissions issue involved. Would it not be easier simply to keep your keys
in a separate XML file and have both assemblies access the XML file?

Pete

"Torrance S." <gi*******@yahoo.com> wrote in message
news:ca**************************@posting.google.c om...
Hi,

I have a class in an assembly that references a value in web.config
like this:
<appSettings>
<add key="mykey" value="myvalue"/>
</appSettings>

string temp = System.Configuration.ConfigurationSettings.AppSett ings.Get("mykey");
This call works properly as is. However, if I call this class from
another assembly (by placing the assembly containing this class in the
calling assembly's references directory), the call fails with a
NullReferenceException. I can reference everything else in the
imported assembly, without any trouble, as you might expect.
It is almost as if an imported assembly can not read its own
web.config file.

I can abstract the values from out of the web.config and place them in
an external xml file, but I would rather not do this. I would prefer
to use the web.config. Any suggestions?

Thanks in advance,
Torrance S.

Env:
.NET IDE 2002 (v 7.0.9466)
.NET Framework 1.0 (v. 1.0.3705)
C# Web Project on W2k Pro

Nov 15 '05 #2
The "calling assembly"'s web.config will be used.

System.Configuration.ConfigurationSettings.AppSett ings.Get("mykey") will
return "myke" from the current APPLICATION's config file. If this is a web
page, then it will use the current web app's config file (web.config).

The referenced assembly has no notion of its "own" configuration file. When
you reference it from an app, that's the application it belongs to.
"Torrance S." <gi*******@yahoo.com> wrote in message
news:ca**************************@posting.google.c om...
Hi,

I have a class in an assembly that references a value in web.config
like this:
<appSettings>
<add key="mykey" value="myvalue"/>
</appSettings>

string temp = System.Configuration.ConfigurationSettings.AppSett ings.Get("mykey");
This call works properly as is. However, if I call this class from
another assembly (by placing the assembly containing this class in the
calling assembly's references directory), the call fails with a
NullReferenceException. I can reference everything else in the
imported assembly, without any trouble, as you might expect.
It is almost as if an imported assembly can not read its own
web.config file.

I can abstract the values from out of the web.config and place them in
an external xml file, but I would rather not do this. I would prefer
to use the web.config. Any suggestions?

Thanks in advance,
Torrance S.

Env:
.NET IDE 2002 (v 7.0.9466)
.NET Framework 1.0 (v. 1.0.3705)
C# Web Project on W2k Pro

Nov 15 '05 #3

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

Similar topics

1
by: José Joye | last post by:
Hello, I have an assembly that is used by a VB6 application. This application can be a normal exe or an ActiveX (called through CCW). My assembly needs to get extra info from a config file. In...
2
by: Suresh Gladstone | last post by:
Hi, This is a bit with versioning and installation of the .NET dlls. I want to perform the following, 1. A third party application will be invoking my .NET dll through COM interop . For this I...
12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
1
by: Brent | last post by:
I have strong named an assembly and installed it into the GAC. I have copied the same assembly to a local folder and made reference to it and set 'Copy Local' to false in the VS IDE, so that my...
5
by: John | last post by:
Hi I am trying to get web reference to my first (!) web service which is on a remote host. I am getting the following error; Server Error in '/' Application. Runtime Error Description: An...
6
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the...
3
by: prabu.girirajan | last post by:
Hi, I have a web application which internally calls certain web methods of a web service. This web service has a interop to ATL COM Component and that ATL component calls a .NET assembly. I would...
5
by: Keith | last post by:
Hello all, I have a C# Windows Forms app. It is in namespace App.GUI. It builds to Nav.exe. I have entered an application level setting using the designer. Its type is string, name is "FOO"...
7
by: Wiebe Tijsma | last post by:
Hi, I'm running a web application application using the Microsoft.Interop.Security.AzRoles version 1.2.0.0 in the GAC. After an upgrade to Vista, I also have a version 2.0.0.0 in the GAC. I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.