473,396 Members | 2,052 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,396 software developers and data experts.

Problems using application state with custom classes

I am working with vb.net in a asp.net application.
I have created a config file in xml format. The goal is to
be able to change the config file without having to recompile the
entire
application.

So when the Application starts I read the xml file and place
each key-value pair into a Synchronized hash table. Now I want to
save this hashtable to Application state for quick access and also so
I don't have to open the config file a bizzilion times.

The problem comes in when I try to use the Application state from a
custom
class. I have created a custom vars class which holds the methods to
read the XML and build the hashtable, then save it the the application
state. But when I try to save anything into the application state from
this class I recieve a

"System.NullReferenceException: Object reference not set to an
instance of an object."

Error.

I have placed the building of the Application in the default
contructor and each time the constructor is called I get the error.

Here is the code...
Public Class _411Vars
Inherits System.Web.UI.Page

Private config As New Hashtable()

Sub New()
If Context.Application("vars") Is Nothing Then
Context.Application.Lock()
Context.Application("vars") = readXML()
Context.Application.UnLock()
config = CType(context.Application("vars"), Hashtable)
Else
config = CType(Context.Application("vars"), Hashtable)
End If
End Sub

Function c_dbPath() As String
Return CType(config("c_dbPath"), String)
End Function
......
.....
...
..

Now when I try to use the Application state in other web classes it
works just fine.
I get the null exception only when I try to save something to the
Application from a custom class.

I am sure I have missed something some where if anyone can lend a hand
that would be great.

I have read in places that the Application("") call must be in the Sub
Page_Load but I have been successful when using it in other
places??????

Any suggestions would be great

Thanks
Nov 17 '05 #1
0 1788

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

Similar topics

10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
3
by: Roshawn Dawson | last post by:
Hi, I'm having a bit of a problem using ASP.NET. I'm using VS.NET 2002 and I have .NET Framework 1.0 and 1.1 installed on my development machine. I've developed many web apps with no problems,...
0
by: ZR | last post by:
I am writing two applications which needs to (among other things) communicate through network, so one of them is a client and the other one is a server. I have used asynchronous socket examples...
8
by: Tomasz | last post by:
Hello Developers! I have an interesting problem using my custom MembershipProvider, RoleProvider and Forms Authentication. Both MembershipProvider and RoleProvider require session state, where...
5
by: Claudio M. E. Bastos Iorio | last post by:
Hi, anyone using VS2008 (final) on windows Vista? I have a problem. The ASP.NET web site administration tool on any site created by VS2008, running on Vista, is not working as it should. I can...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
5
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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.