473,396 Members | 1,748 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.

Error in global.cs file

In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file.



Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
anmar.SharpWebMail.UI.Global.getEffectiveCulture(C ultureInfo ci) in global.cs:95
anmar.SharpWebMail.UI.Global.ParseCultures(Object[] cultures) in global.cs:180
anmar.SharpWebMail.UI.Global.ParseCultures(Object[] cultures) in global.cs:177
anmar.SharpWebMail.UI.Global.Application_AcquireRe questState() in global.cs:50

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Objec t target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +296
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.Util.ArglessEventHandlerProxy.Callback( Object sender, EventArgs e) +41
System.Web.SyncEventExecutionStep.System.Web.HttpA pplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +64




--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210



The code in global.cs file is

using System;
[assembly: log4net.Config.XmlConfigurator()]

namespace anmar.SharpWebMail.UI
{

public class Global : System.Web.HttpApplication {
protected static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.Met hodBase.GetCurrentMethod().DeclaringType);

protected static System.Globalization.CultureInfo invariant = null;
protected static System.Collections.Specialized.HybridDictionary availablecultures;

protected static System.Resources.ResourceManager resources = null;public void Application_Start ( System.Object sender, System.EventArgs args ) {
initConfig();

}

public void Application_Error ( System.Object sender, System.EventArgs args ) {
if ( log.IsErrorEnabled ) log.Error ( "Application_Error", Server.GetLastError() );

#if !DEBUG
Server.ClearError();

#endif

}

public virtual void Application_AcquireRequestState() {
// For each request initialize the culture values with the

// user language as specified by the browser.

System.String[] lang = new System.String[]{Request.QueryString["lang"], null};
if ( this.Context.Session!=null && this.Session["effectiveculture"]!=null )

lang[1] = this.Session["effectiveculture"].ToString();
System.Globalization.CultureInfo culture = this.ParseCultures ( lang, Request.UserLanguages );

if ( culture==null )
culture = invariant;

if ( culture!=null && lang[1]!=culture.Name ) {
if ( !culture.IsNeutralCulture )

System.Threading.Thread.CurrentThread.CurrentCultu re = culture;
System.Threading.Thread.CurrentThread.CurrentUICul ture = culture;

if ( this.Context.Session!=null ) {
Session["resources"] = resources.GetResourceSet(culture, true, true);

Session["effectiveculture"] = getEffectiveCulture(culture);
}

}

}

public void Session_Start ( System.Object sender, System.EventArgs args ) {
// Inbox Object

anmar.SharpWebMail.CTNInbox inbox = new anmar.SharpWebMail.CTNInbox();
if ( Application["sharpwebmail/read/inbox/sort"]!=null )

inbox.SortExpression = Application["sharpwebmail/read/inbox/sort"].ToString();
Session["inbox"] = inbox;

Session["sharpwebmail/read/message/temppath"] = parseTempFolder(Application["sharpwebmail/read/message/temppath"], Session.SessionID);Session["sharpwebmail/send/message/temppath"] = parseTempFolder(Application["sharpwebmail/send/message/temppath"], Session.SessionID);
}

public void Session_End ( System.Object sender, System.EventArgs args ) {
// Clean up temp files

cleanTempFolder(Session["sharpwebmail/read/message/temppath"]);cleanTempFolder(Session["sharpwebmail/send/message/temppath"]);
}

private void cleanTempFolder ( System.Object value ) {

try {
if ( value!=null ) {

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo (value.ToString());
if ( dir.Exists )

dir.Delete(true);dir=null;
}

} catch( System.Exception e ) {

if ( log.IsErrorEnabled )log.Error("Error cleanling up dir", e);
}

}

public System.String getEffectiveCulture ( System.Globalization.CultureInfo ci ) {
System.String culture = System.String.Empty;

if ( !availablecultures.Contains(ci.Name) && !ci.Equals(System.Globalization.CultureInfo.Invari antCulture) ) culture = this.getEffectiveCulture(ci.Parent);
else

culture = ci.Name;

return culture;
}

private void initConfig () {
Application["product"] = System.Reflection.Assembly.GetExecutingAssembly(). GetName().Name;

Application["version"] = System.Reflection.Assembly.GetExecutingAssembly(). GetName().Version;
resources = new System.Resources.ResourceManager("SharpWebMail", System.Reflection.Assembly.GetExecutingAssembly()) ;

Application["resources"] = resources;
System.Collections.Hashtable config = (System.Collections.Hashtable)System.Configuration .ConfigurationSettings.GetConfig("sharpwebmail");

foreach ( System.Collections.DictionaryEntry item in config ) {
Application.Add(item.Key.ToString(), item.Value);

}

config = null;
if ( Application["sharpwebmail/send/addressbook"]!=null ) {

Application["sharpwebmail/general/addressbooks"] = true;
}

if ( (bool)Application["sharpwebmail/read/message/useserverencoding"] ) {anmar.SharpMimeTools.SharpMimeHeader.EncodingDefa ult = System.Text.Encoding.Default;
}

TestAvailableCultures();

System.Collections.SortedList availablecultures_values = new System.Collections.SortedList(availablecultures.Co unt);foreach ( System.Collections.DictionaryEntry item in availablecultures ) {
availablecultures_values.Add(item.Value, item.Key);

}

Application["AvailableCultures"] = availablecultures_values;
initInvariantCulture();

Application["sharpwebmail/read/message/temppath"] = parseTempFolder(Server.MapPath("/"), Application["sharpwebmail/read/message/temppath"]);Application["sharpwebmail/send/message/temppath"] = parseTempFolder(Server.MapPath("/"), Application["sharpwebmail/send/message/temppath"]);
}

private void initInvariantCulture() {

if ( invariant==null )
ParseInvariant(Application["sharpwebmail/general/default_lang"].ToString());

if ( invariant==null )
ParseInvariant("en");

if ( invariant==null ) { invariant = System.Globalization.CultureInfo.InvariantCulture;
// Set the first available culture as the default one

if ( availablecultures.Count>0 ) {
System.Collections.IDictionaryEnumerator enumerator = availablecultures.GetEnumerator();

if ( enumerator.MoveNext() )
invariant = ParseCultureSpecific((string)enumerator.Key);

enumerator = null;
}

}

}

private System.Globalization.CultureInfo ParseCulture ( System.String culturename ) {
System.Globalization.CultureInfo culture = null;

try {
culture = new System.Globalization.CultureInfo(culturename);

} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )

log.Error("Error parsing culture", e);
}

