MongoDb.Driver上的System.Reflection.AmbiguousMatchException

时间:2018-05-31 22:26:22

标签: c# mongodb asp.net-web-api

所有。 我用ASP.NET 4和Mongo创建了Rest API。它在Windows 10下的本地PC上工作正常,在Windows 2008 R2 + .NET 4.7.1下的测试环境中也能正常工作。但它在Windows 2012 R2 + .NET 4.7.1下对我的prod环境无效,我收到以下错误:

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.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 Treolan.Catalog.Providers.BaseDataProvider..ctor(IAppSettings appSettings) in D:\Projects\TreolanCatalog\Treolan\Treolan.Catalog.Providers\BaseDataProvider.cs:line 39
   at Treolan.Catalog.Providers.Categories.CategoriesProvider..ctor(IAppSettings appSettings) in D:\Projects\TreolanCatalog\Treolan\Treolan.Catalog.Providers\Categories\CategoriesProvider.cs:line 22
   at Treolan.Catalog.WebApi.Controllers.CategoriesController.<>c.<.ctor>b__6_0() in D:\Projects\TreolanCatalog\Treolan\Treolan.Catalog.WebApi2\Controllers\CategoriesController.cs:line 31
   at Treolan.Catalog.WebApi.Controllers.CategoriesController.<Get>d__7.MoveNext() in D:\Projects\TreolanCatalog\Treolan\Treolan.Catalog.WebApi2\Controllers\CategoriesController.cs:line 48

我发现了类似的问题,但其他开发人员在Azure上使用了Application Insight。我不使用Application Insight或Azure。

我尝试使用MongoDb.Driver 2.5.0和2.6.1,但我遇到了同样的问题。

你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,经过搜索,我找到了解决方案

我的应用程序在Azure VM中

要解决这个问题

使用终端服务器转到此计算机, 转到控制面板, 进入程序/功能 从服务器上删除应用程序洞察力状态监控器工具包

这已经为我解决了这个问题

希望有帮助