j'ai une classe définie dans une bibliothèque de classes:Comment utiliser la classe externe dans l'activité de workflow dans .NET?
namespace TestLib
{
public class TestClass
{
public static void Test() { }
}
}
J'ai aussi un Activity
défini dans un fichier XAML
. Maintenant, je veux utiliser l'activité InvokeMethod
dans cette activité à appeler la méthode statique à l'intérieur de la classe, mais le débogueur émet une exception d'exécution qui dit:
"Could not load file or assembly 'TestLib, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
La bibliothèque de classes est correctement référencée et je peux voir que dans la source XAML , aussi. Si j'inclue cette classe dans la source, cela fonctionne correctement.
Quelle est la bonne façon d'utiliser les types externes dans les flux de travail et ce que je fais mal? Merci.
MISE À JOUR:
Recréer ce cas est très simple.
Créez un projet Class Library
nommé TestLib
et ajoutez le TestClass
ci-dessus.
Créez un projet Activity Library
et renommez l'activité principale en TestActivity
. Ajouter la référence à TestLib
. Ajoutez une activité Sequence
avec une activité InvokeMethod
à l'intérieur, et utilisez-la pour appeler la méthode TestClass.Test
. Ceci est XAML
code:
<Activity mc:Ignorable="sap sap2010 sads" x:Class="WorkflowSimpleTest.TestActivity" sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#" sap2010:WorkflowViewState.IdRef="WorkflowSimpleTest.Activity1_1"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:t="clr-namespace:TestLib;assembly=TestLib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Text</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>Microsoft.CSharp</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Activities</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.Runtime.Serialization</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
<AssemblyReference>System.Xaml</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
<AssemblyReference>System.Xml.Linq</AssemblyReference>
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>TestLib</AssemblyReference>
<AssemblyReference>WorkflowSimpleTest</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<Sequence sap2010:WorkflowViewState.IdRef="Sequence_1">
<InvokeMethod sap2010:WorkflowViewState.IdRef="InvokeMethod_1" MethodName="Test" TargetType="t:TestClass" />
<WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1" Text="End activity." />
<sads:DebugSymbol.Symbol>d1dEOlxFbHZlZGluXFByb2plY3RzXEF1dG9tYXRpb24mQklcc291cmNlXFNFQ1VSSVRBU1xXb3JrZm9sd1NpbXBsZVRlc3RcVGVzdEFjdGl2aXR5LnhhbWwEJgMqDgIBAScFJ3ECAQQoBShVAgECKEMoUgIBAw==</sads:DebugSymbol.Symbol>
</Sequence>
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="InvokeMethod_1" sap:VirtualizedContainerService.HintSize="218,130" />
<sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="218,62" />
<sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="240,356">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</sap2010:ViewStateData>
<sap2010:ViewStateData Id="WorkfolwSimpleTest.Activity1_1" sap:VirtualizedContainerService.HintSize="280,436" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>
Créer une application console et exécuter le flux de travail en utilisant ce code:
Dictionary<string, object> vars = new Dictionary<string, object>() { };
WorkflowApplication wfApp = new WorkflowApplication(new TestActivity(), vars);
wfApp.Completed += delegate (WorkflowApplicationCompletedEventArgs e)
{
Console.WriteLine("Completed.");
};
wfApp.Idle += delegate (WorkflowApplicationIdleEventArgs e1)
{
Console.WriteLine("Idle.");
};
wfApp.Run();
L'application devrait lancer exception d'exécution.
Est-il possible que vous ajoutiez plus de code, probablement, votre utilisation de 'InvokeMethod' et d'autres choses importantes? –
@ J.Pichardo J'ai mis à jour ma question. –