views:

100

answers:

1
using System;
using System.Reflection;

namespace A
{
  interface IObjectWithId<TId>
  {
    TId Id { get; }
  }
  interface IEntityBase : IObjectWithId<object>
  {
    new object Id { get; }
  }
  abstract class BusinessObject<TId> : IObjectWithId<TId>
  {
    public abstract TId Id { get; }
  }
  class EntityBase : BusinessObject<object>, IEntityBase
  {
    public override object Id { get { return null; } }
  }

  public static class Program
  {
    public static void Main()
    {
      Console.WriteLine(typeof(EntityBase).GetProperty("Id", BindingFlags.Instance | BindingFlags.Public));
    }
  }
}

I am getting this:

System.Reflection.AmbiguousMatchException was unhandled
  Message="Ambiguous match found."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
       at System.Type.GetProperty(String name, BindingFlags bindingAttr)
       at A.Program.Main() in C:\Home\work\A\Program.cs:line 26
  InnerException: 

Visual Studio about: Microsoft Visual Studio 2008 Version 9.0.30729.1 SP Microsoft .NET Framework Version 3.5 SP1

Installed Edition: Professional

Microsoft Silverlight Projects 2008 91605-270-1013592-60817 Microsoft Silverlight Projects 2008 Version 9.0.30730.126

Microsoft Visual Basic 2008 91605-270-1013592-60817 Microsoft Visual Basic 2008

Microsoft Visual C# 2008 91605-270-1013592-60817 Microsoft Visual C# 2008

Microsoft Visual C++ 2008 91605-270-1013592-60817 Microsoft Visual C++ 2008

Microsoft Visual Studio 2008 Tools for Office 91605-270-1013592-60817 Microsoft Visual Studio 2008 Tools for Office

Microsoft Visual Web Developer 2008 91605-270-1013592-60817 Microsoft Visual Web Developer 2008

AnkhSVN - Subversion Support for Visual Studio 2.1.6941.125 AnkhSVN - Subversion Support for Visual Studio 2.1.6941.125 * Ankh.Package 2.1.6941.125 * Subversion 1.6.3 via SharpSvn 1.6003.1296.38121

AnkhSVN is linked to: Apr 1.3.5, Apr-util 1.3.7, Neon 0.28.4, OpenSSL 0.9.8k 25 Mar 2009, serf 0.3.1, SQLite 3.6.13, Subversion 1.6.3-SharpSvn-tag-1.6.3@38121, ZLib 1.2.3 AnkhSVN is dynamically linked to: Cyrus Sasl 2.1.23 AnkhSVN is optionally linked to: Berkeley DB 4.4.20, SharpPlink 1.6003.1296.38121

DXCore for Visual Studio 3.2 DXCore for Visual Studio

Gallio Version 3.1 build 449 Gallio integration for Visual Studio

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB944899) KB944899 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/944899.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB945282) KB945282 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/945282.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946040) KB946040 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/946040.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946308) KB946308 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/946308.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946344) KB946344 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/946344.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB946581) KB946581 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/946581.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947171) KB947171 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/947171.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947173) KB947173 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/947173.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947180) KB947180 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/947180.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947540) KB947540 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/947540.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB947789) KB947789 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/947789.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB948127) KB948127 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/948127.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB953256) KB953256 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/953256.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB971092) KB971092 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/971092.

Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU (KB974479) KB974479 This hotfix is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this hotfix will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/974479.

Microsoft Visual Studio 2008 Professional Edition - ENU Service Pack 1 (KB945140) KB945140 This service pack is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this service pack will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/945140.

Microsoft Visual Studio 2008 Professional Edition - ENU Service Pack 1 (KB947888) KB947888 This service pack is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this service pack will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/947888.

Microsoft Visual Studio 2008 Professional Edition - ENU Service Pack 1 (KB948484) KB948484 This service pack is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this service pack will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/948484.

Microsoft Visual Studio 2008 Professional Edition - ENU Service Pack 1 (KB948560) KB948560 This service pack is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this service pack will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/948560.

Security Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB972222) KB972222 This security update is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this security update will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/972222.

Security Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB973675) KB973675 This security update is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this security update will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/973675.

Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB956453) KB956453 This update is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this update will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/956453.

Update for Microsoft Visual Studio 2008 Professional Edition - ENU (KB967143) KB967143 This update is for Microsoft Visual Studio 2008 Professional Edition - ENU. If you later install a more recent service pack, this update will be uninstalled automatically. For more information, visit http://support.microsoft.com/kb/967143.

Visual Studio Package Load Analyzer 1.0 A utility that analyzes package load failures in Visual Studio.

VSCommands 1.0 VSCommands adds new functionality to the IDE.

.NET Reflector Visual Studio add-in that integrates .NET Reflector into Visual Studio to allow you to seamlessly debug into third-party code and assemblies, even if you don't have the source code for them. Visit www.red-gate.com for more information. Copyright (c) 2009-2010 Red Gate Software Inc.

ANTS Memory Profiler 5 Add-in For more information about ANTS Profiler 5, see the website at http://www.red-gate.com Copyright (c) Red Gate Software Ltd 1999-2009

Dave Sexton's DocProject For more information, go to http://www.codeplex.com/DocProject Copyright © 2006-2008 Dave Sexton http://davesexton.com

DevExpress Tools DXCore extensibility layer for Visual Studio .NET, from Developer Express, Inc. (www.devexpress.com).

EDIT:

Strangely enough, looks like other folks fail to reproduce it. Though it does crash on my machine every time. I found out that this code:

Console.WriteLine(typeof(EntityBase).GetProperty("Id", BindingFlags.Instance | BindingFlags.Public, null, typeof(object), Type.EmptyTypes, null));

Does work OK, although it should be the same.

A: 

Was this ever resolved? I currently have a very similar issue...

abstract class A
{
    public virtual Int64 Id { get; set; }
}

class B : A
{
    public override Int64 Id { get{...} set {...} }
}

Calling typeof(B).GetProperty("Id") works fine on my machine (returns the PropertyInfo of the overriden Id property in class B, however, a colleague of mine runs the same code on his machine and he get the AmbiguousMatchException thrown.

Any ideas?

Scott