# .Net Activity not returning Result

**URL:** <https://community.temporal.io/t/net-activity-not-returning-result/11946>\
**Category:** Community Support\
**Created:** [April 30, 2024, 8:22am UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946 "2024-04-30T08:22:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![joao.zacharias](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joao.zacharias](https://community.temporal.io/u/joao.zacharias)\
**Post date:** [April 30, 2024, 8:22am UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/1 "2024-04-30T08:22:12Z")

</div>

In .Net when i try to get the “response” from activity, the returned object it’s always like a new instance and not the instance that i used on return.  
For example, i’m returning the below result  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/4/484c9d6fe3ab0cb4ee25dc6ab52e95940e5a773b.png)  
And at workflow the response is like a new instance of Result without any property filled.  
What do i have to do to get the returned object?  
P.S - i already tried with another kind of class

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [April 30, 2024, 12:14pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/2 "2024-04-30T12:14:35Z")

</div>

> [@joao.zacharias](#):
>
> the returned object it’s always like a new instance and not the instance that i used on return.

Workflow and activity results are serialized and put in history and returned to the caller deserliazed from the server, not directly. Activities may not even execute on the same machine as the workflow that called them.

---

<div class="post-metadata">

**Author:** ![joao.zacharias](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joao.zacharias](https://community.temporal.io/u/joao.zacharias)\
**Post date:** [April 30, 2024, 1:52pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/3 "2024-04-30T13:52:35Z")

</div>

Ok, nice!  
So it’s a problem with serialization? Because the returned value is different or in this case like a default instance.

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [April 30, 2024, 2:15pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/4 "2024-04-30T14:15:34Z")

</div>

I’d have to see your code to know the problem, but by default the SDK tries to serialize/deserialize to/from JSON. See [the conversion section of the README](https://github.com/temporalio/sdk-dotnet/?tab=readme-ov-file#data-conversion).

---

<div class="post-metadata">

**Author:** ![joao.zacharias](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joao.zacharias](https://community.temporal.io/u/joao.zacharias)\
**Post date:** [April 30, 2024, 3:08pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/5 "2024-04-30T15:08:26Z")

</div>

I see, let me give more details.

Here’s how i’m initializing the client and the worker.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/2/211aa3f2a0a88995fc876bb4daf89fdea11b23bc.png)

Here’s what i’m returning from the activity.

```auto
        if (importZone.Items.Any(x => !string.IsNullOrEmpty(x.Errors)))
        {
            await _mediator.Publish(new ImportFailedEvent(importZone));

            _logger.LogError("Carrier validation failed");
            return Result.Fail("Carrier validation failed");
        }

        return Result.Ok();

```

And at workflow level, this values are not being correctly serialized. It’s returning like a default instance.

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [April 30, 2024, 3:19pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/6 "2024-04-30T15:19:34Z")

</div>

I need to see the signature of the activity and the invocation of the activity from the workflow and the class of the return type. The workflow deserializes using JSON based on result type of the lambda expression of the activity (or you have to set the result type explicitly when you ask for result if you are not using typesafe lambda expressions). By default, if it doesn’t work with `System.Text.Json` it won’t work as a return type.

---

<div class="post-metadata">

**Author:** ![joao.zacharias](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joao.zacharias](https://community.temporal.io/u/joao.zacharias)\
**Post date:** [April 30, 2024, 3:34pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/7 "2024-04-30T15:34:14Z")

</div>

This is the method/activity  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/2X/7/7f41f89493f66df354ddaa20cbadd64061dbac8b.png)  
Do i need to pass any parameter on the Attribute?

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [April 30, 2024, 3:45pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/8 "2024-04-30T15:45:36Z")

</div>

This does not show calling from workflow or what `Result` is. Can `Result.Ok` be properly serialized/deserialized to/from `System.Text.Json` with the `Result` type to the .NET JSON deserialize call?

For example, what does `var jsonString = JsonSerializer.Serialize(Result.Ok())` return? And if you give that to `var obj = JsonSerializer.Deserialize<Result>(jsonString)` what is in `obj`? This is how .NET JSON serialization works, but I fear you have a sum type which is not compatible with .NET JSON serialization.

---

<div class="post-metadata">

**Author:** ![joao.zacharias](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joao.zacharias](https://community.temporal.io/u/joao.zacharias)\
**Post date:** [April 30, 2024, 3:50pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/9 "2024-04-30T15:50:33Z")

</div>

Got it, i expected the serialization for this class works because it’s the same class which we are using in another project with Hangfire. I’ll try to do these tests.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [April 30, 2024, 3:59pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/10 "2024-04-30T15:59:01Z")

</div>

I am not familiar with Hangfire, but a quick glance shows they do a combination of JSON serialization as well as adding extra information for which type name it is. This is inherently .NET specific and Temporal uses JSON without such metadata so it can work across languages (think of it like an HTTP API). But if you want to take this approach, the conversion is customizable. It is advanced, but you can override the payload converter of the data converter to include the .NET assembly type name in the payload metadata on conversion to payload, and use that metadata to create a certain type on conversion from payload.

---

<div class="post-metadata">

**Author:** ![joao.zacharias](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@joao.zacharias](https://community.temporal.io/u/joao.zacharias)\
**Post date:** [April 30, 2024, 4:15pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/11 "2024-04-30T16:15:06Z")

</div>

sure, i see now it’s a different paradigm. I don’t want to waste time creating custom serializers, it’s not worth the work, i’ll try a different approach maybe create a simple class.  
Thanks a lot for the explanation.

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [April 30, 2024, 4:23pm UTC](https://community.temporal.io/t/net-activity-not-returning-result/11946/12 "2024-04-30T16:23:27Z")

</div>

Happy to help! Yes it’s very common for Temporal users to create models (e.g. simple `record`s) specific for Temporal use and translate from other models. This makes them easy to adjust without affecting other parts of the system. Yes, often sum types and other abstract data types do not work well with multi-language serialization mechanisms like pure JSON.
