Implementing ICustomMemberProvider without referencing Linqpad.

I'm wondering if your advice from this really, really old stackoverflow question is still relevant.

In particular this bit :

Note that if the test class is defined in another assembly, you don't need to reference LINQPad in order to implement ICustomMemberProvider. You can just paste in the following definition into your project and LINQPad will pick it up:

namespace LINQPad
{
   public interface ICustomMemberProvider
   {
      IEnumerable<string> GetNames ();
      IEnumerable<Type> GetTypes ();
      IEnumerable<object> GetValues ();
   }
}

I'm trying to do this and it is not working and I am getting errors in the log file

9.8.11 (X64) 2026-05-12T16:27:56.7486577+01:00 CustomMemberProvider
InvalidOperationException - Sequence contains no matching element

Source=System.Linq

 -System.Linq.ThrowHelper Void ThrowNoMatchException() offset: 0xA
 -System.Linq.Enumerable TSource First[TSource](System.Collections.Generic.IEnumerable`1[TSource], System.Func`2[TSource,System.Boolean]) offset: 0x0
 -LINQPad.ObjectGraph.CustomMemberProviderNode Void .ctor(LINQPad.ObjectGraph.ObjectNode, System.Object, Boolean, LINQPad.ObjectGraph.GraphOptions, Boolean, System.Object) offset: 0xCC
 -LINQPad.ObjectGraph.CustomMemberProviderNode LINQPad.ObjectGraph.ObjectNode CreateFromCustomMemberProvider(LINQPad.ObjectGraph.ObjectNode, System.Object, Boolean, LINQPad.ObjectGraph.GraphOptions, Boolean, System.Object) offset: 0x1
 -LINQPad.ObjectGraph.ObjectNode LINQPad.ObjectGraph.ObjectNode CreateInternal(LINQPad.ObjectGraph.ObjectNode, System.Object, System.Type, Boolean, LINQPad.ObjectGraph.GraphOptions, System.Object, Boolean ByRef) offset: 0xA61

Best Answer

Answers

  • All three methods need to return at least one element, and each method needs to return the same number of elements. Then it should work.

  • This is a test class

    using LINQPad;
    using System;
    using System.Collections.Generic;
    
    public partial class Foo  
    {  
        public string DATE { get; set; }
    }
    
    public partial class Foo : ICustomMemberProvider
    {
        public string FirstName , LastName , Junk ;
    
        IEnumerable<string> ICustomMemberProvider.GetNames()
            => new string[] { "FirstName", "LastName" };
    
        IEnumerable<Type> ICustomMemberProvider.GetTypes()
            => new Type[] { typeof(string), typeof(string) };
    
        IEnumerable<object> ICustomMemberProvider.GetValues()
            => new object[] { FirstName, LastName };
    }
    

    It appears work when I create a new Foo object, but not when I am doing Linq Queries

    void Main()
    {
        Show(new Foo());
        Show(Foo.First());
    }
    
    public void Show<T>(T input)
    {
        var type = input.GetType();
        var interfaces = type.GetInterfaces().Select(a => a.FullName);
        (new { input, type, interfaces }).Dump(type.Name);
    }
    

    produces

    The linq results are FooProxy objects which appear to implement ICustomMemberProvider (although I can find a way to decompile this as ILSpy says - Cannot find 'T:Castle.Proxies.FooProxy' in command line specified assemblies).