Azure / Azure/durabletask

Task activity received "[\"HelloWorld\"]" instead of string "HelloWorld" passed in task orchestration

Offen
#573 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
1.7k
Forks
335
Ø Merge
2 T. 23 Std.
Gemergte PRs (30 T.)
6

Beschreibung

There are two issues here:

**The first one is** that I pass string "HelloWorld" to a task activity in task orchestration, however when I debug I find that the task activity received the string "[\"HelloWorld\"]".

**The second one is** that the task orchestration ran twice(which is weird for me) and when the twice, I got the exception.
"Object reference not set to an instance of an object." the call stack is

![image](https://user-images.githubusercontent.com/12733681/125599877-733c9969-d152-482b-a20d-759aa69d5b61.png)

My code is very simple: just following the encode video sample but more simple.

1.EncodeOrchestration
```
public class EncodeOrchestration : TaskOrchestration
{
public override async Task RunTask(OrchestrationContext context, string input)
{
Console.WriteLine("The input text is " + input);
string resultFromActivity = await context.ScheduleTask(typeof(EncodeActivity), input);

Console.WriteLine($"The result of {this.GetType().Name} is {resultFromActivity}.");
return resultFromActivity;
}
}
```

2. EncodeActivity
```
public class EncodeActivity : TaskActivity
{
public override string Run(TaskContext context, string activityInput)
{
Console.WriteLine($"{this.GetType().Name} received the input text is as bellow:");
Console.WriteLine(activityInput);

string result = "This is activity.";
return result;
}
}
```

3. I use azure storage create task hub client and create orchestration instance in one application project
```
static void Main(string[] args)
{
//omit some code to initialize task hub client, I use the durable.storage
string orchestrationInput = "HelloWorld3";
var instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(EncodeOrchestration), orchestrationInput).GetAwaiter().GetResult();

Console.ReadLine();
}
```

4. Then I create another console application project to start task hub worker
```
static void Main(string[] args)
{
//omit some code to initialize task hub worker with the same storage when initializing task hub client
Console.WriteLine("Worker start to run");
var hubworker = .taskHubWorker.AddTaskOrchestrations(typeof(EncodeOrchestration)).AddTaskActivities(typeof(EncodeActivity)).StartAsync().ConfigureAwait(true).GetAwaiter().GetResult();
Console.WriteLine(hubworker.orchestrationService);
Console.ReadLine();
}
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit EncodeOrchestration.RunTask, EncodeActivity.Run und dem im Issue gezeigten Aufruf CreateOrchestrationInstanceAsync. Reproduziere den Workflow mit dem Azure Storage task hub und der Eingabe HelloWorld3, vergleiche anschließend die Eingaben der Orchestrierung und der Activity und überprüfe den gemeldeten Nullreferenz-Stacktrace. Als abgeschlossen gilt die Aufgabe, wenn beide gemeldeten Verhaltensweisen erklärt sind und die erwartete einmalige Ausführung sowie die String-Eingabe durch einen verifizierten Regressionstest abgedeckt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, csharp
Bereich
backend, distributed-systems
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.