Friday, October 29, 2010

Using UsageMode to Determine Design Time or Run Time

During design time editing of forms with custom user controls on them, strange errors began popping up relating to StructureMap. The issue is well documented on the internet, and is caused by controls firing the constructor when their parent form is opened in design mode. (A great explanation is provided here.) Since we had data access code in the constructor of the custom control which needed StructureMap initialized, but the Bootstrapper had not yet been called, the code would error out.

In order to work around this issue, I began testing for System.ComponentModel.UsageMode.Runtime(or DesignTime).

No comments:

Post a Comment