StrataFrame Forum

Exception when setting RequiredFields

http://forum.strataframe.net/Topic1523.aspx

By Andria Jensen - 6/13/2006

I'm getting the following error for one of my BO's when I try to set the RequiredFields property:

"An error occurred while attempting to load this type editor:
Exception has been thrown by the target of an invocation."

I can map it without error through the BO Mapper and I have created several other BO's without problems.  What could cause something like this?

By Trent L. Taylor - 6/13/2006

Andria,

Rebuild your solution (not just build) and if you still get the error, get out of Visual Studio and come back in and see if the error persists.  Most times this is due to VS trying to hold on to an assembly.

By Andria Jensen - 6/13/2006

I rebuilt and still had the same error, then closed all of VS and came back.  Still the same error.  Anything else that could cause this?
By Andria Jensen - 6/13/2006

Any suggestions on getting past this problem???  I'm kind of stuck working and can't go forward.
By StrataFrame Team - 6/14/2006

Are there any compiler errors within the project, or does it build properly?

Are you getting the same error within other business objects, or just that one business object.

If it is localized to a single business object, can you post the main code file and the designer file for the business object here on the forum (or email it to me) so I can step through it and see if we can track down the problem?

By Andria Jensen - 6/14/2006

It compiles fine and I even used it as a reference in another project.  I just can't get to the required fields.  I'm having the issue only with one other BO at this time.  I'm attaching the projects I'm having problems with and maybe you can tell me if I've done something wrong.  I followed the same steps I've taken to create a lot of other BOs, but these don't seem to work like the rest.
By StrataFrame Team - 6/14/2006

The reason it's throwing an exception is that you're filling the business object within the constructor.  When you are in the designer, all code within the constructor is executed at design-time because the designer creates instances of the objects at design-time.  When your objects are created, they're trying to fill themselves, and since the DataSource("") is the data source being used by StrataFrame, it cannot find your tables, and therefore cannot fill the business object at design-time.  Your best solution is to remove the FillDataTable method from the constructor and do one of two things: 1) Create a Shared "factory" method that will create new instances of the business objects and fill them before returning their references, or 2) Just manually call the FillDataTable method after the object is created.
By Andria Jensen - 6/14/2006

OK, that makes sense.  I can figure something else out to accomplish this.  A factory method will probably be a good way for me to go.  Thanks for the help!
By StrataFrame Team - 6/14/2006

Andria,

I forgot to mention that if you ever want to test on some code that should on run at design-time, you can use the ReadOnly DesignMode property, like this:

If Me.DesignMode Then

'-- Code that should only run at design-time

End If

Unfortunately, this won't help you in this case, because the DesignMode property will always return False (because it isn't set) until after the constructor exits.  So, once an object has been instantiated, you can test on the property, but until it has been set, you cannot use it. 

Oh, and the property is Protected, so you can only access it within the object (unless you wrap it in a public property).