HELP! circular assembly reference
Hi,
I have a custom text box control that fires rules on the text leave event.
To fire the rules I need the ruleset and rules execution parameters to be passed from the form.
I was doing this using the following code
privatevoid TextEditor_Leave(object sender,EventArgs e)
{
BaseForm FindForm =(BaseForm)this.FindForm();
if (null != FindForm.ruleExecution)
{
try
{
FindForm.ruleSetDataSet.RuleSet.Execute(FindForm.ruleExecution);
}
catch (Exception ex)
{
//MessageBox.Show("Exception thrown \n" + ex.Message);
}
}
else
{
// MessageBox.Show("RuleExecution is null");
}
}
This code has created a circular assembly reference because the baseform references the controls library but to accept the baseform I need to set a reference from my contol library to the baseform library.
Does anyone know how I could get these parameters to my control without having to reference the the baseform usingBaseForm FindForm =(BaseForm)this.FindForm(); ?
A colleague mentioned something about using the Invoke() method, can this be used?
Thanks.
MS gets away with this by first compiling one of the assemblies against a dummy assembly, then compiling the other assembly, and then recompiling the original assembly, or some nonesense. Frankly, I think you're better off reorganizing you're dlls to remove this circular dependency.
>> i have been told they dont want it done that way or using interfaces.
Let's recap:
1) You have a problem, but
2) "They" refuse to let you use the simple tools designed specifically to deal with that exact problem, but would apparently rather you use a complex, obscure and slow alternative.
Hmmm.... Would beating them over the head with a stick help?
The one correct answer is that you need to create an interface, say IUsesRules, defined in the same assembly as your TextEditor class. It would look something like this:
1: public interface IUsesRules
2: { 3: RuleType1 ruleExecution { get; } 4: RuleType2 ruleSetDataSet { get; } 5: }
(You'll have to fill in th ecorrect data types for RuleTYpe1 & RuleType 2). Then you would code the event handler as:
1: private void TextEditor_Leave(object sender, EventArgs e)
2: { 3: IUsesRules FindForm = this.FindForm() as IUsesRules;
4: if (FindForm != null && null != FindForm.ruleExecution)
5: { 6: try
7: { 8: FindForm.ruleSetDataSet.RuleSet.Execute(FindForm.ruleExecution);
9: }
10: catch (Exception ex)
11: { 12: //MessageBox.Show("Exception thrown \n" + ex.Message); 13: }
14: }
15: else
16: { 17: // MessageBox.Show("RuleExecution is null"); 18: }
19: }
20:
Note that remarkably little has changed (and even less would have changed if I'd left the potenial bug in the code). The definition of BaseForm changes even less. It goes from
class BaseForm : Form
to
class BaseForm : Form, IUsesRules
That's it. I'm sure the resistance to using an interface is base solely on cluelessness on the speakers part (let me guess A VB6 consultant now trying to pass himself off as a .Net expert?)