Windows Form Databinding Error

Posts   
 
    
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 07-Nov-2006 13:34:17   

Hi,

Version: 2.0.0.0 Final Released: July 6th, 2006 ORMSupportClasses.NET20: 2.0.0.60701 Platform: .NET 2.0 Template Group: Adapter Language: C# .NET Version: 2.0.50727 Environment: Windows Forms Database Type: SQL Server 2000 OS: Windows XP

Full stack trace at the end.

I've seen one other thread that seems to address this (see the link below), but I'm not understanding the solution. I've done a couple of simple drag/drop databinding tests doing the following steps:

  1. Drag an Entity collection object onto a new form

  2. Select the entity factory

  3. Drag a binding source onto form

  4. Set the binding source DataSource property to the entity collection above

    • Other Data Sources
    • Image List instances
    • Select the name of the entity collection
  5. Pull data in the Load event to display in fields as defined below.

I've then either drag a DataGridView (for a list view) or a binding navigator associated with individual controls I drag to the form using simple binding to the entity collection members.

At this point I run the form and properly see the data. Everything thing is (seems) fine.

However, seemingly randomly, I'll make changes like adding a new event and the data binding breaks with the following error:

Error: {"Cannot bind to the property or column ImgPk on the DataSource.\r\nParameter name: dataMember"}

Today the only thing I did was clicked on a PictureBox control and added a DragDrop event. I then placed a couple of variable assignments in the event just to trace to see if the event was being fired properly. When I ran the project I received the error above.

This happened last week in my initial experimentation with binding the collection control with a completely different table.

Am I making a newb error of some kind?

Thanks in advance!

Related(?) post: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3721&StartAtMessage=0&#20391

StackTrace " at System.Windows.Forms.BindToObject.CheckBinding()\r\n at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager)\r\n at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)\r\n at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)\r\n at System.Windows.Forms.BindingsCollection.Add(Binding binding)\r\n at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)\r\n at System.Windows.Forms.Control.UpdateBindings()\r\n at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)\r\n at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)\r\n at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)\r\n at System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value)\r\n at System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value)\r\n at System.Windows.Forms.ContainerControl.get_BindingContext()\r\n at System.Windows.Forms.Control.get_BindingContextInternal()\r\n at System.Windows.Forms.Control.get_BindingContext()\r\n at System.Windows.Forms.Control.UpdateBindings()\r\n at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)\r\n at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)\r\n at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)\r\n at System.Windows.Forms.ContainerControl.OnCreateControl()\r\n at System.Windows.Forms.Form.OnCreateControl()\r\n at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n at System.Windows.Forms.Control.CreateControl()\r\n at System.Windows.Forms.Control.WmShowWindow(Message& m)\r\n at System.Windows.Forms.Control.WndProc(Message& m)\r\n at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n at System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n at System.Windows.Forms.Form.WmShowWindow(Message& m)\r\n at System.Windows.Forms.Form.WndProc(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)\r\n at System.Windows.Forms.Control.SetVisibleCore(Boolean value)\r\n at System.Windows.Forms.Form.SetVisibleCore(Boolean value)\r\n at System.Windows.Forms.Control.set_Visible(Boolean value)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run(Form mainForm)\r\n at Magazines.Program.Main() in C:\\projects\\test\\FormTest2\\Magazines\\Magazines\\Program.cs:line 14\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()"

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 07-Nov-2006 15:37:57   

Hello,

where did you add the event wich break the databinding in your first case? On your datagridview, is editing working well or does it throw you an exception too?

Could you post some of your code for sample?

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 07-Nov-2006 16:22:15   

jbb wrote:

Hello,

where did you add the event wich break the databinding in your first case? On your datagridview, is editing working well or does it throw you an exception too?

Could you post some of your code for sample?

Hi,

This is on a secondary computer that I don't have access to right now and I don't remember where the exception was originally thrown. I believe in the Load event since that's where the code is that does the binding, but I'm not sure.

