Skip to content

Stack Overflow when trying to use shim from task #76

Open
Miista/pose
#29

Description

@mconradiesa

When trying to replace a function call within a task started by PoseContext.Isolate...

`
Shim consoleShim = Shim.Replace(() => Debug.WriteLine(Is.A())).With(
delegate (string s) { Debug.WriteLine($"Hijacked: {s}"); });

        var tcs = new TaskCompletionSource<string>();   

        PoseContext.Isolate(() =>
        {
            Debug.WriteLine("Starting test");

            /* Running in a separate task causes stack overflow */
            _ = Task.Run(() =>
            {
                Debug.WriteLine("In different task");
            });
            /**********/

            Debug.WriteLine("Test Complete.");

            tcs.SetResult("Complete");
        }, consoleShim);

        await tcs.Task;`

I get the following stack overflow error:
Stack overflow. at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](Int32) at System.Collections.Generic.Dictionary2[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reflection.Emit.Label, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryInsert(Int32, System.Reflection.Emit.Label, System.Collections.Generic.InsertionBehavior)
at Pose.Extensions.DictionaryExtensions.TryAdd[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reflection.Emit.Label, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.Dictionary2<Int32,System.Reflection.Emit.Label>, Int32, System.Reflection.Emit.Label) at Pose.IL.MethodRewriter.Rewrite() at DynamicClass.stub_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String, Int32, Int32, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String) at DynamicClass.stub_virt_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.SR_InternalGetResourceString(System.String) at DynamicClass.stub_System.SR_InternalGetResourceString(System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.SR_GetResourceString(System.String) at DynamicClass.stub_System.SR_GetResourceString(System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.stub_System.SR_get_Arg_InvalidOperationException(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.InvalidOperationException_.ctor(System.InvalidOperationException) at DynamicClass.stub_ctor_System.InvalidOperationException_.ctor(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Runtime.CompilerServices.RuntimeHelpers_IsBitwiseEquatable() at DynamicClass.stub_System.Runtime.CompilerServices.RuntimeHelpers_IsBitwiseEquatable(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Array_LastIndexOf(System.String[], System.String, Int32, Int32) at DynamicClass.stub_System.Array_LastIndexOf(System.String[], System.String, Int32, Int32, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String, Int32, Int32) at DynamicClass.stub_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String, Int32, Int32, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String) at DynamicClass.stub_virt_System.Collections.Generic.List1[System.String]_LastIndexOf(System.Collections.Generic.List1<System.String>, System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.SR_InternalGetResourceString(System.String)...

Activity

  1. Miista commented on Jan 27, 2024

    @Miista

    For support for async/await please see Miista/pose#12

    cc: @mconradiesa @ehewitt-sel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions