Exception has been thrown by the target of an invocation.


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I received the following error when navigating away from an instance of the DevEx XtraGrid (bound to a BO via a BBS):

">

I have tried updating the framework (1.6.6 released version), then I tried updating to the most recent DevEx version (8.2.4).  I have removed the grid and replaced it with another instance.  All attempts have resulted in the same behavior.

Does anyone have any idea why the XtraGrid is causing this error to popup?  Btw, I can answer 'No' and continue using the form.  I'd really like to use the XtraGrid rather than the EnhancedList (which is nice, but lacks a couple of necessary features). 

Thanks for your help!
Bill

Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Bill,



Doubt that this is it, but you probably ought to check value against null AND DbNull.Value, in that order. The first checks if any record was returned, the second if the value returned was NULL. Again, I doubt this is your problem, but it could bite you at some point.
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Without you setting up a sample that reproduces the behavior it is going to be hard for me to tell you what to do exactly.  I do know, however, that this is more than likely something that needs to be first addressed in the BO to account for NULLs, and then you may have to set a property somewhere in the grid if the problem persists...so past some of the recommendations that I have made or Greg has made it is going to be hard to give you any answers....sorry Ermm
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I did provide a sample project that does exactly what I am describing (see earlier post).  I will try the double null/DBNull.value check.  Thanks.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
if (loValue == null || loValue == DBNull.Value)

This does not change anything.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I ran your sample, and it did not work.  Not SF, but your query would not ever work.  I did reproduce your problem once I made the query work.  The bottom line is that you are using a this.CurrentRow["ItemsCount"] without actually having that column in the data table.  When the Dispose fires, that strong-type field is being evaluated and thus the error.

I have reattached the sample (I had to change the references to 8.1 since I haven't dowloaded 8.2).  But this had nothing to do with the grid or or SF for that matter. 

If you want to reference a field in the data table, make sure it is there otherwise the error will occur.  You can also do real-time aggregate calculations if you have the need when the property is evaluated....though you could run into performance issues there if an additional query is taking place.

Also, your query would not work

SELECT * AS ItemsCount FROM Movies

That query will never work since you cannot place a wildcard into a single column name.  I changed to this just to create the column, but you could do a query and figure out your aggregates, etc.

SELECT Movies.*, Movies.mv_pk AS ItemsCount FROM Movies

I know that pushing the PK into this column doesn't do anything of value here, but it should at least get the point across.

But in regards to your problem, that was it here.

Attachments
DataGridTest.zip (142 views, 125.00 KB)
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Please read all of my posts...I am trying to be as thorough as I can so I can get the surgical, precision-type help that I need.

The thread immediately following my sample post explained the incorrect SQL that was in the sample.

And, yes, I also subsequently provided information about manually adding the column to the datatable during data table initialization or refill.  It appeared to solve the problem in the test sample, but failed to solve the problem in my application.

If the column exists because I manually add it, then I get the casting problem. 

Using either a check on "null" and/or "DBNull.Value" does nothing to get me past the error.

The error popup does not supply any debug information.  I am lost when it comes to "seeing" what actually is causing the problem.  I am assuming a casting issue because the DataGridView responds with more information which I assume is the same problem that the DevEx GridView is having.  Big assumption on my part, I think.

I'll keep trying and continue to post results on this thread.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Bill, as I have mentioned in previous posts as well, I cannot help you without a good sample.  I don't want to have to piece all of this together in hopes that I reproducing your problem.  I would rather have a sample in my hands that reproduces your problem so that I can help you.  I downloaded your sample, reproduced the error, made it work and reposted it.  If that was not your problem, then please post another sample that does accurately reproduce the issue.  Going back and forth will not get your problem resolved otherwise it would have happened already. 
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Bill, as I have mentioned in previous posts as well, I cannot help you without a good sample.  I don't want to have to piece all of this together in hopes that I reproducing your problem.  I would rather have a sample in my hands that reproduces your problem so that I can help you.  I downloaded your sample, reproduced the error, made it work and reposted it.  If that was not your problem, then please post another sample that does accurately reproduce the issue.  Going back and forth will not get your problem resolved otherwise it would have happened already. 

I have already shown you how to reproduce the error.  You can reproduce the error even with your updated sample project.  It's easy to reproduce.  I am unable to provide you more than that.

That was exactly my point, Bill!!!!!

YOU MUST either pull back a value from the server as a column that represents the custom property you are trying to pull (ItemsCount) or perform some type of calculationo with the data that you did pull back...using your query YOU DO NOT HAVE A COLUMN named ItemsCount that can be accessed from the CUrrentRow of the BO!!!!!

I don't think I see your point.  What point are you referencing?  Do you see my point?  I do not want the custom property referenced in the grid.  Why should I even reference it in my query?  If the custom property has to be reference in every query, then to fill the BO "Select * from MyTable" should never work.  I should always get an eval error along the way somewhere.


Here's another piece of the puzzle...remove the grid and throw text boxes onto the form to reference the same three fields.  Open the form, navigate to a few records, then close the form.  NO ERROR!!!  So, something is up with the grid via the BBS.  I should be able to add a grid, connect it to the same BO through a BBS, show the same three fields in the grid and it should work.  It doesn't.  Closing the form generates an error.

That is what I am looking for an explanation on.  If the BBS somehow forces the custom property to be evaluated, then how do I turn that off on an instance by instance basis?  On some forms, I want that custom property to show on a grid...on others, like this one, I do not.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Bill,



I'm not sure if this will help (the last suggestion didn't Sad ), but maybe...



When you have a custom property that is using code like:



this.CurrentRow["ItemsCount"]




this means that there must a column in the data table named "ItemsCount". Apparently, this column will get called when the BO is disposed (didn't know that), if the data table doesn't have that column it will break. So, you just have to code for that. In cases like this (were I don't always want or need the value from a custom property and want to get the data from the underlying data table), I've started using code like this within my property getter:



if this.CurrentDataTable.Columns.Contains("ItemsCount")

{

  if this.CurrentRow["ItemsCount"] != null && this.CurrentRow["ItemsCount"] != DbNull.Value

  {

    return this.CurrentRow["ItemsCount"];

  } else

    return 0;

  }

} else

{

  return 0;

}




With this code (hopefully my C# is close enough to understand), it returns the value from the datatable if the column has been loaded and if the value is set, otherwise it returns zero. For any situations where I need to use the custom property, I make sure I include the appropriate SQL to load that column.



Hope this gets you closer! I know your frustration in learning this stuff! Pinch

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Thanks, Greg.  The code works in the test project using a simple "SELECT * FROM Movies" query.  I will see how it behaves in my application.  Stand by.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Using a DataGridView . . . success.

Using a DevEx GridControl . . . failure. 

The same error popup on window close: "Exception has been thrown by the target of an invocation. Do you want to correct the value?  Yes.  No."  If I select "Yes" the window stays open.  If I select "No" the window closes.

The version of the DevEx GridControl is 8.2.4.  I am running on the latest SF release 1.6.6.  I will try to put this into the support and forums of DevEx.  Maybe someone there can provide some further direction.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
You can put this on the DevEx support forum, but it won't help you any.  This has nothing to do with the grid other than the fact that the field is being evaluated on a Dispose.

I know that you don't get what I am telling you, and Greg has tried to tell you the very same thing that I have been trying to tell you.

So let's start over.  You have asked for help, you created a sample that reproduced the problem.  I downloaded the sample that you gave and reproduced the problem on the version 8.1 grid.  I showed you an example of how to resolve the error by trying to make you understand that if you are going to create a custom property that relies on an underlying column pulled back from a query...that column must exist in the result set!!! 

For example, you can't create a custom property that attempts to pull from the CurrentRow if that column isn't within the CurrentDataTable.

You are welcome to post another sample if your first sample did not accurately depict your problem, which at this point it apparently did not since I corrected it and reposted it and you are still not pleased with the results.

If you do not supply "surgical precision-type" help, then you need to supply "surgical precision-type" details, otherwise we cannot help.

We have tried for a week now to help you with this problem and have gotten nowhere other than some frustrated and caustic remarks.  So let's take the emotion out of the equation and start over....by starting with a sample that accurately depicts your problem.  Past that, the bantering back and forth has not gotten anywhere and we are a week into the problem with no resolution....though I and Greg both seem to understand your problem, we cannot seem to make you understand the underlying issue.  So at this point, let's go back to the sample, create one that shows exactly what you are trying to do since you did not like my previous answer, I will correct it and repost it.

Thanks.

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
You have misinterpreted what I have been writing.  I am not at all intending to be caustic in my remarks.  There is no professionalism in that.  I am extremely grateful for every snippet of help given.  As I implement the ideas supplied here and attempt to fix my problem, I only report back to the forum what is happening.  If I do not follow a certain logic, I mention it.  Not trying to be a dork here.  Perhaps it looks that way.  Sorry.
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
No worries, we are good, I just want to help you get your problem resolved...and I am sure that you have no issue with that goal either Hehe

So that is why I was suggesting going at another sample that more accurately represents your problem so that we can hopefully get to the bottom of this.

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
When the Dispose fires, that strong-type field is being evaluated and thus the error.

This statement intrigues me.  If the custom property object is null then the return value is always zero (0) of type decimal.  Why would there be an error thrown at that time?  It is not thrown when the object is created.

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Change this . . .


public void FillAll()
{
    FillDataTable(
"SELECT Movies.*, mv_pk As ItemsCount FROM Movies");
}

. . . to this . . .


public void FillAll()
{
    FillDataTable(
"SELECT Movies.* FROM Movies");
}

. . . and the error occurs.  I do not understand.  The column should evaluate as null, therefore return a value of zero.  Why does this error?  What if all I wanted was to list the movie titles (SELECT mv_Title FROM Movies) and display the results in a grid, would this not be a valid query since custom properties are involved in the BO?  Should I always have to fill the custom properties with something (SELECT mv_Title, 0 AS ItemCount FROM Movies) even if I am not going to reference the custom property(-ies), or any other property (e.g. mv_Year, mv_Rating, etc.)?

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
That was exactly my point, Bill!!!!!

YOU MUST either pull back a value from the server as a column that represents the custom property you are trying to pull (ItemsCount) or perform some type of calculationo with the data that you did pull back...using your query YOU DO NOT HAVE A COLUMN named ItemsCount that can be accessed from the CUrrentRow of the BO!!!!!

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
                 Sonds goods...:)
Trent L. Taylor - 17 Years Ago
Bill Cunnien - 17 Years Ago
                         Just to reiterate...the error does not appear with a DataGridView...
Bill Cunnien - 17 Years Ago
                         We have developers using a DevExpress grid and BBS objects every day....
Trent L. Taylor - 17 Years Ago
                             From going back and rereading your previous posts, it just sounds like...
Trent L. Taylor - 17 Years Ago
                             The details are quite simple (sample app attached). 1) Create form....
Bill Cunnien - 17 Years Ago
                                 The following data retrieval method was not updated properly before I...
Bill Cunnien - 17 Years Ago
                                     I duplicated the details I found in the designer file of a BO and this...
Bill Cunnien - 17 Years Ago
                                         Adding the following fixes the problem. [codesnippet] private...
Bill Cunnien - 17 Years Ago
                                             It worked on the test solution, but my application is not responding...
Bill Cunnien - 17 Years Ago
                                                 Here is the most recent error message for us to work with...
Bill Cunnien - 17 Years Ago
                                                     This looks like you may need to take something into account within...
Trent L. Taylor - 17 Years Ago
                                                         Yup...you are right...it is a custom property. Here is the code (the...
Bill Cunnien - 17 Years Ago
                                                             Here is another exception. This one comes about by removing the...
Bill Cunnien - 17 Years Ago
                                                                 EUREKA!! :w00t: :w00t: :w00t: Instead of evaulating the object...
Bill Cunnien - 17 Years Ago
                                                                     Stop the presses! The DevEx XtraGrid is not behaving. It still pops...
Bill Cunnien - 17 Years Ago
                                                                     Bill,

Doubt that this is it, but you probably ought to...
Greg McGuffey - 17 Years Ago
                                                                         Without you setting up a sample that reproduces the behavior it is...
Trent L. Taylor - 17 Years Ago
                                                                             I did provide a sample project that does exactly what I am...
Bill Cunnien - 17 Years Ago
                                                                                 [codesnippet] if (loValue == null || loValue == DBNull...
Bill Cunnien - 17 Years Ago
                                                                                     I ran your sample, and it did not work. Not SF, but your query would...
Trent L. Taylor - 17 Years Ago
                                                                                         Please read all of my posts...I am trying to be as thorough as I can...
Bill Cunnien - 17 Years Ago
                                                                                             Bill, as I have mentioned in previous posts as well, I cannot help you...
Trent L. Taylor - 17 Years Ago
                                                                                                 [quote]Bill, as I have mentioned in previous posts as well, I cannot...
Bill Cunnien - 17 Years Ago
                                                                                                     Bill,

I'm not sure if this will help (the last suggestion...
Greg McGuffey - 17 Years Ago
                                                                                                         Thanks, Greg. The code works in the test project using a simple...
Bill Cunnien - 17 Years Ago
                                                                                                             Using a DataGridView . . . success. Using a DevEx GridControl . . ....
Bill Cunnien - 17 Years Ago
                                                                                                                 You can put this on the DevEx support forum, but it won't help you...
Trent L. Taylor - 17 Years Ago
                                                                                                                     Youhave misinterpreted what Ihave beenwriting. I am not at all...
Bill Cunnien - 17 Years Ago
                                                                                                                         No worries, we are good, I just want to help you get your problem...
Trent L. Taylor - 17 Years Ago
                                                                                         [quote]When the Dispose fires, that strong-type field is being...
Bill Cunnien - 17 Years Ago
                                                                                             Change this . . . [codesnippet] public void FillAll() {...
Bill Cunnien - 17 Years Ago
                                                                                                 That was exactly my point, Bill!!!!! YOU MUST either pull back a...
Trent L. Taylor - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search