tonerdo / pose

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

Issue with NET7 #79

Open paillave opened 11 months ago

paillave commented 11 months ago

What am I doing wrong here? https://dotnetfiddle.net/PdKvbF

using System;
using Pose;

public class Program
{
    public static void Main()
    {
        Shim dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 4, 4));
        PoseContext.Isolate(() =>
        {
            // Outputs "4/4/04 12:00:00 AM"
            Console.WriteLine(DateTime.Now);
        }, dateTimeShim);
    }
}

I get this:

Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at dynamic_System.Collections.Generic.Dictionary`2[System.String,System.Resources.ResourceLocator]_FindValue(Dictionary`2, String)
   at dynamic_System.Collections.Generic.Dictionary`2[System.String,System.Resources.ResourceLocator]_TryGetValue(Dictionary`2, String, ResourceLocator&)
   at dynamic_System.Resources.RuntimeResourceSet_GetObject(RuntimeResourceSet, String, Boolean, Boolean)
   at dynamic_System.Resources.RuntimeResourceSet_GetString(RuntimeResourceSet, String, Boolean)
   at dynamic_System.Resources.ResourceManager_GetString(ResourceManager, String, CultureInfo)
   at dynamic_System.SR_InternalGetResourceString(String)
   at dynamic_System.SR_GetResourceString(String)
   at dynamic_System.PlatformNotSupportedException_.ctor(PlatformNotSupportedException)
   at stub_ctor_System.PlatformNotSupportedException_.ctor(RuntimeMethodHandle, RuntimeTypeHandle)
   at dynamic_System.Runtime.CompilerServices.Unsafe_As(TextWriter&)
   at dynamic_System.Threading.Volatile_Read(TextWriter&)
   at dynamic_System.Console_get_Out()
   at dynamic_System.Console_WriteLine(Object)
   at dynamic_Program+<>c_<Main>b__0_2(<>c)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at Pose.PoseContext.Isolate(Action entryPoint, Shim[] shims)
   at Program.Main()
Command terminated by signal 6
ividyon commented 9 months ago

17

Downgrading fro 1.2.1 to 1.1.0 did work for me, but I'm still not sure if the library is even doing anything atm

Miista commented 5 months ago

@paillave @ividyon There's a bug in versions above 1.1.0 (at least that's my experience). I haven't been able to shim anything with versions above 1.1.0.