Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 77423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:49:40+00:00 2026-05-10T20:49:40+00:00

The code below gives an error: Property ‘Int32 Key’ is not defined for type

  • 0

The code below gives an error:

Property ‘Int32 Key’ is not defined for type ‘ConsoleApplication1.IKeyed`1[TKey]’

when the expression e is created but is fine when func f is created, can anyone explain why and if there is a way to fix it?

Module Module1     Sub Main()         Dim g = New keyedThingGetter(Of KeyedThing, Integer)         Dim thing = g.getThing()     End Sub End Module  Public Class keyedThingGetter(Of Tthing As IKeyed(Of TKey), TKey)     Public Function getThing() As Tthing         Dim f As Func(Of Tthing, Boolean)         f = Function(thing) thing.Key.Equals(1)         Dim e As Expressions.Expression(Of Func(Of Tthing, Boolean))         e = Function(thing) thing.Key.Equals(1)         Return Nothing     End Function End Class  Public Interface IKeyed(Of TKey)     ReadOnly Property Key() As TKey End Interface  Public Class KeyedThing     Implements IKeyed(Of Integer)     Public ReadOnly Property Key() As Integer Implements IKeyed(Of Integer).Key         Get             Return 1         End Get     End Property End Class 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:49:41+00:00Added an answer on May 10, 2026 at 8:49 pm

    Workaround is at the bottom

    That’s very odd. I’m still looking into it, but this ‘mostly equivalent’ C# works fine:

    using System; using System.Linq.Expressions;  interface IKeyed<TKey> {     TKey Key { get; } }  class KeyedThing : IKeyed<int> {     public int Key { get { return 1; } } }  class KeyedThingGetter<TThing, TKey> where TThing : IKeyed<TKey> {     public void GetThing()     {         Func<TThing, bool> f = thing => thing.Key.Equals(1);         Expression<Func<TThing, bool>> e = thing => thing.Key.Equals(1);     } }  class Test {     static void Main()     {         var g = new KeyedThingGetter<KeyedThing, int>();         g.GetThing();     } } 

    EDIT: There’s an interesting difference between the expression trees created. Here’s the VB expression (decompiled to C# with Reflector):

    Expression<Func<Tthing, bool>> expression = Expression .Lambda<Func<Tthing, bool>> (Expression.Call(Expression.Convert (Expression.Property(Expression.Convert(expression2 =  Expression.Parameter(typeof(Tthing), 'thing'), typeof(IKeyed<>)), (MethodInfo) methodof(IKeyed<TKey>.get_Key, IKeyed<TKey>)), typeof(object)),  (MethodInfo) methodof(object.Equals), new Expression[] {  Expression.Convert(Expression.Constant(1, typeof(int)), typeof(object)) }), new  ParameterExpression[] { expression2 }); 

    Here’s the C# version:

    Expression<Func<TThing, bool>> expression = Expression .Lambda<Func<TThing, bool>> (Expression.Call(Expression.Convert (Expression.Property(Expression.Convert(expression2 =  Expression.Parameter(typeof(TThing), 'thing'), typeof(IKeyed<TKey>)),  (MethodInfo) methodof(IKeyed<TKey>.get_Key, IKeyed<TKey>)), typeof(object)),  (MethodInfo) methodof(object.Equals), new Expression[] {  Expression.Convert(Expression.Constant(1, typeof(int)), typeof(object)) }), new  ParameterExpression[] { expression2 }); 

    The difference is in the fourthline – the type of the parameter. In the C#, it’s typeof(IKeyed<TKey>) whereas in the VB it’s typeof(IKeyed<>).

    A bug in the VB compiler perhaps? Not sure yet. Hopefully Marc G will chime in soon, as resident expression tree expert…

    EDIT: Given the difference, I worked out how to fix it. Either change it to:

    Dim e as Expressions.Expression(Of Func(Of Tthing, Boolean)) e = Function(thing as IKeyed(Of TKey)) thing.Key.Equals(1)) 

    or

    Dim e as Expressions.Expression(Of Func(Of IKeyed(Of TKey), Boolean)) e = Function(thing) thing.Key.Equals(1)) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's a matter of preference, but I prefer to see… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer Smalltalk-80, released by Xerox in 1980, used self. Objective-C (early… May 11, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer You could join a big open source project, you'll learn… May 11, 2026 at 11:44 pm

Related Questions

The code below gives an error: Property 'Int32 Key' is not defined for type
EDIT: See my working code in the answers below. In brief: I have a
I want my application to download some data from the internet, in iPhone SDK
I've been trying to get this code to work for hours! All I need
I am new to AS3. When learning AS3, I get the below code from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.