Design Time UserControl Error

Topics: Data Access Application Block
Jul 18, 2008 at 1:44 AM
Edited Jul 18, 2008 at 2:31 AM
Hi,

I am using the EntLib 4.0 library to build my companies latest and greatest application. I am utilizing the Data, Logging, and Validation application blocks thus far.

I have used the EntLib configuration editor to create my config file.

What I have is this. A user control (very basic) that initializes a controller class which in turn initializes a data provider. After I develop the control and drop it on the parent form, there are  no issues. However, when I close down the solution, reopen it, and try to open the parent form, I get the error message below:

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.GetConnectionStringSettings(String name)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

I have recreated the identical problem three times.

The interesting thing is, when I run the application, the control works just fine and there are no compilation errors or warnings.

Also, I completely deleted the user control from the parent form and tried to drag and drop the control back onto the form and got the following error message:

Failed to create component 'ctlModule'. The error message follows:
'Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build
Key[Microsoft.Practices.EnterpriseLibrary.Data.Dabase, null]) failed: The value can not be null or an empty string.
(Strategy type
Microsoft.Practives.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationObjectStrategy, index 2) --->
System.ArgumentException: The value can not be null or an emptry string.
  at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.GetConnectionStringSetting(String
name)
  at Microsoft.Practices.EnterpriseLibrary.Dat.DatabaseCustomFactory.CreateObject(IBuilderContext context,
String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
  at icrosoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.PreBuildUp(IBuilderContext context)
  at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
  --- End of inner exception stack...'

Anyone know what might be happening here?

Thanks in advance,
Pat
Jul 18, 2008 at 2:43 PM
Hi,

You're probably trying to use EntLib while in design mode. If that's the case, this thread should provide you the information you need http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=27518; even though it's related to an ASP.NET control, the concepts are the same for WinForms controls.

Hope this helps,
Fernando


cdkisa wrote:
Hi,

I am using the EntLib 4.0 library to build my companies latest and greatest application. I am utilizing the Data, Logging, and Validation application blocks thus far.

I have used the EntLib configuration editor to create my config file.

What I have is this. A user control (very basic) that initializes a controller class which in turn initializes a data provider. After I develop the control and drop it on the parent form, there are  no issues. However, when I close down the solution, reopen it, and try to open the parent form, I get the error message below:

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.GetConnectionStringSettings(String name)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

I have recreated the identical problem three times.

The interesting thing is, when I run the application, the control works just fine and there are no compilation errors or warnings.

Also, I completely deleted the user control from the parent form and tried to drag and drop the control back onto the form and got the following error message:

Failed to create component 'ctlModule'. The error message follows:
'Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build
Key[Microsoft.Practices.EnterpriseLibrary.Data.Dabase, null]) failed: The value can not be null or an empty string.
(Strategy type
Microsoft.Practives.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationObjectStrategy, index 2) --->
System.ArgumentException: The value can not be null or an emptry string.
  at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.GetConnectionStringSetting(String
name)
  at Microsoft.Practices.EnterpriseLibrary.Dat.DatabaseCustomFactory.CreateObject(IBuilderContext context,
String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
  at icrosoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.PreBuildUp(IBuilderContext context)
  at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
  --- End of inner exception stack...'

Anyone know what might be happening here?

Thanks in advance,
Pat


Jul 18, 2008 at 7:59 PM
Hi,

Thanks for replying.

The link you provided sounds similar but does not correct my issue.

Here is my solution structure:
[DLL] Security
 - Controller classes
[DLL] Data
 - DataProvider classes
[EXE] WindowsClient
 - Controls
    - ctlModule
 - app.config

The ctlModule user control initializes the security.controller class which initializes a data provider class (_db = new DataProvider(); ) . The data provider class uses the default dabase from the configuration (app.config). I added the if(!this.DesignMode){ InitController(); }, but the error continues to prevail.

So I tried an experiment. I created a new control to do the same thing and made sure I only initialized objects when not in design mode. That failed as well.

This error only started happening after I initially developed the control and put it on the form. After I had closed the form and reopened it did this error start happening.

Cheers,
Pat

Jul 18, 2008 at 8:12 PM
Hi,

If you get this error then at some point you're trying to instantiate runtime objects at design time. Is it possible you're initializing objects in the constructor? If that's the case, it would explain why you're still getting the exception: the value for the DesignMode property depends on the component being sited, which can only happen after the constructor is done. However, it wouldn't explain why don't see the issue when you add the object for the first time.

Try initializing your custom control out of the constructor, and if you still can't figure out what's going on attach a debugger to VisualStudio and set up a breakpoint on the failing Enterprise Library code.

Hope this helps,
Fernando


cdkisa wrote:
Hi,

Thanks for replying.

The link you provided sounds similar but does not correct my issue.

Here is my solution structure:
[DLL] Security
 - Controller classes
[DLL] Data
 - DataProvider classes
[EXE] WindowsClient
 - Controls
    - ctlModule
 - app.config

The ctlModule user control initializes the security.controller class which initializes a data provider class (_db = new DataProvider(); ) . The data provider class uses the default dabase from the configuration (app.config). I added the if(!this.DesignMode){ InitController(); }, but the error continues to prevail.

So I tried an experiment. I created a new control to do the same thing and made sure I only initialized objects when not in design mode. That failed as well.

This error only started happening after I initially developed the control and put it on the form. After I had closed the form and reopened it did this error start happening.

Cheers,
Pat




Jul 18, 2008 at 8:38 PM

Eureka!

The problem was that I was initializing the view in the Ctor of the control. Once I moved the initialization into the load event all was well.

Thanks for your help!!

Cheers,

Pat


fsimonazzi wrote:
Hi,

If you get this error then at some point you're trying to instantiate runtime objects at design time. Is it possible you're initializing objects in the constructor? If that's the case, it would explain why you're still getting the exception: the value for the DesignMode property depends on the component being sited, which can only happen after the constructor is done. However, it wouldn't explain why don't see the issue when you add the object for the first time.

Try initializing your custom control out of the constructor, and if you still can't figure out what's going on attach a debugger to VisualStudio and set up a breakpoint on the failing Enterprise Library code.

Hope this helps,
Fernando


cdkisa wrote:
Hi,

Thanks for replying.

The link you provided sounds similar but does not correct my issue.

Here is my solution structure:
[DLL] Security
 - Controller classes
[DLL] Data
 - DataProvider classes
[EXE] WindowsClient
 - Controls
    - ctlModule
 - app.config

The ctlModule user control initializes the security.controller class which initializes a data provider class (_db = new DataProvider(); ) . The data provider class uses the default dabase from the configuration (app.config). I added the if(!this.DesignMode){ InitController(); }, but the error continues to prevail.

So I tried an experiment. I created a new control to do the same thing and made sure I only initialized objects when not in design mode. That failed as well.

This error only started happening after I initially developed the control and put it on the form. After I had closed the form and reopened it did this error start happening.

Cheers,
Pat







May 15, 2009 at 4:35 PM

Thanks . Your explanation solved one of my problems.