If this doesn't ring an immediate bell, I'll see if I can come up with conditions that duplicate this on my side since it's not consistently reproducible. It's happened twice now (although in fairly simple scenarios), but it may very well be something I'm doing on my side that triggers it.

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 07-Nov-2006 16:32:01   

Hi,

in a winform the load method only needs to be call once so your databinding only needs to be call once. If the problem was throw in the load event, did the binding is really made and your grid working? Do you try to modify the entitycollection wich is the datasource of your grid? And if you add no more event all is working well?

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 08-Nov-2006 10:50:49   

jbb wrote:

Hi,

in a winform the load method only needs to be call once so your databinding only needs to be call once. If the problem was throw in the load event, did the binding is really made and your grid working? Do you try to modify the entitycollection wich is the datasource of your grid? And if you add no more event all is working well?

The exception is being thrown during the construction of the form somewhere. If I debug the form, I can step through the entire InitializeComponent() of the designer and step out of the constructor. When I click Step Over after it leaves the constructor, the exception is thrown at the Application.Run.

Another clue to add:

After I dropped the components on a brand new form and had it successfully working I saved the code for the Form1.Designer.cs. I then changed the AllowDrag property to true. I simply tried to save the form and received the following error immediately:

Code generation for property 'EntityFactoryToUse' failed. Error was: EntityFactory2Converter is unable to convert ImageEntityFactory to System.ComponentModel.Design.Serialization.InstanceDescriptor.

After I clicked the OK button, I was able to save the form. However when I ran the form I received the exception I mentioned at the beginning of this forum thread.

When I do a diff on the new broken designer code compared to the original designer code that worked, it appears the only difference is the order in which various things are being assigned (the initialization of the data binding components seems to all be there, but in a different order). I haven't done an exhaustive comparison yet (because there are dozens of lines moved around) but I suspect the answer lies in the fact that the designer is moving initialization code that is ultimately causing the exception.

If I take the original designer code that worked and replace the broken designer code, all is well again. I can run the form, step through records, close the form, run it again, etc. All is well.

I still don't understand the exact trigger that causes the exception because I'd actually been using the form this morning to experiment with a number of events without problem. I then remove an event in the properties window and when I tried to save, I received the save error mentioned above (the EntityFactoryToUse error). So you can't just duplicate by following my instructions and adding an event or two... there's something else here that I haven't quite put my finger on, but it may have to do with removing events from the designer, and the designer reorganizing the initialization code to the point the exception occurs.

