diff --git a/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.NetFramework.cs b/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.NetFramework.cs index 5016955aa2..85b57fc019 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.NetFramework.cs +++ b/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.NetFramework.cs @@ -33,7 +33,30 @@ private static string ResolveManagedProfilerDirectory() return null; } - Logger.Debug("Requester [{0}] requested [{1}]", args?.RequestingAssembly?.FullName ?? "", args?.Name ?? ""); + Logger.Debug("Requester [{0}] requested [{1}]", args.RequestingAssembly?.FullName ?? "", args.Name ?? ""); + + // All MongoDB* are signed and does not follow https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/versioning#assembly-version + // There is no possibility to automatically redirect from 2.28.0 to 2.29.0. + // Loading assembly and ignoring this version. + if (assemblyName.StartsWith("MongoDB", StringComparison.OrdinalIgnoreCase) && + (string.Equals(assemblyName, "MongoDB.Driver.Core", StringComparison.OrdinalIgnoreCase) || + string.Equals(assemblyName, "MongoDB.Bson", StringComparison.OrdinalIgnoreCase) || + string.Equals(assemblyName, "MongoDB.Libmongocrypt", StringComparison.OrdinalIgnoreCase))) + { + try + { + var mongoAssembly = Assembly.Load(assemblyName); + Logger.Debug("Assembly.Load(\"{0}\") succeeded={1}", assemblyName, mongoAssembly != null); + return mongoAssembly; + } + catch (Exception ex) + { + Logger.Debug(ex, "Assembly.Load(\"{0}\") Exception: {1}", assemblyName, ex.Message); + } + + return null; + } + var path = Path.Combine(ManagedProfilerDirectory, $"{assemblyName}.dll"); if (File.Exists(path)) {