[CSHARP-1863] Multiple custom attributes of the same type found error. Created: 06/Dec/16  Updated: 27/Oct/23  Resolved: 28/Apr/17

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ivan Fioravanti Assignee: Robert Stam
Resolution: Works as Designed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Azure Cloud Service OS Family 5



 Description   

We are having a strange issue, probably related to bug CSHARP-1807. Using full .NET Framework we are now using System.Runtime.InteropServices.RuntimeInformation 4.0.1.0 (coming from NuGet package 4.3.0.0) and when app runs on an Azure Cloud Service we have following exception:

 	 	 	
Multiple custom attributes of the same type found. 
at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) 
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) 
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) 
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) 
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) 
Multiple custom attributes of the same type found. 
at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) 
at System.Runtime.InteropServices.RuntimeInformation.get_FrameworkDescription() 
at System.Lazy`1.CreateValue() 
at System.Lazy`1.LazyInitValue() 
at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateClientDocument(String applicationName) 
at MongoDB.Driver.Core.Connections.BinaryConnectionFactory..ctor(ConnectionSettings settings, IStreamFactory streamFactory, IEventSubscriber eventSubscriber) 
at MongoDB.Driver.Core.Configuration.ClusterBuilder.BuildCluster() 
at MongoDB.Driver.ClusterRegistry.CreateCluster(ClusterKey clusterKey) 
at MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(ClusterKey clusterKey) 
at MongoDB.Driver.MongoClient..ctor(MongoClientSettings settings) 
at 



 Comments   
Comment by Robert Stam [ 28/Apr/17 ]

Closing this as "Works as Designed" since the problem lies with components outside of the .NET Driver.

Comment by Mikhail Belov [ 13/Feb/17 ]

Yes, swtiching off the diagnostincs tool helped, but I wouldn't call it "resolved" =). Hope, MS guys will be able to fix it ASAP.

Comment by Peter Sunde [ 12/Feb/17 ]

Thanks for the tip Mikhail, uninstalling the application insights status monitor toolkit from all servers resolved the issue

Comment by Mikhail Belov [ 11/Feb/17 ]

Application Insights may be the reason: https://github.com/Azure/autorest/issues/1542

Just in case someone else face with this.

Comment by Mikhail Belov [ 11/Feb/17 ]

Hi, the same is actual for me too. I have ASP.NET MVC app and it works ok on my laptop on W10 x64 under IIS 10.0.10586.0). Also it works on Windows Server 2012 R2 Azure VM under IIS 8.5. But when I deploy my app to Azure cloud service it doesn't work.

Target framework 4.5.2
Driver version 2.4.1

Here is the stack trace:

System.Reflection.AmbiguousMatchException: Multiple custom attributes of the same type found.
at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
at System.Runtime.InteropServices.RuntimeInformation.get_FrameworkDescription()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at MongoDB.Driver.Core.Connections.ConnectionInitializer..ctor(String applicationName)
at MongoDB.Driver.Core.Connections.BinaryConnectionFactory..ctor(ConnectionSettings settings, IStreamFactory streamFactory, IEventSubscriber eventSubscriber)
at MongoDB.Driver.Core.Configuration.ClusterBuilder.BuildCluster()
at MongoDB.Driver.ClusterRegistry.CreateCluster(ClusterKey clusterKey)
at MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(ClusterKey clusterKey)
at MongoDB.Driver.MongoClient..ctor(MongoClientSettings settings)

Comment by Robert Stam [ 22/Dec/16 ]

Any more information on this issue and how to reproduce it?

Comment by Robert Stam [ 06/Dec/16 ]

By way of a test, the following code does not throw an exception when run in a console application using .NET Framework 4.6:

public static void Main(string[] args)
{
    var attr = (AssemblyFileVersionAttribute)typeof(object).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
    Console.WriteLine(attr.Version);
}

Comment by Robert Stam [ 06/Dec/16 ]

Do you know the actual type of the exception?

I'm assuming it must be an AmbiguousMatchException.

https://msdn.microsoft.com/en-us/library/k7s8054x(v=vs.110).aspx#Exceptions

Comment by Robert Stam [ 06/Dec/16 ]

That exception would appear to be coming from here:

https://github.com/dotnet/corefx/blob/master/src/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs#L28

Could this be a bug in System.Runtime.InteropServices.RuntimeInformation?

Why would GetCustomAttribute throw an exception on this line? Does the assembly that contains typeof(object) have multiple AssemblyFileVersionAttributess?

Generated at Wed Feb 07 21:40:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.