With that said, I suspect I can take the broken designer code, figure out the original order of initialization that was working, and get the broken designer code to work (I'm just guessing at this point, but it seems I'm getting close to what's going on).

John

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 08-Nov-2006 11:00:57   

Bingo!

Here's the single line of code in the original working designer that is missing from the broken designer code:

this.entityCollection1.EntityFactoryToUse = new Generated.FactoryClasses.ImageEntityFactory();

After I add this line back to the broken designer code, it works. So something is going on when I simply change properties or add events that causes the designer to remove the line of code above.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39889
Joined: 17-Aug-2003
# Posted on: 08-Nov-2006 11:29:20   

Seems like serialization (that's the term MS uses for this) of the objects on a design canvas to code (which means it generates the initializecomponent method with all the goo) of the object sometimes fails. I haven't seen this myself with entitycollections nor heard about this before but it sometimes happens. I run into this myself in the llblgen pro designer with the objectselector usercontrol: vs.net refuses to generate a line of code which instantiates the control on the designer so I can't design the form.

There's a hotfix for this I pressume. You can download it here: https: //connect.microsoft.com/content/content.aspx?ContentID=3705&siteid=210&wa=wsignin1.0

it's KB912019

Frans Bouma | Lead developer LLBLGen Pro
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 08-Nov-2006 11:35:21   

Just saw your post and will try the hotfix. I'd already written the following before I'd seen your post.

Very strange. In experimenting with this project to find the trigger, I deleted my existing form and created a new one. I dragged the EntityCollection onto the form, renamed it, and then tried to save. I immediately received the EntityFactoryToUse error on saving. When I looked at the designer code, sure enough the EntityFactoryToUse assignment was missing. I deleted this form and tried it twice more and received the same error at the same point. I haven't noticed this error this early in the process before. It had been after I'd changed properties or added events previously.

I then quit Visual Studio 2005 and restarted it. The EntityCollection was automatically showing up in this project in the Toolbox under the section for the project components. I know I can manually add it to the project, but it's very strange that after I started duplicating this error, all of a sudden the EntityCollection is no longer automatically showing in the toolbox. I recompiled the entire project and restarted Visual Studio again and it just isn't showing up automatically any longer. I'll try manually adding it back to the toolbox next and see happens.

Note that I have not regenerated or modified the LLBL projects or auto generated code in any way over the past few days. I could understand the EntityCollection perhaps not showing up if I'd modified the auto generated code in same way (it would be easier to understand a direct cause and effect here anyway).

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 08-Nov-2006 11:44:15   

Otis wrote:

Seems like serialization (that's the term MS uses for this) of the objects on a design canvas to code (which means it generates the initializecomponent method with all the goo) of the object sometimes fails. I haven't seen this myself with entitycollections nor heard about this before but it sometimes happens. I run into this myself in the llblgen pro designer with the objectselector usercontrol: vs.net refuses to generate a line of code which instantiates the control on the designer so I can't design the form.

There's a hotfix for this I pressume. You can download it here: https: //connect.microsoft.com/content/content.aspx?ContentID=3705&siteid=210&wa=wsignin1.0

it's KB912019

Hmmm... the link you posted doesn't seem to work. I did find the hotfix link on the Microsoft site and when I try to follow their download link and sign in using my passport account I'm taken to a Page Not Found page with a message that states that the content I requested cannot be found OR I do not have permission to view it.

KB Article http://support.microsoft.com/kb/912019

John

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39889
Joined: 17-Aug-2003
# Posted on: 08-Nov-2006 12:04:38   

Could it be you added a beta-version of the ORMSupportClasses to the toolbox? (which contained EntityCollection before it was moved to the genrated code) ?

I think it's similar to what is experienced in the designer, when the designer asks vs.net to get all the IEntityFactory2 implementing types available in the current solution and it comes up with nothing, because the ORMSupportClasses instance in vs.net's appdomain is different from the one used by the solution... disappointed

I thought anyone with an MS passport could access that link. It's https, not http, perhaps that's the issue, I'm not sure.

Frans Bouma | Lead developer LLBLGen Pro
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 08-Nov-2006 12:05:55   

I manually added EntityCollection back to the toolbox by browsing to the generic dll. One thing I'd noticed before when I'd done this is that when I manually add the dll, the choices I have for EntityCollection include one with an apostrophe-like character in the name EntityCollection`1 (this is the apostrophe available on the tilde key). It normally forces you to select both of them at the same time (if you deselect the one with the funny character the normal one is deselected also). It seems regardless of how you manually select EntityCollection, I still end up with two of them in my toolbox. Either one seems to work and creates exactly the same references. Is this normal?

Anyway, once I manually dragged EntityCollection back onto the toolbox, all is normal again. I can rename without it throwing errors and step through my records. I haven't gone so far as trying to change properties and add events to see if the designer looses the reference, but at this point I'll just manually add the missing assignment back.

[Edit an hour or so later]

So far I haven't received any further errors after making quite a few changes. Perhaps the EntityCollection that was automatically showing up was causing the problem. I don't remember ever adding a beta version of EntityCollection to the toolbox, but perhaps I did.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39889
Joined: 17-Aug-2003
# Posted on: 08-Nov-2006 13:11:44   

The ~1 one is the generic one (EntityCollection<T>), which you shouldn't use as databinding can't deal with generics. I pressume this question is now solved?

Frans Bouma | Lead developer LLBLGen Pro
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 08-Nov-2006 13:18:38   

Otis wrote:

The ~1 one is the generic one (EntityCollection<T>), which you shouldn't use as databinding can't deal with generics. I pressume this question is now solved?

Yes, thank you very much for your support!!