Search   

Friday, February 10, 2012

Support » Support Forum

Register  Login

 Menu  
 
    

 Welcome!  
 


Welcome to the NDO support forum!

kreis.gif Please register/login at the site if you want to post a thread. We sometimes copy support mails of common interest to the forum. They appear with anonymous sender.
kreis.gif Please post your messages in English language if possible. You can do your posts also in German, we will translate your post and our answer so that all users of the forum can read your posts.
kreis.gif The forum software requires that javascript is enabled.
kreis.gif Please do not insert licence information or licence keys in forum posts.
kreis.gif If you know a good answer to a post of another user, feel free to reply!
kreis.gif The forum is monitored. We reserve the right to remove posts we consider not to be useful for other forum users.

   Print   

      
 NDO Support Forum  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  NullReferenceEx...
 NullReferenceException in Query
 
 5/2/2007 8:44:46 AM
schoetbi
15 posts


NullReferenceException in Query
 Modified By Mirko  on 5/2/2007 9:35:24 AM)
Hello, I made a query:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SystemComponentConfig.QueryHelper qh = new SystemComponentConfig.QueryHelper();
SystemComponentConfig cfg = null;

try
{
NDOQuery q = new NDOQuery(this.persistenceManager
, qh.systemComponentId + "='" + id.ToString() + "'", false);
45: List cfgs = q.Execute();
if (cfgs.Count > 0)
cfg = cfgs[0];
}
catch (Exception e)
{
log.Error("Could not query for SystemComponentnConfig for SystemComponent ID="
+ id.ToString(), e);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

and got the following exception:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Exception: System.NullReferenceException
Message: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
Source: NDO
bei NDO.PersistenceManager.b(Class A_0, IPersistenceCapable A_1, DataRow A_2)
bei NDO.PersistenceManager.a(Class A_0, IPersistenceCapable A_1, DataRow A_2)
bei NDO.PersistenceManager.a(Type A_0, ICollection A_1, Boolean A_2)
bei NDO.Query.c(Type A_0, String A_1)
bei NDO.Query.b()
bei NDO.Query.Execute()
bei NDO.NDOQuery`1.Execute()
bei Sara.Services.SystemComponentServiceDb.GetConfigFor(Guid id) in C:\Sara\PrototypeTrunk\CoreClasses\Sara.Services\Systemcomponents\SystemComponentServiceDb.cs:Zeile 45.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I cannot deduce from this exception to the source of the error. What object is null here? How can I avoid to get this exception without rechecking everything in the mapping? I wish to have an errormessage that points me to the solution without knowing it in advance. Maybe the track to the solution is a little easier with NDO 2.0?

A few facts:
I automatically generate the SQL script,
Regenerated the database
made the demo-objects (only one in this case)
restarted the program
made the above query

regards,
Tobias
 5/2/2007 9:39:44 AM
Mirko
109 posts
5th


Re: NullReferenceException in Query

Hi Tobias,

I guess, that id.ToString() is a string which can't be recognized as a valid expression by NDO or the underlying ADO.NET provider. Try to do the following:

NDOQuery<...> q = new NDOQuery<...>(this.persistenceManager, qh.systemComponentId + "= {0}", false);
q.Parameters.Add(id); // id must have the same type as systemComponentId

If that doesn't help, please write a small test solution and send it to me.

Regards:
Mirko

 5/2/2007 12:12:55 PM
schoetbi
15 posts


Re: NullReferenceException in Query
Hello,

i tried the new type of query but got the same fault. Before I invest the time to create a new sulution I would like to ask you if there is no other posibility. In the exception there is the name of the method where the exception occours. You should be able to find the object that is null. If this is not possible, then I would suggest, to include more logging in the NDO.dll so that we can trace the error. Would it be possible to get an assembly with more logging included? We have allready a log-Adapter for log4net, so that we could see which object is null.

regards, Tobias
 5/2/2007 1:54:42 PM
Mirko
109 posts
5th


Re: NullReferenceException in Query

Hi Tobias,

we try to include as much as possible diagnostic code into NDO but we can't cover all situations with it. NDO relies heavily on the .NET base class libraries, which tend to return null or throw NullReference exceptions. All you can do is debugging as usual. Something is causing an object to be null and we have to discover, what it is. I'll send a version of the NDO.dll to your email address which shows the readable names of the methods in which the exception occurs. Run the code with the dll and send the name of the method to me.

Best Regards
Mirko

 5/3/2007 1:58:47 PM
schoetbi
15 posts


Re: NullReferenceException in Query
Hello Mirko,

thaks for the help. After going through all lists within the class, I saw that some Lists havent been initialized by the contructor. Unfortunaltelly I did the initialization code of the lists in a constuctor with an parameter. Therefore it was not called when NDO instatiates the object from the database.

I then implemented the default constructor explicitiley and inizialized the lists in the class... and everything worked fine.

Regards,
Tobias

  NDO-Forum postings in english please, if possible.  Developing with NDO  NullReferenceEx...
  SearchSearch  Forum HomeForum Home