Problem I have a C# Durable Azure Functions app (v2) containing an orchestration and activity function.
The orchestration calls the activity as follows:
propBag.CE = await context.CallActivityAsync<CEData>(nameof(GetCEByExternalIdActivity), propBag);
The call works ok and the Activity function executes, builds up the content for propBag.CE and returns.
The CE object contains a few other objects, including:
public List<IParty> Individuals { get; set; }
public List<IParty> Organisations { get; set; }
These properties are assigned to as follows:
consPort.Individuals = await GetParties(clientRel.RelatedIndividuals, CEEntityType.Individual);
consPort.Organisations = await GetParties(clientRel.RelatedOrganisations, CEEntityType.Organisation);
The fact that it contains an Interface seems to give the Durable Functions runtime a problem. When it attempts to deserialize the value returned from the activity function, I get the following error:
Could not create an instance of type Interfaces.Avaloq.Application.Models.CE.IParty. Type is an interface or abstract class and cannot be instantiated
Does anyone know of a good fix for this? Maybe there's a way to configure how the function will attempt to deserialize the json?
Workaround I worked-around the problem by changing the class to contain lists of the concrete types of IParty as follows:
public List<Individual> Individuals { get; set; }
public List<Organisation> Organisations { get; set; }
I then had to ensure that I cast to the concrete type from the IParty before assigning to those properties, as follows:
var myList = (await GetParties(clientRel.RelatedIndividuals, CEEntityType.Individual));
foreach (var party in myList)
{
consPort.Individuals.Add((Individual)party);
}
myList = (await GetParties(clientRel.RelatedOrganisations, CEEntityType.Organisation));
foreach (var party in myList)
{
consPort.Organisations.Add((Organisation)party);
}
Not pretty but gets me around the problem.