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.NullRefe renceException: 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:
[NullReferenceEx ception: Object reference not set to an instance of an object.]
anmar.SharpWebM ail.UI.Global.g etEffectiveCult ure(CultureInfo ci) in global.cs:95
anmar.SharpWebM ail.UI.Global.P arseCultures(Ob ject[] cultures) in global.cs:180
anmar.SharpWebM ail.UI.Global.P arseCultures(Ob ject[] cultures) in global.cs:177
anmar.SharpWebM ail.UI.Global.A pplication_Acqu ireRequestState () in global.cs:50
[TargetInvocatio nException: Exception has been thrown by the target of an invocation.]
System.RuntimeM ethodHandle._In vokeMethodFast( Object target, Object[] arguments, SignatureStruct & sig, MethodAttribute s methodAttribute s, RuntimeTypeHand le typeOwner) +0
System.RuntimeM ethodHandle.Inv okeMethodFast(O bject target, Object[] arguments, Signature sig, MethodAttribute s methodAttribute s, RuntimeTypeHand le typeOwner) +72
System.Reflecti on.RuntimeMetho dInfo.Invoke(Ob ject obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityC hecks) +296
System.Reflecti on.RuntimeMetho dInfo.Invoke(Ob ject obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.Util .ArglessEventHa ndlerProxy.Call back(Object sender, EventArgs e) +41
System.Web.Sync EventExecutionS tep.System.Web. HttpApplication .IExecutionStep .Execute() +92
System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean& completedSynchr onously) +64
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.42; ASP.NET Version:2.0.507 27.210
The code in global.cs file is
using System;
[assembly: log4net.Config. XmlConfigurator ()]
namespace anmar.SharpWebM ail.UI
{
public class Global : System.Web.Http Application {
protected static log4net.ILog log = log4net.LogMana ger.GetLogger(S ystem.Reflectio n.MethodBase.Ge tCurrentMethod( ).DeclaringType );
protected static System.Globaliz ation.CultureIn fo invariant = null;
protected static System.Collecti ons.Specialized .HybridDictiona ry availablecultur es;
protected static System.Resource s.ResourceManag er resources = null;public void Application_Sta rt ( System.Object sender, System.EventArg s args ) {
initConfig();
}
public void Application_Err or ( System.Object sender, System.EventArg s args ) {
if ( log.IsErrorEnab led ) log.Error ( "Application_Er ror", Server.GetLastE rror() );
#if !DEBUG
Server.ClearErr or();
#endif
}
public virtual void Application_Acq uireRequestStat e() {
// For each request initialize the culture values with the
// user language as specified by the browser.
System.String[] lang = new System.String[]{Request.QueryS tring["lang"], null};
if ( this.Context.Se ssion!=null && this.Session["effectivecultu re"]!=null )
lang[1] = this.Session["effectivecultu re"].ToString();
System.Globaliz ation.CultureIn fo culture = this.ParseCultu res ( lang, Request.UserLan guages );
if ( culture==null )
culture = invariant;
if ( culture!=null && lang[1]!=culture.Name ) {
if ( !culture.IsNeut ralCulture )
System.Threadin g.Thread.Curren tThread.Current Culture = culture;
System.Threadin g.Thread.Curren tThread.Current UICulture = culture;
if ( this.Context.Se ssion!=null ) {
Session["resources"] = resources.GetRe sourceSet(cultu re, true, true);
Session["effectivecultu re"] = getEffectiveCul ture(culture);
}
}
}
public void Session_Start ( System.Object sender, System.EventArg s args ) {
// Inbox Object
anmar.SharpWebM ail.CTNInbox inbox = new anmar.SharpWebM ail.CTNInbox();
if ( Application["sharpwebma il/read/inbox/sort"]!=null )
inbox.SortExpre ssion = Application["sharpwebma il/read/inbox/sort"].ToString();
Session["inbox"] = inbox;
Session["sharpwebma il/read/message/temppath"] = parseTempFolder (Application["sharpwebma il/read/message/temppath"], Session.Session ID);Session["sharpwebma il/send/message/temppath"] = parseTempFolder (Application["sharpwebma il/send/message/temppath"], Session.Session ID);
}
public void Session_End ( System.Object sender, System.EventArg s args ) {
// Clean up temp files
cleanTempFolder (Session["sharpwebma il/read/message/temppath"]);cleanTempFold er(Session["sharpwebma il/send/message/temppath"]);
}
private void cleanTempFolder ( System.Object value ) {
try {
if ( value!=null ) {
System.IO.Direc toryInfo dir = new System.IO.Direc toryInfo (value.ToString ());
if ( dir.Exists )
dir.Delete(true );dir=null;
}
} catch( System.Exceptio n e ) {
if ( log.IsErrorEnab led )log.Error("Err or cleanling up dir", e);
}
}
public System.String getEffectiveCul ture ( System.Globaliz ation.CultureIn fo ci ) {
System.String culture = System.String.E mpty;
if ( !availablecultu res.Contains(ci .Name) && !ci.Equals(Syst em.Globalizatio n.CultureInfo.I nvariantCulture ) ) culture = this.getEffecti veCulture(ci.Pa rent);
else
culture = ci.Name;
return culture;
}
private void initConfig () {
Application["product"] = System.Reflecti on.Assembly.Get ExecutingAssemb ly().GetName(). Name;
Application["version"] = System.Reflecti on.Assembly.Get ExecutingAssemb ly().GetName(). Version;
resources = new System.Resource s.ResourceManag er("SharpWebMai l", System.Reflecti on.Assembly.Get ExecutingAssemb ly());
Application["resources"] = resources;
System.Collecti ons.Hashtable config = (System.Collect ions.Hashtable) System.Configur ation.Configura tionSettings.Ge tConfig("sharpw ebmail");
foreach ( System.Collecti ons.DictionaryE ntry item in config ) {
Application.Add (item.Key.ToStr ing(), item.Value);
}
config = null;
if ( Application["sharpwebma il/send/addressbook"]!=null ) {
Application["sharpwebma il/general/addressbooks"] = true;
}
if ( (bool)Applicati on["sharpwebma il/read/message/useserverencodi ng"] ) {anmar.SharpMim eTools.SharpMim eHeader.Encodin gDefault = System.Text.Enc oding.Default;
}
TestAvailableCu ltures();
System.Collecti ons.SortedList availablecultur es_values = new System.Collecti ons.SortedList( availablecultur es.Count);forea ch ( System.Collecti ons.DictionaryE ntry item in availablecultur es ) {
availablecultur es_values.Add(i tem.Value, item.Key);
}
Application["AvailableCultu res"] = availablecultur es_values;
initInvariantCu lture();
Application["sharpwebma il/read/message/temppath"] = parseTempFolder (Server.MapPath ("/"), Application["sharpwebma il/read/message/temppath"]);Application["sharpwebma il/send/message/temppath"] = parseTempFolder (Server.MapPath ("/"), Application["sharpwebma il/send/message/temppath"]);
}
private void initInvariantCu lture() {
if ( invariant==null )
ParseInvariant( Application["sharpwebma il/general/default_lang"].ToString());
if ( invariant==null )
ParseInvariant( "en");
if ( invariant==null ) { invariant = System.Globaliz ation.CultureIn fo.InvariantCul ture;
// Set the first available culture as the default one
if ( availablecultur es.Count>0 ) {
System.Collecti ons.IDictionary Enumerator enumerator = availablecultur es.GetEnumerato r();
if ( enumerator.Move Next() )
invariant = ParseCultureSpe cific((string)e numerator.Key);
enumerator = null;
}
}
}
private System.Globaliz ation.CultureIn fo ParseCulture ( System.String culturename ) {
System.Globaliz ation.CultureIn fo culture = null;
try {
culture = new System.Globaliz ation.CultureIn fo(culturename) ;
} catch ( System.Exceptio n e ) {
if ( log.IsErrorEnab led )
log.Error("Erro r parsing culture", e);
}
return culture;
}
private System.Globaliz ation.CultureIn fo ParseCultureSpe cific ( System.String culturename ) {
if ( culturename.Ind exOf(';')>0 )
culturename = culturename.Rem ove(culturename .IndexOf(';'), culturename.Len gth - culturename.Ind exOf(';'));
System.Globaliz ation.CultureIn fo culture = null;
try {
culture = System.Globaliz ation.CultureIn fo.CreateSpecif icCulture(cultu rename);
if ( culturename.Len gth>0 && culture.Equals( System.Globaliz ation.CultureIn fo.InvariantCul ture) )
culture = ParseCulture(cu lturename);
} catch ( System.Exceptio n e ) {
if ( log.IsErrorEnab led )
log.Error("Erro r parsing specific culture", e);
}
return culture;
}
private System.Globaliz ation.CultureIn fo ParseCultures ( params System.Object[] cultures ) {
System.Globaliz ation.CultureIn fo culture = null;
if ( cultures!=null ) {
foreach ( System.Object item in cultures ) {
if ( item==null )
continue;
if ( item is System.Array )
culture = ParseCultures(i tem as System.Object[]);
else if ( item is System.String )
culture = this.ParseCultu reSpecific(item .ToString());
if ( culture!=null && getEffectiveCul ture(culture).L ength>0 ) break;
else
culture = null;
}
}
return culture;
}
private void ParseInvariant ( System.String culture ) {
invariant = ParseCulture(cu lture);
if ( invariant!=null ) {
culture = getEffectiveCul ture(invariant) ;
if ( culture.Length> 0 )
invariant = ParseCultureSpe cific(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.E mpty) && !sufix.Equals(S ystem.String.Em pty) ) return System.IO.Path. Combine (prefix.ToStrin g(), sufix.ToString( ));
else
return null;
}
private void TestAvailableCu ltures() {
availablecultur es = new System.Collecti ons.Specialized .HybridDictiona ry();
foreach ( System.Globaliz ation.CultureIn fo item in System.Globaliz ation.CultureIn fo.GetCultures( System.Globaliz ation.CultureTy pes.AllCultures ) ) {if ( !item.Equals(Sy stem.Globalizat ion.CultureInfo .InvariantCultu re) && !availablecultu res.Contains(it em.Name) && resources.GetRe sourceSet(item, true, false)!=null )
availablecultur es.Add(item.Nam e, item.EnglishNam e);
}
}
}
}
What is the reason for this error? How to solve it? I am using VS2005 ASP.net 2.0