sebastienros/fluid

Exception thrown when registering DateTimeOffset

Closed this issue · 2 comments

// Tested with Fluid.Core 2.2.15 on .NET 6
var options = new TemplateOptions();
options.MemberAccessStrategy.Register<DateTimeOffset>();
System.ArgumentException: Cannot bind to the target method because its signature is not compatible with that of the delegate type.
   at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags)
   at System.Reflection.RuntimeMethodInfo.CreateDelegate(Type delegateType)
   at Fluid.Accessors.PropertyInfoAccessor..ctor(PropertyInfo propertyInfo)
   at Fluid.MemberAccessStrategyExtensions.<>c__DisplayClass1_0.<GetTypeMembers>b__0(ValueTuple`2 key)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Fluid.MemberAccessStrategyExtensions.GetTypeMembers(Type type, MemberNameStrategy memberNameStrategy)
   at Fluid.MemberAccessStrategyExtensions.Register(MemberAccessStrategy strategy, Type type)
   at Fluid.MemberAccessStrategyExtensions.Register[T](MemberAccessStrategy strategy)
   at Program.<Main>$(String[] args) in C:\...\ConsoleApp1\ConsoleApp1\Program.cs:line 6

Confirmed when adding this test

        [Fact]
        public Task ShouldRegisterDateTimeOffset()
        {
            var options = new TemplateOptions();
            options.MemberAccessStrategy.Register<DateTimeOffset>();
            return Task.CompletedTask;
        }

It will now prevent you from compiling by ensuring that T is a reference type.