-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Given a situation like below where 2 code blocks both contain a variable declaration of the same name, foo
, the Dasync framework attempts to re-saturate the execution context following the await
ed method (Task.Delay(1)
which symbolizes any async IO requiring a Dasync transition):
public class Example
{
public async void Test()
{
var boolean = true;
if (boolean)
{
var foo = "hello";
await Task.Delay(1);
Console.WriteLine(foo);
}
else
{
var foo = "world";
await Task.Delay(1);
Console.WriteLine(foo);
}
}
}
During the execution of a method like this, Dasync fails to disambiguate between the 2 distinct variables in each code block and throws this exception:
System.Reflection.AmbiguousMatchException: Ambiguous match found.
at System.RuntimeType.GetField(String name, BindingFlags bindingAttr)
at Dasync.ValueContainer.ValueContainerTypeBuilder.BuildInternal(ContainerDesc desc)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Dasync.ValueContainer.ValueContainerTypeBuilder.Build(Type delegatedType, IEnumerable`1 delegatedProperties, String newTypeName)
at Dasync.ValueContainer.ValueContainerFactory.CreateProxy(Object target, IEnumerable`1 properties)
at Dasync.ExecutionEngine.Transitions.TransitionRunner.GetValueContainerProxy(IAsyncStateMachine asyncStateMachine, AsyncStateMachineMetadata metadata)
at Dasync.ExecutionEngine.Transitions.TransitionRunner.LoadRoutineStateAsync(ITransitionCarrier transitionCarrier, IAsyncStateMachine asyncStateMachine, AsyncStateMachineMetadata metadata, Boolean isContinuation, CancellationToken ct)
at Dasync.ExecutionEngine.Transitions.TransitionRunner.RunRoutineAsync(ITransitionCarrier transitionCarrier, TransitionDescriptor transitionDescriptor, CancellationToken ct)
at Dasync.ExecutionEngine.Transitions.TransitionRunner.RunAsync(ITransitionCarrier transitionCarrier, CancellationToken ct)
... application code stack trace
If this has been fixed in newer versions of Dasync then we can gladly close it as solved. There are workarounds that one could say results in better design anyways like moving the scope of the variable above both code blocks or using 2 different names, but there could still be valid reasons to do this and since the C# compiler allows this scenario it seems like it should be supported nonetheless.