NullReferenceException in Devart.Data.Linq.Provider.g.a

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
edwin
Posts: 19
Joined: Thu 08 Oct 2009 09:15

NullReferenceException in Devart.Data.Linq.Provider.g.a

Post by edwin » Mon 23 May 2011 08:42

I got an NullReferenceException using the latest version (6.30.160.0) that didn't occur in our previous version 5.25.49.0:
System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld.
bij Devart.Data.Linq.Provider.g.a(bg A_0)
bij Devart.Data.Linq.Provider.h.a(bg A_0)
bij Devart.Data.Linq.Provider.g.a(SqlExpression A_0)
bij Devart.Data.Linq.Provider.g.a(SqlExpression A_0, Boolean A_1)
bij Devart.Data.Linq.Provider.n.a(IDataServices A_0, SqlExpression A_1, Boolean A_2)
bij Devart.Data.Linq.Provider.n.a(IDataServices A_0, SqlExpression A_1)
bij Devart.Data.Linq.Provider.n.a(Type A_0, SqlExpression A_1, IDataServices A_2)
bij Devart.Data.Linq.Provider.DataProvider.CompiledQuery.GetReaderFactory(List`1 elementInstanceTypes, IDataServices services, SqlNode query)
bij Devart.Data.Linq.Provider.DataProvider.CompiledQuery..ctor(QueryInfo queryInfo, IDataServices services, Boolean isQueryObjectByKey, Object queryObjectKey)
bij Devart.Data.Linq.Provider.DataProvider.BuildQuery(Expression query)
bij Devart.Data.Linq.Provider.DataProvider.Devart.Data.Linq.Provider.IProvider.Compile(Expression query)
bij Devart.Data.Linq.DataQuery`1.i()
bij System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
bij System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
bij Jumbo.Juist.Models.Data.DAL.Search(DateTime dt) in D:\Projects\JUIST\Juist\Juist\Models\Data\DAL.cs:regel 54
bij Jumbo.Juist.Controllers.ZoekenController.Index(String date) in D:\Projects\JUIST\Juist\Juist\Controllers\ZoekenController.cs:regel 47
bij lambda_method(ExecutionScope , ControllerBase , Object[] )
bij System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
bij System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
bij System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
bij System.Web.Mvc.ControllerActionInvoker.c__DisplayClassd.b__a()
bij System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
bij System.Web.Mvc.ControllerActionInvoker.c__DisplayClassd.c__DisplayClassf.b__c()
bij System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
bij System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
The associated code is:

Code: Select all

        /// 
        /// Search based on the given Date
        /// 
        /// 
        /// 
        public static SearchResult Search(DateTime dt)
        {
            IQueryable iq =
            // var xxx =
                from rd in AppDataContext.GetInstance().RouteDags
                join b in AppDataContext.GetInstance().Bezorgings on rd.Id equals b.RouteDag
                join h in AppDataContext.GetInstance().Hubs on b.Hub equals h.Id into hjoined
                from hj in hjoined.DefaultIfEmpty()                
                where rd.Datum == dt
                orderby rd.Vertrektijd.TimeOfDay, rd.Routenummer, b.Winkelnummer
                //select new {rd, b, hjoined, hj};
                select new SearchResultItem
                {
                    Naam = String.IsNullOrEmpty(hj.Code) ? b.Winkelnaam : "Via " + hj.Code + ": " + b.Winkelnaam,
                    Winkelnummer = b.Winkelnummer,
                    Routenummer = rd.Routenummer,
                    Vertrektijd = rd.Vertrektijd,
                    Levertijd = b.Levertijd,
                    Prognose = b.Prognose,
                    Chauffeur = rd.Chauffeur,
                    Configuratie = rd.Configuratie,
                    Voertuignummer = rd.Voertuignummer,
                    AankomstDC = rd.AankomstDc,
                    VertrekDC = rd.VertrekDc,
                    RouteDagId = rd.Id,
                    BezorgingId = b.Id
                };

             //var y = xxx.ToList();
             //return null; 

            SearchResult sr = new SearchResult(iq.ToList(), dt);

            return sr;

        }


Hope you can help fixing this.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Mon 23 May 2011 13:01

We have fixed this issue, the fix will be available in the nearest build.

As a temporary workaround, you can use an anonymous type in the query, e.g.,

Code: Select all

IQueryable iq =
  (from rd in AppDataContext.GetInstance().RouteDags
  ...
  select new
  {
    Naam = String.IsNullOrEmpty(hj.Code) ? b.Winkelnaam :
      "Via " + hj.Code + ": " + b.Winkelnaam,
    Winkelnummer = b.Winkelnummer,
    ...
  })
  .ToList()
  .Select(a => new SearchResultItem() 
  {
    Naam = a.Naam,
    Winkelnummer = a.Winkelnummer,
    ...
  })
  .ToList();
Also, you can use the 6.10.141 version of dotConnect for Oracle. Provided that you have an active subscription, you should be able to download it from Registered Users' Area:
http://secure.devart.com/

agillesp
Posts: 11
Joined: Fri 03 Jun 2011 07:50

Fix Available

Post by agillesp » Fri 03 Jun 2011 16:10

Is this fix available or when will it be? This bug is very debilitating for me and the work-around isn't acceptable in my case.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 03 Jun 2011 17:03

We have released the new 2.50.24 build of LinqConnect, which includes the fix for this issue. You can download this build from
http://www.devart.com/linqconnect/download.html
(the trial and free versions) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For the detailed information about the fixes and improvements available in LinqConnect 2.50.24, please refer to
http://www.devart.com/forums/viewtopic.php?t=21155

edwin
Posts: 19
Joined: Thu 08 Oct 2009 09:15

Other error pops up (Entity type has no key)

Post by edwin » Mon 06 Jun 2011 15:25

Unfortunately, another error pops up, after deployment in production:

Code: Select all

System.InvalidOperationException: Entity type has no key.
   at Devart.Data.Linq.Mapping.l.a(IList`1 A_0)
   at Devart.Data.Linq.Mapping.l.a(MetaType A_0)
   at Devart.Data.Linq.t.c(MetaType A_0)
   at Devart.Data.Linq.Provider.DataProvider.TryGetQueryObjectByKey(Expression query, Object& queryObjectKey)
   at Devart.Data.Linq.Provider.DataProvider.BuildQuery(Expression query)
   at Devart.Data.Linq.Provider.DataProvider.Devart.Data.Linq.Provider.IProvider.Compile(Expression query)
   at Devart.Data.Linq.DataQuery`1.i()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Jumbo.Juist.Controllers.BeheerController.ExecuteMedeaExport(AppDataContext context)
This occurs in the following code:

Code: Select all

List list = context.V_MedeaExports.Where(x => x.Datum >= DateUtility.GetToday()).ToList();
V_MedeaExports is a view. We have other places were we use views, which do work and some don't. At the places where it doesn't work, an inequality (>=) is used, instead of all equalities (=) in the Where.

As an ugly workaround, I set Entity Key to 'true' for "Datum" (which means Date) in the linq2sql properties, but I don't know if this has other undesired consequences...

I'll repeat this post in a new thread, might be usefull for others which didn't have the original problem.

edwin
Posts: 19
Joined: Thu 08 Oct 2009 09:15

Post by edwin » Tue 07 Jun 2011 09:26

As a correction to my last post, the workaround is not working!!!

Although no exception is thrown, not all data is present!

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 07 Jun 2011 15:38

edwin, we've answered you in another topic:
http://www.devart.com/forums/viewtopic.php?t=21197

Post Reply