tonerdo / pose

Replace any .NET method (including static and non-virtual) with a delegate
MIT License
1.07k stars 75 forks source link

Bug with a test app #69

Open DmitryJustDmitry opened 2 years ago

DmitryJustDmitry commented 2 years ago

Hi, stumled in something looks like a bug.

  1. Create simple app:
using System;
using Pose;
namespace HelloWorld
{
    class Hello {         
        static void Main(string[] args)
        {
             Shim dtShim = Shim.
                Replace(() => DateTime.Now).
                With(() => new DateTime(2004, 4, 4));
            PoseContext.Isolate(() => {Console.WriteLine(DateTime.Now);}, dtShim);
            System.Console.WriteLine("Fine!");
        }
    }
}
  1. And a simple project:

    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <LangVersion>8.0</LangVersion> 
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    </PropertyGroup>
    <ItemGroup>
    <PackageReference Include="Pose" Version="1.2.1" />
    </ItemGroup>
    </Project>
  2. Trying to debug (Ubuntu 20.04, VS Code (latest), .net 6, built with dotnet build -a x64) - getting infinite stack message, ending like:

at DynamicClass.stub_System.SR_get_Arg_PlatformNotSupported(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamicSystem.PlatformNotSupportedException.ctor(System.PlatformNotSupportedException) at DynamicClass.stub_ctorSystem.PlatformNotSupportedException.ctor(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_Internal.Runtime.CompilerServices.Unsafe_As(Char ByRef) at DynamicClass.stub_Internal.Runtime.CompilerServices.Unsafe_As(Char ByRef, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.String_EqualsHelper(System.String, System.String) at DynamicClass.stub_System.String_EqualsHelper(System.String, System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle)

at DynamicClass.stub_System.String_Equals(System.String, System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.stub_System.String_op_Equality(System.String, System.String, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Resources.ResourceManager_GetFirstResourceSet(System.Resources.ResourceManager, System.Globalization.CultureInfo) at DynamicClass.stub_System.Resources.ResourceManager_GetFirstResourceSet(System.Resources.ResourceManager, System.Globalization.CultureInfo, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Resources.ResourceManager_GetString(System.Resources.ResourceManager, System.String, System.Globalization.CultureInfo) at DynamicClass.stub_virt_System.Resources.ResourceManager_GetString(System.Resources.ResourceManager, System.String, System.Globalization.CultureInfo, 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_PlatformNotSupported(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamicSystem.PlatformNotSupportedException.ctor(System.PlatformNotSupportedException) at DynamicClass.stub_ctorSystem.PlatformNotSupportedException.ctor(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_Internal.Runtime.CompilerServices.Unsafe_As(System.IO.TextWriter ByRef) at DynamicClass.stub_Internal.Runtime.CompilerServices.Unsafe_As(System.IO.TextWriter ByRef, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Threading.Volatile_Read(System.IO.TextWriter ByRef) at DynamicClass.stub_System.Threading.Volatile_Read(System.IO.TextWriter ByRef, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Console_get_Out() at DynamicClass.stub_System.Console_get_Out(System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamic_System.Console_WriteLine(System.Object) at DynamicClass.stub_System.Console_WriteLine(System.Object, System.RuntimeMethodHandle, System.RuntimeTypeHandle) at DynamicClass.dynamicHelloWorld.Hello+<>c

b__0_2(<>c) at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Span`1 ByRef, System.Signature, Boolean, Boolean) at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) at System.Delegate.DynamicInvokeImpl(System.Object[]) at System.Delegate.DynamicInvoke(System.Object[]) at Pose.PoseContext.Isolate(System.Action, Pose.Shim[]) at HelloWorld.Hello.Main(System.String[])