@@ -72,12 +72,12 @@ internal static BsonDocument CreateDriverDocument()
72
72
internal static BsonDocument CreateDriverDocument ( string driverVersion )
73
73
{
74
74
var driverName = "mongo-csharp-driver" ;
75
- if ( IsLegacyLoaded ( ) )
75
+ if ( TryGetType ( "MongoDB.Driver.MongoServer, MongoDB.Driver.Legacy" ) )
76
76
{
77
77
driverName = $ "{ driverName } |legacy";
78
78
}
79
79
80
- if ( IsEFLoaded ( ) )
80
+ if ( TryGetType ( "MongoDB.EntityFrameworkCore.Query.MongoQueryContext, MongoDB.EntityFrameworkCore" ) )
81
81
{
82
82
driverName = $ "{ driverName } |efcore";
83
83
}
@@ -87,16 +87,6 @@ internal static BsonDocument CreateDriverDocument(string driverVersion)
87
87
{ "name" , driverName } ,
88
88
{ "version" , driverVersion }
89
89
} ;
90
-
91
- bool IsLegacyLoaded ( )
92
- {
93
- return Type . GetType ( "MongoDB.Driver.MongoServer, MongoDB.Driver.Legacy" ) != null ;
94
- }
95
-
96
- bool IsEFLoaded ( )
97
- {
98
- return Type . GetType ( "MongoDB.EntityFrameworkCore.Query.MongoQueryContext, MongoDB.EntityFrameworkCore" ) != null ;
99
- }
100
90
}
101
91
102
92
internal static BsonDocument CreateEnvDocument ( )
@@ -193,7 +183,7 @@ internal static BsonDocument CreateOSDocument()
193
183
string architecture ;
194
184
string osVersion ;
195
185
196
- if ( Type . GetType ( "Mono.Runtime" ) != null )
186
+ if ( TryGetType ( "Mono.Runtime" ) )
197
187
{
198
188
switch ( Environment . OSVersion . Platform )
199
189
{
@@ -381,6 +371,20 @@ internal static BsonDocument RemoveOptionalFieldsUntilDocumentIsLessThan512Bytes
381
371
382
372
return clientDocument ;
383
373
}
374
+
375
+ private static bool TryGetType ( string typeName )
376
+ {
377
+ try
378
+ {
379
+ var type = Type . GetType ( typeName ) ;
380
+ return type != null ;
381
+ }
382
+ catch
383
+ {
384
+ // ignore any exceptions here.
385
+ return false ;
386
+ }
387
+ }
384
388
#endregion
385
389
}
386
390
}
0 commit comments