pose: System.InvalidProgramException when trying to shim DateTime.Now
Write the following program:
using System;
using Pose;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
var dt = DateTime.Now;
Shim dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 4, 4));
PoseContext.Isolate(() =>
{
var time = DateTime.Now;
Console.WriteLine(time);
},
dateTimeShim);
}
}
}
Compile it with netcoreapp2.0 and run with .NET Core ⇒ throws an exception:
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.Text.Encoding_.ctor(Encoding , Int32 )
at stub_ctor_System.Text.Encoding_.ctor(Encoding , Int32 , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Text.OSEncoding_.ctor(OSEncoding , Int32 )
at stub_ctor_System.Text.OSEncoding_.ctor(Int32 , RuntimeMethodHandle , RuntimeTypeHandle )
at stub_System.Text.EncodingHelper_GetSupportedConsoleEncoding(Int32 , RuntimeMethodHandle , RuntimeTypeHandle )
at stub_System.ConsolePal_get_OutputEncoding(RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Threading.LazyInitializer_EnsureInitializedCore(Encoding& , Object& , Func`1 )
at stub_System.Threading.LazyInitializer_EnsureInitializedCore(Encoding& , Object& , Func`1 , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Threading.LazyInitializer_EnsureInitialized(Encoding& , Object& , Func`1 )
at stub_System.Threading.LazyInitializer_EnsureInitialized(Encoding& , Object& , Func`1 , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Console_EnsureInitialized(Encoding& , Func`1 )
at stub_System.Console_EnsureInitialized(Encoding& , Func`1 , RuntimeMethodHandle , RuntimeTypeHandle )
at stub_System.Console_get_OutputEncoding(RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.ConsolePal_GetUseFileAPIs(Int32 )
at stub_System.ConsolePal_GetUseFileAPIs(Int32 , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.ConsolePal_GetStandardFile(Int32 , FileAccess )
at stub_System.ConsolePal_GetStandardFile(Int32 , FileAccess , RuntimeMethodHandle , RuntimeTypeHandle )
at stub_System.ConsolePal_OpenStandardOutput(RuntimeMethodHandle , RuntimeTypeHandle )
at stub_System.Console_OpenStandardOutput(RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Console+<>c_<get_Out>b__25_0(<>c )
at dynamic_System.Threading.LazyInitializer_EnsureInitializedCore(TextWriter& , Object& , Func`1 )
at stub_System.Threading.LazyInitializer_EnsureInitializedCore(TextWriter& , Object& , Func`1 , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Threading.LazyInitializer_EnsureInitialized(TextWriter& , Object& , Func`1 )
at stub_System.Threading.LazyInitializer_EnsureInitialized(TextWriter& , Object& , Func`1 , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Console_EnsureInitialized(TextWriter& , Func`1 )
at stub_System.Console_EnsureInitialized(TextWriter& , Func`1 , RuntimeMethodHandle , RuntimeTypeHandle )
at stub_System.Console_get_Out(RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_System.Console_WriteLine(Object )
at stub_System.Console_WriteLine(Object , RuntimeMethodHandle , RuntimeTypeHandle )
at dynamic_ConsoleApp4.Program+<>c_<Main>b__0_2(<>c )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at Pose.PoseContext.Isolate(Action entryPoint, Shim[] shims)
at ConsoleApp4.Program.Main(String[] args) in T:\Temp\ConsoleApp4\ConsoleApp4\Program.cs:line 12
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 12
- Comments: 20 (4 by maintainers)
Hi @crushjz, can’t give a definite ETA at the moment. I’ve been a bit swamped with work and all, I believe I can fix most of the
InvalidProgramExceptionwithout resorting to a re-implementation with Expression Trees. This will be my focus for the coming weeksGuys, I’m also having the same issue. Any advances or previous versions that could work? Congratulations for the nice software!
Any workaround or previous version that doesn’t have the issue?
@devedse been improving the debugging experience around the generated IL to help figure out exactly where the problem is. Just cleaning that up and will make a release soon
Do you have any ETA on when this will be fixed?
Pose is so useful, but this issue limits its main functionality.
Given that as of today, this bug has effectively been ignored for over 5 years, I think its safe to say that if you run into this defect, that means Prose is no longer an option that can be trusted.
Its important to call out that even the maintainer doesn’t want to fix this, as shown by the lack of a fix in 5 years of people waiting, so its probably best to find other options.
This issue is still present in the latest NuGet package (version 1.2.1). I was able to run my tests by reverting to version 1.1.0
Still working out the intricacies of the new implementation especially around performance. Expression trees allow for more features but are a bit harder to translate IL to
Hi @tonerdo, any updates on this yet? 😄