Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,11 @@ public static bool IsDefined(MemberInfo element, Type attributeType, bool inheri
if (attrib == null || attrib.Length == 0)
return null;

Attribute match = attrib[0];
if (attrib.Length == 1)
return attrib[0];
return match;

throw new AmbiguousMatchException(SR.RFLCT_AmbigCust);
throw ThrowHelper.GetAmbiguousMatchException(match);
}

#endregion
Expand Down Expand Up @@ -614,10 +615,11 @@ public static bool IsDefined(ParameterInfo element, Type attributeType, bool inh
if (attrib == null || attrib.Length == 0)
return null;

Attribute match = attrib[0];
if (attrib.Length == 1)
return attrib[0];
return match;

throw new AmbiguousMatchException(SR.RFLCT_AmbigCust);
throw ThrowHelper.GetAmbiguousMatchException(match);
}

#endregion
Expand Down Expand Up @@ -683,10 +685,11 @@ public static bool IsDefined(Module element, Type attributeType, bool inherit)
if (attrib == null || attrib.Length == 0)
return null;

Attribute match = attrib[0];
if (attrib.Length == 1)
return attrib[0];
return match;

throw new AmbiguousMatchException(SR.RFLCT_AmbigCust);
throw ThrowHelper.GetAmbiguousMatchException(match);
}

#endregion
Expand Down Expand Up @@ -752,10 +755,11 @@ public static bool IsDefined(Assembly element, Type attributeType, bool inherit)
if (attrib == null || attrib.Length == 0)
return null;

Attribute match = attrib[0];
if (attrib.Length == 1)
return attrib[0];
return match;

throw new AmbiguousMatchException(SR.RFLCT_AmbigCust);
throw ThrowHelper.GetAmbiguousMatchException(match);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2822,9 +2822,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
{
MethodInfo methodInfo = candidates[j];
if (!System.DefaultBinder.CompareMethodSig(methodInfo, firstCandidate))
{
throw new AmbiguousMatchException();
}
throw ThrowHelper.GetAmbiguousMatchException(firstCandidate);
}

// All the methods have the exact same name and sig so return the most derived one.
Expand Down Expand Up @@ -2878,10 +2876,10 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (types == null || types.Length == 0)
{
// no arguments
PropertyInfo firstCandidate = candidates[0];

if (candidates.Count == 1)
{
PropertyInfo firstCandidate = candidates[0];

if (returnType is not null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
return null;

Expand All @@ -2891,7 +2889,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
{
if (returnType is null)
// if we are here we have no args or property type to select over and we have more than one property with that name
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(firstCandidate);
}
}

Expand Down Expand Up @@ -2920,7 +2918,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if ((bindingAttr & eventInfo.BindingFlags) == eventInfo.BindingFlags)
{
if (match != null)
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(match);

match = eventInfo;
}
Expand Down Expand Up @@ -2950,7 +2948,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (match != null)
{
if (ReferenceEquals(fieldInfo.DeclaringType, match.DeclaringType))
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(match);

if ((match.DeclaringType!.IsInterface) && (fieldInfo.DeclaringType!.IsInterface))
multipleStaticFieldMatches = true;
Expand All @@ -2962,7 +2960,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
}

if (multipleStaticFieldMatches && match!.DeclaringType!.IsInterface)
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(match);

return match;
}
Expand Down Expand Up @@ -2998,7 +2996,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (FilterApplyType(iface, bindingAttr, name, false, ns))
{
if (match != null)
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(match);

match = iface;
}
Expand Down Expand Up @@ -3027,7 +3025,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (FilterApplyType(nestedType, bindingAttr, name, false, ns))
{
if (match != null)
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(match);

match = nestedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static Attribute OneOrNull(IEnumerable<CustomAttributeData> results)
return null;
CustomAttributeData result = enumerator.Current;
if (enumerator.MoveNext())
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(result);
return result.Instantiate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ public void CopyTo(MemberInfo[] array, int startIndex)
// Assuming the policy says it's ok to ignore the ambiguity, we're to resolve in favor of the member
// declared by the most derived type. Since QueriedMemberLists are sorted in order of decreasing derivation,
// that means we let the first match win - unless, of course, they're both the "most derived member".
if (match.DeclaringType.Equals(challenger.DeclaringType))
throw new AmbiguousMatchException();

if (!_policies.OkToIgnoreAmbiguity(match, challenger))
throw new AmbiguousMatchException();
// If they're not from same type, we throw if the policy doesn't allow ambiguity.
if (match.DeclaringType.Equals(challenger.DeclaringType) ||
!_policies.OkToIgnoreAmbiguity(match, challenger))
throw ThrowHelper.GetAmbiguousMatchException(match);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public sealed override Type[] GetGenericArguments()
if (ns != null && !ns.Equals(ifc.Namespace))
continue;
if (match != null)
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(match);
match = ifc;
}
return match;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,21 @@ protected sealed override PropertyInfo GetPropertyImpl(string name, BindingFlags
if (types == null || types.Length == 0)
{
// no arguments
PropertyInfo firstCandidate = candidates[0];

if (candidates.Count == 1)
{
PropertyInfo firstCandidate = candidates[0];
if (returnType is not null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
return null;
return firstCandidate;
}
else
{
if (returnType is null)
{
// if we are here we have no args or property type to select over and we have more than one property with that name
throw new AmbiguousMatchException();
throw ThrowHelper.GetAmbiguousMatchException(firstCandidate);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public sealed override bool Bind(RuntimeAssemblyName refName, bool cacheMissedLo
{
if (foundMatch)
{
exception = new AmbiguousMatchException();
exception = new AmbiguousMatchException(SR.Format(SR.AmbiguousMatchException_Assembly, refName.FullName));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -129,4 +129,7 @@
<data name="FileLoadException_RefDefMismatch" xml:space="preserve">
<value>Cannot load assembly '{0}'. The assembly exists but its version {1} is lower than the requested version {2}.</value>
</data>
<data name="AmbiguousMatchException_Assembly" xml:space="preserve">
<value>Ambiguous match found for assembly '{0}'.</value>
</data>
</root>
20 changes: 13 additions & 7 deletions src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,27 @@
<data name="AppDomain_Policy_PrincipalTwice" xml:space="preserve">
<value>Default principal object cannot be set twice.</value>
</data>
<data name="AmbiguousImplementationException_NullMessage" xml:space="preserve">
<value>Ambiguous implementation found.</value>
</data>
<data name="Arg_AccessException" xml:space="preserve">
<value>Cannot access member.</value>
</data>
<data name="Arg_AccessViolationException" xml:space="preserve">
<value>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</value>
</data>
<data name="Arg_AmbiguousMatchException" xml:space="preserve">
<data name="Arg_AmbiguousImplementationException_NoMessage" xml:space="preserve">
<value>Ambiguous implementation found.</value>
</data>
<data name="Arg_AmbiguousMatchException_Attribute" xml:space="preserve">
<value>Multiple custom attributes of the same type '{0}' found.</value>
</data>
<data name="Arg_AmbiguousMatchException_NoMessage" xml:space="preserve">
<value>Ambiguous match found.</value>
</data>
<data name="Arg_AmbiguousMatchException_CustomAttributeData" xml:space="preserve">
<value>Ambiguous match found for '{0}'.</value>
</data>
<data name="Arg_AmbiguousMatchException_MemberInfo" xml:space="preserve">
<value>Ambiguous match found for '{0} {1}'.</value>
</data>
<data name="Arg_ApplicationException" xml:space="preserve">
<value>Error in the application.</value>
</data>
Expand Down Expand Up @@ -3299,9 +3308,6 @@
<data name="Resources_StreamNotValid" xml:space="preserve">
<value>Stream is not a valid resource file.</value>
</data>
<data name="RFLCT_AmbigCust" xml:space="preserve">
<value>Multiple custom attributes of the same type found.</value>
</data>
<data name="InvalidFilterCriteriaException_CritInt" xml:space="preserve">
<value>An Int32 must be provided for the filter criteria.</value>
</data>
Expand Down
Loading