ORMGeneral trace switch causes exception

Posts   
 
    
Posts: 98
Joined: 10-Nov-2006
# Posted on: 12-Nov-2007 18:58:26   

I have exactly the same problem as is described in this thread:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=9331

except I'm using the 2.5.07.1019 version of SD.LLBLGen.Pro.ORMSupportClasses.NET20.DLL

Specifically, if I set the ORMGeneral trace flag to 4, I get a NullReferenceException.

Did this bug come back in this most recent version?

Here's my stack trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.GetEntityDescription(Boolean switchFlag, IEntity entity) +225
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.GetEntityDescription(TEntity entity, Boolean switchFlag) +17
   SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.PerformAdd(T item) +95
   SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1..ctor(SerializationInfo info, StreamingContext context) +417
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1..ctor(SerializationInfo info, StreamingContext context) +39
   XXX.CollectionClasses.ContactCollection..ctor(SerializationInfo info, StreamingContext context) in D:\Source\XXX\CollectionClasses\ContactCollection.cs:57

As a workaround, I'll just set the trace flag to 3 or less.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 12-Nov-2007 19:09:07   

What are the specifics of the entity added? I.e. was it empty, new, loaded...

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 10-Nov-2006
# Posted on: 12-Nov-2007 19:54:18   

Sorry I didn't post more details - though everything you needed might be in that other thread and didn't want to duplicate data if it wasn't necessary.

I have an ASP.NET page that contains a list of LLBLGen Entities in its ViewState. When I post the page back and the ViewState gets decoded, I see the error. Here's a full stack trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.GetEntityDescription(Boolean switchFlag, IEntity entity) +225
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.GetEntityDescription(TEntity entity, Boolean switchFlag) +17
   SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.PerformAdd(T item) +95
   SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1..ctor(SerializationInfo info, StreamingContext context) +417
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1..ctor(SerializationInfo info, StreamingContext context) +39
   XXX.Data.CollectionClasses.ContactCollection..ctor(SerializationInfo info, StreamingContext context) in D:\XXX\Data\CollectionClasses\ContactCollection.cs:57

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context) +0
   System.RuntimeMethodHandle.SerializationInvoke(Object target, SignatureStruct declaringTypeSig, SerializationInfo info, StreamingContext context) +24
   System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context) +114
   System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context) +257
   System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder) +49
   System.Runtime.Serialization.ObjectManager.DoFixups() +167
   System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +203
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +190
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream) +12
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +1713
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +198
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +198
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +384
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +210
   System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader) +198
   System.Web.UI.ObjectStateFormatter.Deserialize(Stream inputStream) +142

[ArgumentException: The serialized data is invalid.]
   System.Web.UI.ObjectStateFormatter.Deserialize(Stream inputStream) +206
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +311
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
   System.Web.UI.HiddenFieldPageStatePersister.Load() +140

[ViewStateException: Invalid viewstate. 
    Client IP: 127.0.0.1
    Port: 3210
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
    ViewState: cHSuvySF6xdQ8yflhPMdsA...]

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +116
   System.Web.UI.HiddenFieldPageStatePersister.Load() +240
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +83
   System.Web.UI.Page.LoadAllState() +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6978
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
   System.Web.UI.Page.ProcessRequest() +86
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.classes_supporter_supporterview_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\aesop\56fd200d\f67e43d4\App_Web_ffwzehmb.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +303
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 13-Nov-2007 18:25:15   

Will look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 14-Nov-2007 12:03:49   

Could you please use the debug build of the ORMSUpportClasses dll (included in the runtime libs folder) by placing that in the bin folder of your application, including the .pdb and run the app again? That should give a line number. I can't reproduce it and the code doesn't look like it will fail on null references unless something is wrong with the entity itself.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 10-Nov-2006
# Posted on: 14-Nov-2007 17:14:39   

Here's the relevant part of the stack trace with the debug build:


[NullReferenceException: Object reference not set to an instance of an object.]
   SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.GetEntityDescription(Boolean switchFlag, IEntity entity) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v2.0\RuntimeLibraries 2.5 .NET 2.x\ORMSupportClasses\EntityBase.cs:3762
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.GetEntityDescription(TEntity entity, Boolean switchFlag) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v2.0\RuntimeLibraries 2.5 .NET 2.x\ORMSupportClasses\EntityCollectionBase.cs:1493
   SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.PerformAdd(T item) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v2.0\RuntimeLibraries 2.5 .NET 2.x\ORMSupportClasses\CollectionCore.cs:1233
   SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1..ctor(SerializationInfo info, StreamingContext context) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v2.0\RuntimeLibraries 2.5 .NET 2.x\ORMSupportClasses\CollectionCore.cs:148
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1..ctor(SerializationInfo info, StreamingContext context) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v2.0\RuntimeLibraries 2.5 .NET 2.x\ORMSupportClasses\EntityCollectionBase.cs:100
   Auctionpay.Aesop.Data.CollectionClasses.ContactCollection..ctor(SerializationInfo info, StreamingContext context) in D:\Source\Aesop\ESW\Dev\Auctionpay\Aesop\Data\CollectionClasses\ContactCollection.cs:57

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 14-Nov-2007 17:54:33   

internal string GetEntityDescription(bool switchFlag, IEntity entity)
{
    if(!switchFlag || (entity == null) || ((entity != null) && entity.IsDeserializing))
    {
        return "EntityBase";
    }

    StringBuilder description = new StringBuilder(256);
    description.AppendFormat(null, "\r\n\tEntity: {0}. ObjectID: {1}\r\n", entity.GetType().FullName, this.ObjectID.ToString());
    foreach(EntityField field in entity.Fields.PrimaryKeyFields)             // LINE 3762
    {
        string currentValue = "<undefined value>";
        if( field.CurrentValue != null )
        {
            currentValue = field.CurrentValue.ToString();
        }
        description.AppendFormat( null, "\tPrimaryKey field: {0}. Type: {1}. Value: {2}\r\n", field.Name, field.DataType.FullName, currentValue );
    }

    return description.ToString();
}

So the PK collection is either null, or the fields are null. I can't reproduce it in a serialization/deserialization setup in a unittest, I'll try to repro it in a webpage.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 15-Nov-2007 13:10:33   

I think I know why this happens. It's not always, but sometimes related objects of an object that's being deserialized aren't filled yet by the binary formatter. As during the deserialization of an entity collection the entities in that collection are added back to the collection, it can be the objects inside these entities, at the point when they're added, aren't filled in yet. I have no idea why this is, but .NET's BinaryFormatter has this side effect. In the designer we also had to add code for this to post-deserialization do things we'd normally do during deserialization.

So I'll add a check there that during deserialization the whole getdescription routine shouldn't do anything.

Fixed in next build (11142007)

Frans Bouma | Lead developer LLBLGen Pro