>>>>Hi all,
>>>>
>>>>I have a web application project and a problem with visibiltiy to the Global.asax class.
>>>>
>>>>In my Global.asax I have a public variable such as this:
>>>>
>>>>
>>>>
>>>>Public Class Global_asax
>>>> Inherits System.Web.HttpApplication
>>>>
>>>> Public Shared MyString As String
>>>> ... All the other event stuff
>>>>End Class
>>>>
>>>>
>>>>I am setting the value of the variale in the Application_Start Event
>>>>
>>>>Now in the same web project I have a class with a namespace of
>>>>Namespace Main.Managers
>>>>the full namespace would be the project root plus Main.Managers so
>>>>MyApplication.Web.Main.Managers
>>>>
>>>>Inside this class I am trying to reference the Shared (static)variable such as this:
>>>>
>>>>
>>>>
>>>>If (MyString = "SomeValue") Then
>>>>
>>>>
>>>>What I get is an error indicating MyString is not declared.
>>>>What am I doing wrong here as I expected the Shared variable to be available in the Global.asax file.
>>>
>>>It is, but it can't resolve the full namespace based off your imported namespaces. Try something like:
>>>
>>>
>>>If (Global_asax.MyString = "SomeValue) Then
>>>
>>
>>The MyString is shared (static) so when I add that, I get:
>>Access of a shared member,... through an instance; expression will not be evaluated.
>
>Ah, it must be resolving to the local (instance) of it and not the class itself. Try the full namespace path to the class, ex. something like: MyApplication.Web.Global_asax.MyString
I feel bad in that I may have led you down a wrong path. I tried to make my post generic and changed it enough that it isn't quite the same as my problem. I just tried your last suggestion and it didn't work so I put a test shared string in my Global.asax file and it did work. Darn!
What I actually have is a class type not a string. And what seems to be the difference is that it isn't initialized until the application_start event handler runs.
Here is what I tried based on your solution:
In the Global.asax file:
Public Shared MyString As String = "AString"
And when I access it outside as this:
MyApplication.Web.Global_asax.MyString
it works ok.
but what I have in Global.asax is this:
Public Shared App As MyApplication.Web.Main.WebApp
And in the Application_Start Event handler
App = New MyApplication.Web.Main.WebApp()
When I try to access this member with the full path as suggested I get
"Access of a shared member,... through an instance; expression will not be evaluated."
Therefore is it because the Application_Start event handler which initialized the member may not be available yet since it is part of the instance of Global.asax?
Thanks
Tim
Timothy Bryan