Azure / autorest

OpenAPI (f.k.a Swagger) Specification code generator. Supports C#, PowerShell, Go, Java, Node.js, TypeScript, Python
MIT License
4.61k stars 737 forks source link

[.NET] AmbiguousMatchException on initializing ServiceClient class #1542

Closed OlehUdovytskyi closed 4 years ago

OlehUdovytskyi commented 8 years ago

Hi 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 ?

wiktork commented 6 years ago

Also @jblackwell-thuzi @roboffer if you guys are willing to share D:\home\LogFiles\eventlog.xml, we do record some instrumentation failures into this log with the newest version of appinsights. Note there may be unrelated events there too, so please be sure to look over the file first.

KingEgonSANCTITY commented 6 years ago

@wiktork Thanks for looking into this. If it helps I was at version 2.00 of the web extension when I encountered the issue. Also it seems kind of a random occurrence as I have been using the mongo driver for a while now in the instance that now has the error. All instances of the driver use cause this now whereas this was not the case in as little as a month ago.

rrrr-o commented 6 years ago

@SergeyKanzhelev It looks like updating the application insights extension has solved our issue, originally I was using the "Restart Site" button in the Site Extensions part of Kudu after making changes and the problem still persisted even after removing application insights entirely.

Killing the w3wp exe from Process Explorer seems to have made it work so it does look like it was v2.0.0 as mentioned above. From reading the extension moves with the slot, so this would explain why switching from staging to live resolved it. I will verify this on our next deployment.

@wiktork I am happy to share that file with you privately

rrrr-o commented 6 years ago

@jblackwell-thuzi Try updating the application insights extension version and then killing the w3wp as I mentioned above, that solved it for us

MattHartz commented 6 years ago

Hi everyone,

So to address this issue do we just need to disable or update application insights?

Thanks!

wiktork commented 6 years ago

@MattHartz Yes, but make sure you restart all your instances to ensure that the updated version has taken effect. As mentioned by @roboffer, you may need to terminate your w3wp.exe processes from Process Explorer.

MiYanni commented 4 years ago

Seems the issue was resolved. Closing.