NullReferenceException on Commit using CpBT

7 views
Skip to first unread message

Josh Rogers

unread,
Jul 14, 2009, 12:54:16 PM7/14/09
to uNhAddIns
I am playing around with converting some of my tables to Hi/Lo and am
running some tests.  I am create a new object.  I save it and it
returns the object with the id as it should, then I call an AcceptAll
which is just ending the conversation:

[PersistenceConversation(ConversationEndMode = EndMode.End)]
        public void AcceptAll()
        {   }

My problem is that it is throwing a NullReferenceException:

System.NullReferenceException: Object reference not set to an instance
of an object.
   at uNhAddIns.Adapters.Common.AbstractConversationInterceptor.DisposeConversationOnException()
in c:\Documents and
Settings\HP_Administrator\Desktop\uNHAddins\uNhAddIns\uNhAddIns.Adapters.Common\AbstractConversationInterceptor.cs:line
156
   at uNhAddIns.CastleAdapters.AutomaticConversationManagement.ConversationInterceptor.Intercept(IInvocation
invocation) in c:\Documents and
Settings\HP_Administrator\Desktop\uNHAddins\uNhAddIns\uNhAddIns.CastleAdapters\AutomaticConversationManagement\ConversationInterceptor.cs:line
46
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at IUserDalProxy1515046b0bf04a9ba6f4eecb85f833a9.AcceptAll()
   at TEAMSLogic.Impl.UserLogic.AcceptAll() in
C:\Source\TEAMS\TEAMS\TEAMSLogic\Impl\UserLogic.cs:line 31
   at TEAMSDataUnitTests.UserTests.CanCreateUser() in
C:\Source\TEAMS\TEAMS\TEAMSUnitTests\UserTests.cs:line 51

I copied the query that NHibernate created and did the query in SQL
Server and it worked just fine so I am not sure where the
NullReferenceException is coming from.

Any guidance would be helpful!

Thanks,
Josh

Fabio Maulo

unread,
Jul 14, 2009, 1:28:11 PM7/14/09
to unha...@googlegroups.com
C:\Source\TEAMS\TEAMS\TEAMSUnitTests\UserTests.cs:line 51

2009/7/14 Josh Rogers <joshl...@gmail.com>



--
Fabio Maulo

Josh Rogers

unread,
Jul 14, 2009, 1:36:32 PM7/14/09
to unha...@googlegroups.com
Fabio,

That is my call to Accept all it is

userLogic.AcceptAll();

I have stepped through and I know it is not null. I also call
userLogic.Save() right before it and it works fine.

I did find this though, I was stepping through the debugger and in the
method DisposeConversationOnException var cca is being assigned
ConversationsContainerAccessor and when looking at that property
there is the property Container and inside the container there is a
CurrentConversation property that is null. Would that be throwing
this exception? If so, why is that null?

Thanks,
Josh

Fabio Maulo

unread,
Jul 14, 2009, 1:50:08 PM7/14/09
to unha...@googlegroups.com
Are you calling a method marked with Persistent... from another method inside the same class ?

2009/7/14 Josh Rogers <joshl...@gmail.com>



--
Fabio Maulo

Josh Rogers

unread,
Jul 14, 2009, 2:05:55 PM7/14/09
to unha...@googlegroups.com
No.....I have found the problem. It ended up being a question that I
need to ask on NHUsers.

But I do have a possible bug in uNHAddins:

If AbstractConversation.EncloseWithExceptionManagement throws an error
when trying to perform action() it throws a new ConversationException
exception which is caught by the try catch block in
ConversationInterceptor.Intercept which the catch clause calls
DisposeConversationOnException which subsequently calls
AbstractConversationContainer.Unbind however everything has already
been unbound so Unbind returns null which then you try to run
Dispose() on that null which in turn throws the unhelpful
NullReferenceException and it loses the stack trace that allows me to
find the actual problem.

It seems the conversation should be unbound after successful
completion of the action or there needs to be a null check in the
DisposeConversationOnException method.

Thanks,
Josh

Josh Rogers

unread,
Jul 14, 2009, 2:23:53 PM7/14/09
to unha...@googlegroups.com
In fact, here is a patch file that I believe would work.
DisposeNullRefExFix.patch

Josh Rogers

unread,
Jul 14, 2009, 2:52:28 PM7/14/09
to unha...@googlegroups.com
Sorry, I actually left of a trailing semi-colon.

Here is the proper patch file....I have compiled and tested, and now
instead of the previous exception I receive this one which is MUCH
more informative:

uNhAddIns.SessionEasier.Conversations.ConversationException: Exception
during persistent conversation End:could not insert:
[TEAMS_ORM.User#10256384][SQL: INSERT INTO dbo.tblUsers (FirstName,
LastName, UserName, Password, EmailAddress, RequirePasswordChange,
UserAdded, DateAdded, Active, UserID) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?)] ---> NHibernate.Exceptions.GenericADOException: could not
insert: [TEAMS_ORM.User#10256384][SQL: INSERT INTO dbo.tblUsers
(FirstName, LastName, UserName, Password, EmailAddress,
RequirePasswordChange, UserAdded, DateAdded, Active, UserID) VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] --->
System.Data.SqlClient.SqlException: String or binary data would be
truncated.

Thanks,
Josh

DisposeNullRefExFix.patch

Fabio Maulo

unread,
Jul 14, 2009, 3:05:14 PM7/14/09
to unha...@googlegroups.com
Thanks.

2009/7/14 Josh Rogers <joshl...@gmail.com>



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages