Assembly Loaded Service
I am having problems with validating a workflow that uses a service that is dynamically loaded from an assembly.
Code Snippet
Assembly ^serviceAssembly = Assembly::LoadFile("C:\\msc\\Workflow\\bin\\Debug\\MscWFPropertiesService.dll");
assemblyNameDictionary->Add( serviceAssembly->FullName, serviceAssembly );
Type ^type = serviceAssembly->GetType("MscWFPropertiesService.PropertiesService");
array<Type^> ^paramTypes = gcnew array<Type^>(1);
paramTypes[0]= Type::GetType("System.Workflow.Runtime.WorkflowRuntime");
MethodInfo ^method = type->GetMethod("CreateService");
method->Invoke(nullptr, gcnew array<Object^>{workflowRuntime});
workflowRuntime->StartRuntime();
This loads the assembly with the service. The call the CreateService will create the service and add the service to the workflow runtime.
Code Snippet
public: static void CreateService(WorkflowRuntime ^workflowRuntime)
{
workflowRuntime->AddService( (IPropertiesService^)gcnew PropertiesService() );
}
When I call
Code Snippet
workflowInstance = workflowRuntime->CreateWorkflow( type );
later on in the code, workflows that use that service fail to validate. Is there a way to give the runtime more information to get it to validate.
[1746 byte] By [
thePoet] at [2008-1-4]
Strange. This morning I came in, rebuilt, and now I don't get the validation exception, but I do get these errors at runtime when hitting the code that calls into the service:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Workflow.Activities.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Workflow.ComponentModel.dll
I don't know why it has changed, or how to get around this error.
The text of the exception is:
Could not find service of type 'MscWFPropertiesService.IPropertiesService' through the currently configured services. Consider adding the service to ExternalDataExchangeService.
But as I said in the first post, this isn't a problem if I load through a referenced assembly, only if I dynamically load it.
By the way, I've reworked the above code to add the service to the ExternalDataExchangeService instead of directly to the WorkflowRuntime. No difference.
Turns out, if the assembly where the service is in the working directory, it all works. So, that is workable for my needs at this point.