@@ -63,22 +63,23 @@ internal static BsonDocument CreateClientDocument(string applicationName, BsonDo
63
63
internal static BsonDocument CreateDriverDocument ( )
64
64
{
65
65
var assembly = typeof ( ConnectionInitializer ) . GetTypeInfo ( ) . Assembly ;
66
- var fileVersionAttribute = assembly . GetCustomAttribute < AssemblyFileVersionAttribute > ( ) ;
67
- var driverVersion = fileVersionAttribute . Version ;
66
+ var driverVersion = GetAssemblyVersion ( assembly ) ;
68
67
69
68
return CreateDriverDocument ( driverVersion ) ;
70
69
}
71
70
72
71
internal static BsonDocument CreateDriverDocument ( string driverVersion )
73
72
{
74
73
var driverName = "mongo-csharp-driver" ;
75
- if ( TryGetType ( "MongoDB.Driver.MongoServer, MongoDB.Driver.Legacy" ) )
74
+ if ( TryGetType ( "MongoDB.Driver.MongoServer, MongoDB.Driver.Legacy" , out _ ) )
76
75
{
77
76
driverName = $ "{ driverName } |legacy";
78
77
}
79
78
80
- if ( TryGetType ( "MongoDB.EntityFrameworkCore.Query.MongoQueryContext, MongoDB.EntityFrameworkCore" ) )
79
+ if ( TryGetType ( "MongoDB.EntityFrameworkCore.Query.MongoQueryContext, MongoDB.EntityFrameworkCore" , out var queryContextType ) )
81
80
{
81
+ var efVersion = GetAssemblyVersion ( queryContextType . Assembly ) ;
82
+ driverVersion = $ "{ driverVersion } |{ efVersion } ";
82
83
driverName = $ "{ driverName } |efcore";
83
84
}
84
85
@@ -183,7 +184,7 @@ internal static BsonDocument CreateOSDocument()
183
184
string architecture ;
184
185
string osVersion ;
185
186
186
- if ( TryGetType ( "Mono.Runtime" ) )
187
+ if ( TryGetType ( "Mono.Runtime" , out _ ) )
187
188
{
188
189
switch ( Environment . OSVersion . Platform )
189
190
{
@@ -372,19 +373,33 @@ internal static BsonDocument RemoveOptionalFieldsUntilDocumentIsLessThan512Bytes
372
373
return clientDocument ;
373
374
}
374
375
375
- private static bool TryGetType ( string typeName )
376
+ private static bool TryGetType ( string typeName , out Type type )
376
377
{
377
378
try
378
379
{
379
- var type = Type . GetType ( typeName ) ;
380
+ type = Type . GetType ( typeName ) ;
380
381
return type != null ;
381
382
}
382
383
catch
383
384
{
384
385
// ignore any exceptions here.
386
+ type = null ;
385
387
return false ;
386
388
}
387
389
}
390
+
391
+ private static string GetAssemblyVersion ( Assembly assembly )
392
+ {
393
+ var versionAttribute = assembly . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ;
394
+ var hashIndex = versionAttribute . InformationalVersion . IndexOf ( '+' ) ;
395
+ if ( hashIndex == - 1 )
396
+ {
397
+ return versionAttribute . InformationalVersion ;
398
+ }
399
+
400
+ return versionAttribute . InformationalVersion . Substring ( 0 , hashIndex ) ;
401
+ }
402
+
388
403
#endregion
389
404
}
390
405
}
0 commit comments