473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error in global.cs file

8 New Member
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
Aug 7 '07 #1
2 2336
kenobewan
4,871 Recognized Expert Specialist
[NullReferenceEx ception: Object reference not set to an instance of an object.]
anmar.SharpWebM ail.UI.Global.g etEffectiveCult ure(C ultureInfo 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 ireRe questState() in global.cs:50
This tells you where to look. HTH.
Aug 7 '07 #2
Plater
7,872 Recognized Expert Expert
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
5038
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 double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
2
6118
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 #80 and line # 38 are the first line offenders. --> --> -->
13
6615
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
2399
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 experiencing than try to translate it. Here's the error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="netfraud.us.Global" %>
8
1908
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 Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
8
1790
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 StreamWriter = File.AppendText(strInputE) srE.WriteLine(vbCr) srE.WriteLine(vbCr) srE.WriteLine(DateTime.Now)
1
2766
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. Got this error when I tried to run a very basic page... code:
7
3319
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
5592
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 Tools Test PC :- .Net Framework 2
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.