The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Occasional error on app restart - Object reference not set to an instance of an object

Last post 11-12-2007, 6:44 AM by Mike.Griffin. 4 replies.
Sort Posts: Previous Next
  •  11-02-2007, 10:04 AM 6310

    Occasional error on app restart - Object reference not set to an instance of an object

    Hi there,

    I have a problem which sometimes occurs when my application restarts during the day, while users are online.  I'm currently using the 2007.0913 Release version of ES, SQL Server 2005, although this is not a new issue related to this release of ES, I've seen it now and again for the last year or so.  It's very infrequent but worth reporting all the same.

    What happens is, just after the application restarts I sometimes get an error message from the application 'Object reference not set to an instance of an object'.  The stack trace indicates that the error occurs while trying to populate data into one of my ES objects.

    A cutdown version of the stack trace looks something like this,

    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
    at BusinessObjects.CompaniesMetadata.esDefault(String mapName) in ...\Generated\Companies.vb
    at BusinessObjects.CompaniesMetadata.GetProviderMetadata(String mapName) in ...\Generated\Companies.vb
    at EntitySpaces.Interfaces.esDynamicQuery.PopulateRequest(esDataRequest request)
    at EntitySpaces.Interfaces.esDynamicQuery.Load() 

    I've indicated the line in esDefault below where the error occurs,

    Code:
    Private Function esDefault(ByVal mapName As String) As esProviderSpecificMetadata
    
        If (Not _providerMetadataMaps.ContainsKey(mapName)) Then
    			
            Dim meta As esProviderSpecificMetadata = New esProviderSpecificMetadata()
    				
            meta.AddTypeMap("ID", new esTypeMap("int", "System.Int32"))
            .
            .
            .
    
            meta.Source = ...
            meta.Destination = ...
    
            meta.spInsert = ...
            meta.spUpdate = ...
            meta.spDelete = ...
            meta.spLoadAll = ...
            meta.spLoadByPrimaryKey = ...
    
            Me._providerMetadataMaps.Add("esDefault", meta)       '<--- Error Here
    
        End If
    
        Return Me._providerMetadataMaps("esDefault")
    
    End Function

     

    I'm wondering, especially since this problem only happens rarely, whether this is related to two users querying the database around the same time, just after the restart??  And for both of them, it initially looks like the esDefault metadata map is not setup yet for a specific table, so they both try to add it around the same time?  That's just a complete guess though.

    My ES classes have been regenerated using the 2007.0913 templates, and in MyGeneration the Generated Master Classes template advanced options, the only checkboxes I have ticked are Generate a Single File, Metadata Class Should Ignore Schema and Metadata Class Should ignore Catalog.

    Not sure what further info you might need so I'll hand over to you.  Hoping you can help.  Thanks.

  •  11-02-2007, 5:52 PM 6316 in reply to 6310

    Re: Occasional error on app restart - Object reference not set to an instance of an object

    This is so strange, we had this problem long ago. We fixed it and it was never reported again, hmmm. If you look at the last line of your metadata class you'll see something like this:

     

    Code:
    static private int _esDefault = RegisterDelegateesDefault();
     

    Since a static variable is only initialized once per class I am very surprised your getting this, in fact, I've been staring at this code for quite some time. Strange that the line occurs on that particular line and with an 'Object reference not set to an instance of an object' error? You can see from the call stack that it calls Add then Insert on the dictionary, so obviously the dictionary is non null, and the other two parameters are "esDefault" and "meta" which seem impossible to be null. I've done a tremendous amount of multi-threaded coding in C so I'll track it down. Obviously two threads are in here at the same time which shouldn't cause an issue. What I would have expected was a duplicate key error in that both got in here and tried to add "esDefault" to the dictionary, hmmm, let me do some research and debugging.

    [modified]

    We can throw a lock in there on  "_providerMetadataMaps" that would probably solve it for sure, but let me figure out what is happening first. Since it hadn't been reported since that change I thought it was snuffed out.


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  11-10-2007, 1:10 PM 6415 in reply to 6316

    Re: Occasional error on app restart - Object reference not set to an instance of an object

    Okay difter, out beta on Monday the 12th will have this fix in, I'm sure we have utterly nailed it this time. You are the only person who has hit it, but there was an edge condition in there, when you upgrade and test post back and let us know how it goes, but again, the build won't be available until the 12th.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  11-12-2007, 3:01 AM 6427 in reply to 6415

    Re: Occasional error on app restart - Object reference not set to an instance of an object

    You've nailed it this time for sure!!  I've been testing with the 1112 beta and this is definitely fixed.

    Thanks so much.  The ES support is outstanding as usual!

  •  11-12-2007, 6:44 AM 6434 in reply to 6427

    Re: Occasional error on app restart - Object reference not set to an instance of an object

    I'd like to thank you actually, your post is a good example that others can learn from, a very clear explanation, call stack, sample code indicating what line the error occurred on, you literally spoon fed us and that is exactly how to do it, so thank you. Unfortunately we still go posts with little more than "Code no worky" as the entire message, 24 responses later we begin to get to the meat of the matter. So, well done drifter Yes

    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML