Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack Overflow when trying to use shim from task #76

Open
mconradiesa opened this issue Mar 13, 2023 · 1 comment · May be fixed by Miista/pose#29
Open

Stack Overflow when trying to use shim from task #76

mconradiesa opened this issue Mar 13, 2023 · 1 comment · May be fixed by Miista/pose#29

Comments

@mconradiesa
Copy link

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)...

@Miista
Copy link

Miista commented Jan 27, 2024

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

cc: @mconradiesa @ehewitt-sel

@Miista Miista linked a pull request Jan 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants