[.NET] AmbiguousMatchException on initializing ServiceClient class
See original GitHub issueHi guys.
I have an issue with initializing my service client created by AutoRest and inherited from ServiceClient
.
It throws AmbiguousMatchException
and it arises in ServiceClient
class.
[AmbiguousMatchException: Multiple custom attributes of the same type found.]
System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) +122
Microsoft.Rest.ServiceClient`1.get_FrameworkVersion() +103
Microsoft.Rest.ServiceClient`1.SetDefaultUserAgentInfo() +177
Microsoft.Rest.ServiceClient`1.SetUserAgent(String productName, String version) +50
Microsoft.Rest.ServiceClient`1..ctor(DelegatingHandler[] handlers) +61
It only appears on my Remote machine with Windows Server 2008 R2 Standart .NET Framework 4.6.1. Locally on Windows 10 Anniversary 4.6.2 Framework everything is ok.
In Microsoft.Rest.ServiceClient I’ve found next part of code in ClientVersion
property getter:
try
{
AssemblyInformationalVersionAttribute customAttribute1 = assembly.GetCustomAttribute(typeof (AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
this._clientVersion = customAttribute1 != null ? customAttribute1.InformationalVersion : (string) null;
if (string.IsNullOrEmpty(this._clientVersion))
{
AssemblyFileVersionAttribute customAttribute2 = assembly.GetCustomAttribute(typeof (AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute;
this._clientVersion = customAttribute2 != null ? customAttribute2.Version : (string) null;
}
}
catch (AmbiguousMatchException ex)
{
}
I think it is source of my problem but I don’t understand why it occurs and to handle it. I see that current exception must be caught but I don’t have any other ideas what else can be wrong.
Guys, any ideas ?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:107 (6 by maintainers)
Top Results From Across the Web
AmbiguousMatchException Constructor (System.Reflection)
Initializes a new instance of the AmbiguousMatchException class with its message string set to the given message and the root cause exception set...
Read more >ASP.NET Core 3.1 MVC returning ...
The server is throwing an error 500 at the end of the startup process. Exception: Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: ...
Read more >OpenEdge Development - Forum
Net Class en App Builder, Last post by gaspar_julian 28-Feb-2020 20:47, 6 ... AmbiguousMatchException: Ambiguous match found.
Read more >[Solved]-VBA Match to C#-C#
Try this result = Application.WorksheetFunction.Match(stringA, Range(stringB), 0); if (iTemp_result == 0) { DoStuff(); }.
Read more >Expert C# 2005 Business Objects, Second Edition
The CommandBase class provides a clear starting point for implementing these types of behav- iors. A command object is created on the client...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Downgrading Microsoft.Rest.ClientRuntime from 2.3.3 to 2.3.2 has fixed the issue for me.
Adding info from my troubleshooting this problem.
In my case, the “Application Insights Monitor” (https://github.com/Azure/azure-content/blob/master/articles/application-insights/app-insights-monitor-performance-live-website-now.md) was injecting an additional “AssemblyFileVersionAttribute” value into mscorlib.dll. So, the Microsoft.Rest.ClientRuntime error makes sense because when it tries to get the file version using that attribute, it is, in fact, ambiguous.
Does it ever make sense to have more than one “AssemblyFileVersionAttribute” on any file? If not, there’s at least a bug in the tool I just mentioned.
Regardless of the answer to number 1, you’ll see that the code for Microsoft.Rest.ClientRuntime tries to use “AssemblyFileVersionAttribute” more than once. In one instance, it catches and ignores AmbiguousReferenceException and in other instances, it is not. I believe it should be consistent. Either it’s always safe to ignore it, or it’s not.