
We recently received the sample code that integrates the Windows Workflow Re-hosted Designer with the Syntax Editor control. So far, we have been very impressed with the whole suite of WPF tools, documentation, the sample code provided, and specifically the Syntax Editor control with the .NET Languages Add-on.
We did encounter a problem with custom assemblies being loaded in the "projectAssembly.AssemblyReferences" in the Windows Workflow sample, and I am wondering if the forum could propose a solution.
The Issue
The Re-hosted Windows Workflow Designer uses IExpressionEditorService and IExpressionEditorInstance to allow replacing the default editor control with a different control. In this case, we want to use the SyntaxEditor because of it's great syntax highlighting and intellisense.
When the Re-hosted Windows Workflow Designer detects the user gave focus to the editor control, it calls the IExpressionEditorService to request an Editor control instance. A new IExpressionEditorInstance is created which encapsulates the SyntaxEditor control. During the constructor, the code loads any required assemblies so that the SyntaxEditor .Net Languages Add-on can provide intellisense. In the following example, I hard coded a custom dll.
private void DotNetProjectAssemblyReferenceLoader(object sender, DoWorkEventArgs e)
{
// Add some common assemblies for reflection (any custom assemblies could be added using various Add overloads instead)
projectAssembly.AssemblyReferences.AddMsCorLib();
projectAssembly.AssemblyReferences.Add("System");
projectAssembly.AssemblyReferences.Add("System.Core");
projectAssembly.AssemblyReferences.Add("System.Xml");
projectAssembly.AssemblyReferences.AddFrom(@"C:\Test\Custom.dll");
}
This works great the first time the IExpressionEditorInstance is created.
But, if the user moves focus away from the editor control, and then back again...the Re-hosted Windows Workflow Desiger creates a new IExpressionEditorInstance. Subsequent calls to the following code will fail.
projectAssembly.AssemblyReferences.AddFrom(@"C:\Test\Custom.dll"); // Fails
I assume this is due to how the assembly is loaded for Reflection. (You may want to look at CodePlex: Common Complier Infrastructure for an alternative to Reflection.)
I was hoping that Ambient Assembly Repository created in the static constructor of the IExpressionEditorInstance would cache the data, but that does not seem to be working either. The directory is created but I don't see any files generated. (Edit: The files are being generated. I moved the Ambient Assembly Repository creation and purning to my applicaiton startup/shutdown. Intellisense is still not working on the custom dll.)
Utlimately I will need to dynamically load and unload custom dlls into the SyntaxEditor control's projectAssembly based on what the user needs in the Windows Workflow. Does anyone have a suggestions?
[Modified 11 years ago]