@@ -531,7 +531,7 @@ void CorProfiler::RewritingPInvokeMaps(const ModuleMetadata& module_metadata, co
531
531
profiler_ref);
532
532
if (FAILED (hr))
533
533
{
534
- Logger::Warn (" ModuleLoadFinished : DefinePinvokeMap to the actual profiler file path "
534
+ Logger::Warn (" RewritingPInvokeMaps : DefinePinvokeMap to the actual profiler file path "
535
535
" failed, trying to restore the previous one." );
536
536
hr = metadata_emit->DefinePinvokeMap (methodDef, pdwMappingFlags,
537
537
WSTRING (importName).c_str (), importModule);
@@ -540,15 +540,15 @@ void CorProfiler::RewritingPInvokeMaps(const ModuleMetadata& module_metadata, co
540
540
// We only warn that we cannot rewrite the PInvokeMap but we still continue the module
541
541
// load.
542
542
// These errors must be handled on the caller with a try/catch.
543
- Logger::Warn (" ModuleLoadFinished : Error trying to restore the previous PInvokeMap." );
543
+ Logger::Warn (" RewritingPInvokeMaps : Error trying to restore the previous PInvokeMap." );
544
544
}
545
545
}
546
546
}
547
547
else
548
548
{
549
549
// We only warn that we cannot rewrite the PInvokeMap but we still continue the module load.
550
550
// These errors must be handled on the caller with a try/catch.
551
- Logger::Warn (" ModuleLoadFinished : DeletePinvokeMap failed" );
551
+ Logger::Warn (" RewritingPInvokeMaps : DeletePinvokeMap failed" );
552
552
}
553
553
}
554
554
@@ -559,7 +559,7 @@ void CorProfiler::RewritingPInvokeMaps(const ModuleMetadata& module_metadata, co
559
559
{
560
560
// We only warn that we cannot rewrite the PInvokeMap but we still continue the module load.
561
561
// These errors must be handled on the caller with a try/catch.
562
- Logger::Warn (" ModuleLoadFinished : Native Profiler DefineModuleRef failed" );
562
+ Logger::Warn (" RewritingPInvokeMaps : Native Profiler DefineModuleRef failed" );
563
563
}
564
564
}
565
565
}
@@ -716,9 +716,14 @@ HRESULT STDMETHODCALLTYPE CorProfiler::ModuleLoadFinished(ModuleID module_id, HR
716
716
}
717
717
}
718
718
719
- if (module_info.assembly .name == managed_profiler_name)
719
+ #ifdef _WIN32
720
+ const bool perform_netfx_redirect = runtime_information_.is_desktop () && IsNetFxAssemblyRedirectionEnabled ();
721
+ #else
722
+ const bool perform_netfx_redirect = false ;
723
+ #endif // _WIN32
724
+
725
+ if (perform_netfx_redirect || module_info.assembly .name == managed_profiler_name)
720
726
{
721
- // Fix PInvoke Rewriting
722
727
ComPtr<IUnknown> metadata_interfaces;
723
728
auto hr = this ->info_ ->GetModuleMetaData (module_id, ofRead | ofWrite, IID_IMetaDataImport2,
724
729
metadata_interfaces.GetAddressOf ());
@@ -740,17 +745,34 @@ HRESULT STDMETHODCALLTYPE CorProfiler::ModuleLoadFinished(ModuleID module_id, HR
740
745
module_info.assembly .app_domain_id , &corAssemblyProperty, enable_by_ref_instrumentation,
741
746
enable_calltarget_state_by_ref);
742
747
743
- const auto & assemblyImport = GetAssemblyImportMetadata (assembly_import);
744
- const auto & assemblyVersion = assemblyImport.version .str ();
748
+ #ifdef _WIN32
749
+ if (perform_netfx_redirect)
750
+ {
751
+ // On the .NET Framework redirect any assembly reference to the versions required by
752
+ // OpenTelemetry.AutoInstrumentation assembly, the ones under netfx/ folder.
753
+ RedirectAssemblyReferences (assembly_import, assembly_emit);
754
+ }
755
+ #endif // _WIN32
745
756
746
- Logger::Info (" ModuleLoadFinished: " , managed_profiler_name, " v" , assemblyVersion, " - Fix PInvoke maps" );
757
+ if (module_info.assembly .name == managed_profiler_name)
758
+ {
747
759
#ifdef _WIN32
748
- RewritingPInvokeMaps (module_metadata, windows_nativemethods_type);
760
+ RewritingPInvokeMaps (module_metadata, windows_nativemethods_type);
749
761
#else
750
- RewritingPInvokeMaps (module_metadata, nonwindows_nativemethods_type);
762
+ RewritingPInvokeMaps (module_metadata, nonwindows_nativemethods_type);
751
763
#endif // _WIN32
764
+ }
765
+
766
+ if (Logger::IsDebugEnabled ())
767
+ {
768
+ const auto & assemblyImport = GetAssemblyImportMetadata (assembly_import);
769
+ const auto & assemblyVersion = assemblyImport.version .str ();
770
+
771
+ Logger::Debug (" ModuleLoadFinished: done " , module_info.assembly .name , " v" , assemblyVersion);
772
+ }
752
773
}
753
- else
774
+
775
+ if (module_info.assembly .name != managed_profiler_name)
754
776
{
755
777
module_ids_.push_back (module_id);
756
778
0 commit comments