Nullreference Exception... cant find where it comes from.


Author
Message
Philipp Guntermann
Philipp Guntermann
StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)
Group: Forum Members
Posts: 141, Visits: 263
hi,

on a specific form i get the nullreference exceptionb below, (only) when i perform the following steps:

1. Delete records, untill none left.

2. Add new record

3. Save new record.

After that i get the exception. However, even tho it sais it could not save the data, by the time it shows the

exception, it has saved the data into the db (without any errors/missing values). When i then close the exception window, everything is fine, i then need to click the save button again, and 1 out of ~3 times, it will then not show the exception.

The Exception i get is the following:

BusinessLayerException
  An error occurred while saving an the data to the server.
NullReferenceException
  Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

Source     : MicroFour StrataFrame Business

Stack Trace:
   bei System.Windows.Forms.Binding.SetPropValue(Object value)
   bei System.Windows.Forms.Binding.PushData(Boolean force)
   bei System.Windows.Forms.BindingManagerBase.PushData(Boolean& success)
   bei System.Windows.Forms.BindingManagerBase.PushData()
   bei System.Windows.Forms.PropertyManager.OnCurrentChanged(EventArgs ea)
   bei System.Windows.Forms.BindToObject.PropValueChanged(Object sender, EventArgs e)
   bei MicroFour.StrataFrame.Business.BusinessLayer.SaveByForm(Boolean Transactional, String TransactionKey)
   bei MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save(Boolean Transactional, String TransactionKey)
   bei MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save()
   bei MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdSave_Click(Object sender, EventArgs e)
   bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   bei System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
   bei System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   bei System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   bei System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

as said, it only happens when adding a new record after i deleted all records. and even tho it shows the exception, in theory it does everything right.

So my main question propably is, when do theese events in the businesslayer get triggered:

   bei System.Windows.Forms.Binding.SetPropValue(Object value)
   bei System.Windows.Forms.Binding.PushData(Boolean force)
   bei System.Windows.Forms.BindingManagerBase.PushData(Boolean& success)
   bei System.Windows.Forms.BindingManagerBase.PushData()

?

Philipp Guntermann
Philipp Guntermann
StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)
Group: Forum Members
Posts: 141, Visits: 263
allright.

i tracked it down to the datetime-picker control. i am now using "Value" as BindingProperty instead of "BindableValue", where it defaults to and the error is gone.

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)Advanced StrataFrame User (960 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Hi Phillip



I don't know if this is relevant in your case but I'll pass it along. I have a lot of data with null datetime fields ( converted from VFP where empty date fields are allowed) In the BOMapper I set those fields to return and set alternate on null / value type and then set #1/1/1800# as the return value. The SF date time control will see that as an empty date.



Philipp Guntermann
Philipp Guntermann
StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)StrataFrame User (231 reputation)
Group: Forum Members
Posts: 141, Visits: 263
Hi Charles,

yes, i think you can specify that in the control aswell. however, in that case both datetime values are required through the BO's requiredfields.

Not sure why setting from BindableValue to Value resolved the issue, or why BindableValue created an issue. But it works that way now, and gets and sets the values correctly from and to the database.

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Phillipp,

This thread is a bit old, but I just been fighting this very same issue getting this weird NullReferenceException not telling me which field was being triggering the error.

In my case I also have a DateTimePicker, but its value was being generated via the BO.SetDefaultValues() and in the BO, this datetime field was part of the Required fields collection.  I moved setting the default value to the BO.BeforeSave() and then I started getting this weird error, it looks like that the required field collection is validated somewhere before the bo.BeforeSave() triggering the error when saving the bo which is wrong because I was setting the value of the field right in the bo.BeforeSave().

Anyway, hope this help somebody else. Smile

Edhy Rijo

Andrew Harper
Andrew Harper
StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)StrataFrame User (282 reputation)
Group: StrataFrame Users
Posts: 87, Visits: 3.3K
Hi Edhy,

I struck this same scenario last week and came to the same conclusion -  that the required fields are validated prior to the BeforeSave(). 
I had to remove one of the fields from the required fields list to get the behaviour i desired,

Andy 
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Andy,

Thanks for confirming this, probably Trent or Ben can jump in explaining the logic behind this behavior.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search