Null-Reference Exception at loading CuteChat time

Last post 02-21-2007, 2:47 AM by knoepdan. 7 replies.
Sort Posts: Previous Next
  •  02-02-2007, 12:03 PM 26383

    Null-Reference Exception at loading CuteChat time

    Hi
     
    In our web application, we use the integrated version of CuteChat (version 3.1.1) for ASP.NET 2.0.  We have encountered a strange problem. At CuteChat-startup (when loading is displayed) a Null Reference exception message popped up as java sript alert box. The same Null reference exception was logged as well.  Apart from this, nothing abnormal seemed to happen, the normal cuteChat user list was displayed. However, a short time afterwards a message was displayed, that the user is not allowed to access the application as anonymous user and the origninal user list disappeared. After a relogin, the same thing happened, the normal user list was displayed (for about 5 seconds) and soon afterwards the same message appeared. The same applied for every user that tried to log in from then on. It seem that  the CuteChat application cache was not initialised properly and this cause CuteChat cause troubles. Only a complete restart of the application (iisreset) helped.
     
    We could not really reproduce this error, but we already had this twice. It seems that this happens at startup, when clicking somewhere else on the website, which causes the frameset to change. The Cute Chat frame however, is not affected by this.
     
    Can you help us with this problem or tell us when a fix will be available. This problem has got quite an impact as the whole application has to be restarted to make CuteChat work again.
     
    Thanks in advance for any answer.
     
    Greetings
     
    Daniel
  •  02-02-2007, 2:01 PM 26388 in reply to 26383

    Re: Null-Reference Exception at loading CuteChat time

    Daniel,
     
    I don't have a directly answer or fix for your problems.
     
    I think for some reasons UserIdentity is lost. When you debug the problem, please focus on the following interface.
     

    Implement IHttpApplicationUserAdapter interface and Let CuteChat know who has logged in the website


    In this step, you need to implement one simple method:

    //Retrieves the unique identity of the current user
    public CuteSoft.Chat.UserIdentity GetUserIdentity()

    Code Example

    public string GetUserUniqueName()

    {    
         if (Context.User.Identity.IsAuthenticated)
            return Context.User.Identity.Name; 
        return null;

    }

    public CuteSoft.Chat.UserIdentity GetUserIdentity()

    {

        string uniquename = GetUserUniqueName();

        if (uniquename == null)

        {

            return CuteSoft.Chat.UserIdentity.CreateNull();

        }

        CuteSoft.Chat.UserIdentity identity = new CuteSoft.Chat.UserIdentity(uniquename, null, Request.UserHostAddress);

        return identity;

    }
     

    Integration with an existing user membership database (C#)


    Before you get started, you need to understand the 'UniqueName' in CuteChat. In CuteChat, UniqueName means the unique data of your user. Depending on how you implement the user system, in some systems, the best unique data is the user ID; in some system, every user have a unique account name; some systems like MSN, the unique data is the user email. It could be string(username, email), integer(user ID) or GUID.
     
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  02-14-2007, 11:27 AM 26706 in reply to 26388

    Re: Null-Reference Exception at loading CuteChat time

     
    Hi
     
    Thanks for your reply. I have adapted our implementation of the IHttpApplicationUserAdapter interface so all exceptions are caught.  This is how we implemented it:

    public
    class CustomUserAdapter : CuteSoft.Chat.UserAdapter {

       public override string GetUserUniqueName( HttpContext context ) {

          try{

             FrameworkUserDTO currentUser = UserInfoProvider.GetFrameworkUser();

             return currentUser.Id.ToString();

          }catch{

             return null;

          }   

       }

    }
     
     
    Unfortunately, even after this implementation we experience the same problem. After a deployment or when the worker process is recycled the CuteChat application sometimes has trouble loading or initialising. If this has happened once, CuteChat does not recover until the next IIS restart. In a productive environment this is a big problem.  It really seems to me that this is a problem of initialization. When the initialization phase is over without any errors, CuteChat works fine. However, if an exception occurs, CuteChat cannot recover. The exception that is written to the log file is the following:  
     
    <Exception>
      <Description>An exception of type 'System.Web.HttpUnhandledException' occurred and was caught.</Description>
      <DateTime>2007-02-14 17:10:11Z</DateTime>
      <ExceptionType>System.Web.HttpUnhandledException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</ExceptionType>
      <Message>Exception of type 'System.Web.HttpUnhandledException' was thrown.</Message>
      <Source>System.Web</Source>
      <HelpLink />
      <Property name="ErrorCode">-2147467259</Property>
      <Property name="Data">System.Collections.ListDictionaryInternal</Property>
      <Property name="TargetSite">Boolean HandleError(System.Exception)</Property>
      <StackTrace>   at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.cutesoft_client_cutechat_im_chatform_aspx.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)</StackTrace>
      <additionalInfo>
        <info name="MachineName" value="PRIME-DEV" />
        <info name="TimeStamp" value="14.02.2007 16:10:11" />
        <info name="FullName" value="EnterpriseLibrary.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
        <info name="AppDomainName" value="/LM/W3SVC/1292483567/Root-2-128159429884466188" />
        <info name="ThreadIdentity" value="" />
        <info name="WindowsIdentity" value="NT AUTHORITY\NETWORK SERVICE" />
      </additionalInfo>
      <InnerException>
        <ExceptionType>System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
        <Message>Object reference not set to an instance of an object.</Message>
        <Source>CuteSoft.Chat</Source>
        <HelpLink />
        <Property name="Data">System.Collections.ListDictionaryInternal</Property>
        <Property name="TargetSite">System.Collections.Specialized.NameValueCollection GetConfigs()</Property>
        <StackTrace>   at CuteSoft.Chat.ChatDataManager.GetConfigs()
       at CuteSoft.Chat.ChatDataManager.GetConfig(String configname)
       at CuteSoft.Chat.ChatApiImpl.DoGetConfig(String name)
       at CuteSoft.Chat.ChatApiImpl.GetConfig(String name)
       at CuteSoft.Chat.ChatWebUtility.GetUserAdapter()
       at CuteSoft.Chat.ChatWebUtility.get_CurrentIdentity()
       at CuteSoft.Chat.Impl.ResourceContext.LoadResources(CultureInfo ci)
       at CuteSoft.Chat.UI.ChatPageBase.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</StackTrace>
      </InnerException>
    </Exception>
    <env_info>
    <entry name="request.URL"><![CDATA[/CuteSoft_Client/CuteChat/IM_ChatForm.Aspx?UserId=17&DisplayName=J%FCrg%20Balmeruss%20-%20SWI&_t1171469411010]]></entry>
    <entry name="request.method"><![CDATA[GET]]></entry>
    <entry name="request.path"><![CDATA[/CuteSoft_Client/CuteChat/IM_ChatForm.Aspx]]></entry>
    <entry name="request.ePrime.name"><![CDATA[]]></entry>
    <entry name="request.params"><![CDATA[UserId=17;DisplayName=Jrg Balmeruss - SWI;=_t1171469411010;]]></entry>
    <entry name="lastSqlStatement"><![CDATA[No sql statements available]]></entry>
    <entry name="request.cookies"><![CDATA[ASP.NET_SessionId=fohxws45d10m1bmul4cweg45;.LOGINUSER=D2AB01301A21E19C472F42FA0DCBC7B73DA4D9137AA3C027E2D669A2CA64E4851DC9244360E5802736D44860F28B97F1E14E8FE7C760D20E85346B774C6CCA3D;year_dropdown_preset=2007;body_dropdown_preset=3;advanced_history_body_dropdown_preset=2;CuteChatIMMainForm=Here;]]></entry>
    <entry name="windows.identity"><![CDATA[NT AUTHORITY\NETWORK SERVICE]]></entry>
    <entry name="user.Agent"><![CDATA[Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)]]></entry>
    <entry name="user.HostAddress"><![CDATA[192.168.2.145]]></entry>
    <entry name="user.HostName"><![CDATA[192.168.2.145]]></entry>
    <entry name="browser.JScriptVersion"><![CDATA[5.6]]></entry>
    <entry name="browser.JavaApplets"><![CDATA[True]]></entry>
    <entry name="browser.MajorVersion"><![CDATADevil]></entry>
    <entry name="browser.MinorVersion"><![CDATA[0]]></entry>
    <entry name="application.version"><![CDATA[4.07.00]]></entry>
    </env_info>
     
     
    Please have a look at it as we cannot go online like this.
     
    Thanks
     
    Daniel
     
  •  02-15-2007, 4:27 AM 26725 in reply to 26706

    Re: Null-Reference Exception at loading CuteChat time

     
     
    Hi
     
    I found a way to reproduce the error:
     
    1. i open our webapplication with the integrated version of CuteChat 3.1.1 in a webbrowser
    2. i restart IIS and leave the browser with cuteChat running open
    3. i open a new browser and connect to our website.
             -> CuteChat will not load !!!!
     
     
    I guess when leaving the browser open, CuteChat  still sends requests to the server. However, after an IIS restart, CuteChat must first initialize properly. However, as CuteChat (from the browser i opened first) still sends requests, an exception is thrown while initializing and CuteChat cannot start up properly. As a result of this failed initialization, CuteChat no longer works and IIS has to be restarted.
     
    We appreciate any help. We really have to get this running.
     
    Thanks in advance..
     
    Daniel 
  •  02-16-2007, 10:36 PM 26760 in reply to 26725

    Re: Null-Reference Exception at loading CuteChat time

    Daniel,
     
    Can you download the standalone version and try it?
     
     
    If you can not find a way to reproduce this issue with the standalone version, the problem maybe is caused by your integration project.
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  02-19-2007, 5:13 AM 26793 in reply to 26760

    Re: Null-Reference Exception at loading CuteChat time

    Hi
     
    I wanted to add that we did not have this problem with version 3.1.0 (integration package). I can try the standalone version, but then i dont see what conlusions i could possibly draw from the result.

    Greetings Daniel    
  •  02-20-2007, 9:03 AM 26823 in reply to 26793

    Re: Null-Reference Exception at loading CuteChat time

     
    Hi Adam
     
    Yes, you are right, the same problem does not occur in the standalone version and it has to do with the way we integrated cuteChat. I did some more investigations and this is what i have found out:
     
    Due to our special environment with two VS 2005 solutions, we could not use the global.asax file to implement the needed interfaces  that connect CuteChat to our user database. We implemented those methods in a separate project/dll and referenced them in the CuteChat database. The following two insert statements do this:
     
    INSERT CuteChatConfig (ConfigName,ConfigValue) VALUES
    (N'DataProviderType',N'CuteChatControls.CustomDataProvider,CuteChatControls')
    INSERT CuteChatConfig (ConfigName,ConfigValue) VALUES
    (N'UserAdapterType',N'CuteChatControls.CustomUserAdapter,CuteChatControls')
     
    I am pretty sure CuteChat somehow caches these config values. When an error occurs at startup, CuteChat does not cache these config values and all continuing requests cannot be handled. Most probably, CuteChat tries to execute the custom methods in global.asax which is the default, but they are not present.
     
    To sum up two reasons cause CuteChat have the problem described in this thread:
    - our special way of integration implementing custom integration methods somewhere else than in global.asax.
    - windows authentication to access database which fails at every iis reset (Not the main reason, just makes error occur more frequently!!)
     
    The reason why we always have this issue when iis is restarted, is that the database is accessed using windows authentication. Every request thread is impersonated to the identity of the current user before accessing the database. However, when iis is reset, the identity is lost and the thread takes the identity of the network service which cannot access our database. When i switched from windows to sql authentication i no longer had the problem. However, due to a our special environments using windows authentication is a must. Furthermore, even if sql authentication is used, if the connection to the db fails (due to a network error for example) at startup time, CuteChat will also fail! Therefore i am still looking for a different solution. Here are my questions:
     
    - Is it possible to set the CustomUserAdapter etc, in the config.file instead of having to execute the two above insert statements?
    - Will there be a new version, that can recover when the configuration is not properly initialized (due to a database error)?
    - Are there any other ways to tackle this problem?
     
    Thanks in advance for any answer.
     
    Daniel
     
  •  02-21-2007, 2:47 AM 26873 in reply to 26823

    Re: Null-Reference Exception at loading CuteChat time

     
    Hi
     
    I have found a workaround. I had to adapt the GetConnectionStringMethod.
     
    Old version:
     

    protected override string GetConnectionString( CuteSoft.Chat.UserIdentity user ){

       WindowsIdentity wi = HttpContext.Current.Session["Identity"] as WindowsIdentity;

       if ( wi != null ) {

          wi.Impersonate();

        }

        return ConfigurationSettings.AppSettings[ "DBConnectionString" ];

    }
     
     
     
     
    TO:
     

    protected override string GetConnectionString( CuteSoft.Chat.UserIdentity user ){

       WindowsIdentity wi = HttpContext.Current.Session["Identity"] as WindowsIdentity;

       if ( wi != null ) {

          wi.Impersonate();

        }else {

       throw new CuteChatException("No user identity available!");
       }

        return ConfigurationSettings.AppSettings[ "DBConnectionString" ];

    }
     
     
     
     
    If no user identity was available (this can happen during an iis reset as the session and forms authentication seem not to be perfectly sychnronised) no impersonation is done and database within the CuteChat dll will fail. If this happpens at loading time, somehow Cutehat gets into a state from which it cannot recover. This solution is now working for us. However, i still think this should not be possible. Access to a database might fail because of different reasons, such as network error, someone has played with the db settings etc.. I believe CuteChat could still fall into an irecovarable state, which should not be possible. I hope this is fixed in a future version (We never experienced this problem in version 3.1.0)
     
    Greetings
     
    Daniel 
View as RSS news feed in XML