Null Reference Exception

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
ibzakharov
Posts: 1
Joined: Tue 04 Mar 2014 15:50

Null Reference Exception

Post by ibzakharov » Tue 04 Mar 2014 17:18

I am getting null reference exception when modifing data. What's the problem?

LinqConnect: 4.4.441.0
DBMS: Oracle Database 11g Release 11.2.0.2.0 - 64bit Production

This occur when data is deleted

Code: Select all

[2014-03-04] [18:41:18.768] Info Begin transaction  
[2014-03-04] [18:41:18.805] Info Execute: BEGIN
DELETE FROM MD_PROC WHERE MD_PROC_ID = :key1;
DELETE FROM MD_PROC WHERE MD_PROC_ID = :key2;
DELETE FROM MD_PROC WHERE MD_PROC_ID = :key3;
END;  
[2014-03-04] [18:41:18.868] Info Rollback  
[2014-03-04] [18:41:18.907] Error System.NullReferenceException: Ссылка на объект не указывает на экземпляр объекта.
   в xget__ProcId_106(MdProcParam )
   в Devart.Data.Linq.Mapping.Accessors.d.Accessor`2.GetValue(T instance)
   в Devart.Data.Linq.Mapping.Accessors.MetaAccessor`2.GetBoxedValue(Object instance)
   в Devart.Data.Linq.Engine.b4.c.c()
   в System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   в System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   в Devart.Data.Linq.Engine.c5.i(IObjectEntry A_0)
   в Devart.Data.Linq.Engine.c5.l()
   в Devart.Data.Linq.Engine.c5.j()
   в Devart.Data.Linq.Engine.c5.a.b()
   в Devart.Data.Linq.Engine.b5.a(ConflictMode A_0)
   в Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
   в Devart.Data.Linq.DataContext.SubmitChanges()
   в PMEditor.Orcl.SubmitChanges() в d:\OISPLUS\Applications\PMEditor\branch\Common\Orcl.cs:строка 206

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Null Reference Exception

Post by MariiaI » Wed 05 Mar 2014 14:39

Could you please send us a small test project with the corresponding DDL/DML scripts so that we are able to reproduce this issue and investigate it in more details.

giacomo.galletto
Posts: 5
Joined: Thu 11 Jun 2015 09:09

Re: Null Reference Exception

Post by giacomo.galletto » Thu 11 Jun 2015 09:11

Hello,

I am having exactly the same problem, submitting changes after deleteOnSubmit.

Did you find a solution?

Cheers
Giacomo

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Null Reference Exception

Post by MariiaI » Thu 11 Jun 2015 10:54

Unfortunately, this error is not reproducible in our environment.
Please describe your scenario in more details, so that we are able to investigate the issue. For example, provide us with the following details:
- the version of LinqConnect;
- the DBMS you are working with;
- the code snippet, with which the error occurs;
- the definitions of the DataContext class and entity classes, etc.

If possible, please send us a small test project with the corresponding DDL/DML scripts, with which this issue is reproducible. This will significantly speed up the process of determining the cause of the error and finding the solution for it.

Looking forward to your reply.

giacomo.galletto
Posts: 5
Joined: Thu 11 Jun 2015 09:09

Re: Null Reference Exception

Post by giacomo.galletto » Thu 11 Jun 2015 13:02

Hello,

sorry for the poor details on my request.
I'm working with a MySQL database with the LinqConnect version 4.4.727.0

My scenario involves two tables, B_POLIZZE and B_CONTENITORI.
The second one has a foreign key IDPOLIZZA linked with the primary key of the first one, in a ON DELETE CASCADE relationship.

Data from the two tables are bound into two datagrid. At the selection of a row in the B_POLIZZE datagrid the corresponding B_CONTENITORI rows are loaded in the second datagrid.

The error occours sometimes (but quite often) trying to delete one or more rows from the B_POLIZZE datagrid, which leads to the deletetion of the linked B_CONTENITORI rows. What the error exactly reports is the following message:
Error System.NullReferenceException: Riferimento non impostato su un'istanza di oggetto.
в xget__IDPOLIZZA_139(B_CONTENITORI)
в Devart.Data.Linq.Mapping.Accessors.d.Accessor`2.GetValue(T instance)
в Devart.Data.Linq.Mapping.Accessors.MetaAccessor`2.GetBoxedValue(Object instance)
в Devart.Data.Linq.Engine.b4.c.c()
в System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
в System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
в Devart.Data.Linq.Engine.c5.i(IObjectEntry A_0)
в Devart.Data.Linq.Engine.c5.l()
в Devart.Data.Linq.Engine.c5.j()
в Devart.Data.Linq.Engine.c5.a.b()
в Devart.Data.Linq.Engine.b5.a(ConflictMode A_0)
в Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
в Devart.Data.Linq.DataContext.SubmitChanges()
The code snippet is:

Code: Select all

For Each BPolizza As B_POLIZZE In dgPolizzeSbarchi.SelectedItems

      If BPolizza.ACCETTATA = "S" Then Continue For 'Salto le polizza accettate in quanto gia flussate

      RemoveHandler BPolizza.PropertyChanged, AddressOf BRecordPropertyChanged
      
      LinqModule.ManifestiDataContext.B_POLIZZEs.DeleteOnSubmit(BPolizza)

Next

LinqModule.ManifestiDataContext.SubmitChanges()
I also tried to firstly delete the linked B_CONTENITORI rows before deleting the B_POLIZZA row:

Code: Select all

For Each BPolizza As B_POLIZZE In dgPolizzeSbarchi.SelectedItems

       If BPolizza.ACCETTATA = "S" Then Continue For 'Salto le polizza accettate in quanto gia flussate

       RemoveHandler BPolizza.PropertyChanged, AddressOf BRecordPropertyChanged

       For Each BCont As B_CONTENITORI In BPolizza.B_CONTENITORIs

              LinqModule.ManifestiDataContext.B_CONTENITORIs.DeleteOnSubmit(BCont)

      Next

      LinqModule.ManifestiDataContext.SubmitChanges()

      LinqModule.ManifestiDataContext.B_POLIZZEs.DeleteOnSubmit(BPolizza)

Next

LinqModule.ManifestiDataContext.SubmitChanges()
I agree a test project able to reproduce the error but unfortunatelly is not so easy for me to provide it, needed to let you also have a DB schema with some data.

Anyway I could try to prepare it, given time.

Regards
Giacomo

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Null Reference Exception

Post by MariiaI » Fri 12 Jun 2015 13:30

Thank you for the response. However, the NullReferenceException is not reproducible in our environment with the latest build of LinqConnect 4.4.760 and sample code similar to yours.
I agree a test project able to reproduce the error but unfortunately is not so easy for me to provide it, needed to let you also have a DB schema with some data.
Anyway I could try to prepare it, given time.
We would be very much obliged to you if you send us your LinqConnect model and/or create a small test project with which this issue can be reproduced and send it us.
JIC: It is not necessary to send us the whole project with real data, you could exclude those parts of the project that should not affect the main scenario.

Post Reply