return culture;
}

private System.Globalization.CultureInfo ParseCultureSpecific ( System.String culturename ) {
if ( culturename.IndexOf(';')>0 )

culturename = culturename.Remove(culturename.IndexOf(';'), culturename.Length - culturename.IndexOf(';'));
System.Globalization.CultureInfo culture = null;

try {
culture = System.Globalization.CultureInfo.CreateSpecificCul ture(culturename);

if ( culturename.Length>0 && culture.Equals(System.Globalization.CultureInfo.In variantCulture) )
culture = ParseCulture(culturename);

} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )

log.Error("Error parsing specific culture", e);
}

return culture;
}

private System.Globalization.CultureInfo ParseCultures ( params System.Object[] cultures ) {
System.Globalization.CultureInfo culture = null;

if ( cultures!=null ) {
foreach ( System.Object item in cultures ) {

if ( item==null )
continue;

if ( item is System.Array )
culture = ParseCultures(item as System.Object[]);

else if ( item is System.String )
culture = this.ParseCultureSpecific(item.ToString());

if ( culture!=null && getEffectiveCulture(culture).Length>0 ) break;
else

culture = null;
}

}

return culture;
}

private void ParseInvariant ( System.String culture ) {
invariant = ParseCulture(culture);

if ( invariant!=null ) {
culture = getEffectiveCulture(invariant);

if ( culture.Length>0 )
invariant = ParseCultureSpecific(culture);

else

invariant = null;
}

}

private System.String parseTempFolder( System.Object prefix, System.Object sufix ) {
// Temp folder

if ( prefix!=null && sufix!=null && !prefix.Equals(System.String.Empty) && !sufix.Equals(System.String.Empty) ) return System.IO.Path.Combine (prefix.ToString(), sufix.ToString());
else

return null;
}

private void TestAvailableCultures() {
availablecultures = new System.Collections.Specialized.HybridDictionary();

foreach ( System.Globalization.CultureInfo item in System.Globalization.CultureInfo.GetCultures( System.Globalization.CultureTypes.AllCultures) ) {if ( !item.Equals(System.Globalization.CultureInfo.Inva riantCulture) && !availablecultures.Contains(item.Name) && resources.GetResourceSet(item, true, false)!=null )
availablecultures.Add(item.Name, item.EnglishName);

}

}

}

}

What is the reason for this error? How to solve it? I am using VS2005 ASP.net 2.0
Aug 7 '07 #1
2 2306
kenobewan
4,871 Expert 4TB
[NullReferenceException: Object reference not set to an instance of an object.]
anmar.SharpWebMail.UI.Global.getEffectiveCulture(C ultureInfo ci) in global.cs:95
anmar.SharpWebMail.UI.Global.ParseCultures(Object[] cultures) in global.cs:180
anmar.SharpWebMail.UI.Global.ParseCultures(Object[] cultures) in global.cs:177
anmar.SharpWebMail.UI.Global.Application_AcquireRe questState() in global.cs:50
This tells you where to look. HTH.
Aug 7 '07 #2
Plater
7,872 Expert 4TB
It also appears that right around that line, you are not checking to make sure your "lang" variable contains valid information and are trying to do proccessing on it that is failing and setting an object to NULL, giving you the null reference exception when you try to use it.
Aug 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
14
by: Roland Hall | last post by:
Since I'm not getting any response from the community, I'm reposting this under my managed account. I've turned my web.config friendly error messages off and it may be easier to view what I'm...
8
by: Brett Romero | last post by:
I get this error when I try to run my ASP.NET app on our server: Server Error in '/' Application. -------------------------------------------------------------------------------- Parser Error...
8
by: jcrouse | last post by:
I am using the following code to trap errors in a sub routine: Try Executable code Catch ex As Exception Dim strInputE As String = Application.StartupPath & "\Error.txt" Dim srE As...
1
by: PaulieS | last post by:
Hi all. Am migrating a customer from IIS5 on W2K server to IIS6 on W2K3. Zipped all the websites and unzipped them to the identical locations on new server. Used IISMT to migrate metabase. ...
7
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int w; int n,m; //void main(); char check(int n,int m,char ch); void cash(int n,int m,char ch);
11
by: xenoix | last post by:
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource. My PC :- Visual Studio 2005 .NET Framework 2 Component Factory Krypton...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.