winforms design time errors with custom usercontrol

winforms design time errors with custom usercontrol

Old forum URL: forums.lhotka.net/forums/t/7147.aspx


mr_fuku posted on Monday, June 22, 2009

Hey Rocky:

I have a NameValueList in a custom winforms usercontrol.

When I drag the usercontrol onto a form, it seems that the DataPortal_Fetch is being called (at design time) which naturally generates an error.

Here is the code from the usercontrol:

ClientsNVL clients = BoHelper.GetClientsNVL();
foreach (NameValueListBase<string, string>.NameValuePair client in clients)
{
  item = new RadComboBoxItem(client.Value, client.Key);
  cbSelectInst.Items.Add(item);
}


and from the BoHelper class:

[Cache(LocalCache.Key.Clients)]
public static ClientsNVL GetClientsNVL()
{
  return ClientsNVL.GetClientsNVL();
}


I find this to be very odd - meaning - why would the DataPortal_Fetch method be called from the designer when the application isn't running? I've used this design pattern previously in a web app and everything was fine. What am I doing incorrectly? I've been pulling my hair out over this one.

Thanks in advance for your thoughts and expertise!

Best,
Ted







mr_fuku replied on Monday, June 22, 2009

btw I seem to have gotten around this with the following snippet but it seems kind of ridiculous:

if (System.Diagnostics.Process.GetCurrentProcess().ProcessName !=devenv")
      {
         // load the combobox
      }

argh...

triplea replied on Monday, June 22, 2009

You usually get these errors when you have code executing in your constructor. Make sure you don't make a call to the DP from within your constructor(s) and that they are marked as private. Also sometimes you will find that if you close your solution, delete all the dll/exe files and rebuild these problems are resolved.

HTH

mr_fuku replied on Monday, June 22, 2009

thanks for getting back so quickly triplea - and yeah i'd seen a couple of posts about what your describing.

that being said, the only method call in the constructor is and has been the InitializeComponent() call...

this one has me stumped.

thanks for your thoughts.

triplea replied on Monday, June 22, 2009

I actually ment the constructor of your BO not the UI one. What is probably happening is that the UI is calling the constructor on your BO when rendering the view in the designer. If your BO constructor has got any logic that is calling the DP then you would get this error. So the question is, what do your constructor(s) look like?

mr_fuku replied on Monday, June 22, 2009

Ah - oivey! I misunderstood you...it's been one of those days hehe.

Anyhew, here is the bo constructor:

private ClientsNVL()
    { /* require use of factory methods */ }


The constructor of the usercontrol:

public CustomerEmploymentInfo()
    {
      InitializeComponent();
    }


And finally the constructor of the form which contains the usercontrol:

public frmCustomer()
    {
      InitializeComponent();
    }

Obviously not a lot going on there....

Just to mention, we have quite a bit of 3rd party controls and frameworks in this application:

Perhaps it has something to do with one of these (my guess would be the telerik stuff which is pretty but...suffice to say it has some odd behaviours that i've noticed over the life cycle of this project).

Also, this is my first foray into Winforms (typically I do asp.net dev) so obviously my experience is somewhat lacking.

Anyway, thanks again for your thoughts! This forum has been really great...and I really am a hardcore propoent of utilizing CSLA as the framework for the DAL.

Cheers!
-Ted

lukky replied on Tuesday, June 23, 2009

@mr_fuku,

Would be most helpful if you could provide the EXACT exception message, and also the call stack when the exception occurs.

Regards.

mr_fuku replied on Tuesday, June 23, 2009

@lukky:

please note that the spring context for this data portal call is specified in the web.config (since we're utilizing the remote data portal option over WCF). this works when the application runs perfectly well, but as i said in my previous posts it is at design time when the errors occur. thanks for your interest and i hope this is helpful.

the error message is as follows:

No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file.

and the call stack:

at PurchasingPower.ServiceHost.ServiceManager.get_ApplicationContext() in C:\!!development\trunk\PurchasingPower.ServiceHost\ServiceManager.cs:line 54
at PurchasingPower.ServiceHost.ServiceManager.GetClientService() in C:\!!development\trunk\PurchasingPower.ServiceHost\ServiceManager.cs:line 124
at PurchasingPower.ServiceHost.ServiceManager.get_ClientService() in C:\!!development\trunk\PurchasingPower.ServiceHost\ServiceManager.cs:line 95
at PurchasingPower.BusinessObjects.Clients.ClientsNVL.DataPortal_Fetch() in C:\!!development\trunk\PurchasingPower.BusinessObjects\Clients\ClientsNVL.cs:line 52
at dm(Object , Object[] )
at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters)

Copyright (c) Marimer LLC