How to get Microsoft.Extensions.Http in COM+ to work?

Pappas Alexandros 1 Reputation point
2023-05-04T11:46:56.4866667+00:00

Hello,

We use IHttpClientFactory in a .NET 4.7 COM+ class. To be able to use IHttpClientFactory, we added the Nuget package Microsoft.Extensions.Http version 7.0, which installed the following dlls in the packages directory:

Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll
Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.DependencyInjection.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.Http.7.0.0\lib\net462\Microsoft.Extensions.Http.dll
Microsoft.Extensions.Logging.7.0.0\lib\net462\Microsoft.Extensions.Logging.dll
Microsoft.Extensions.Logging.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Options.7.0.0\lib\net462\Microsoft.Extensions.Options.dll
Microsoft.Extensions.Primitives.7.0.0\lib\net462\Microsoft.Extensions.Primitives.dll
System.Buffers.4.5.1\lib\net461\System.Buffers.dll
System.Diagnostics.DiagnosticSource.7.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll
System.Memory.4.5.5\lib\net461\System.Memory.dll
System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll
System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll
System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll

We installed these dlls in the GAC with gacutil. Upon calling the method HttpClient.PostAsync we get the exception:

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  1. What do we have to do, so that COM+ can find this dll?
  2. Is it safe to install the above dlls in the GAC on a production server with Windows Server 2012?
  3. The name "System.Runtime.CompilerServices.Unsafe.dll" does not suggest safeness. Is it really safe for a production environment?
  4. Is it safe to use HttpClientFactory in a COM+ class?
  5. The following solution demonstrates the problem: https://github.com/pappasa/TestHttpClientFactory

Best regards,

Alexandros

Windows for business Windows Server User experience Other
Developer technologies .NET Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,746 Reputation points
    2023-05-05T18:26:23.4+00:00

    Hello there,

    What do we have to do, so that COM+ can find this dll?

    It's common for multiple versions of the same dynamic-link library (DLL) to exist in different file system locations within an operating system (OS). You can control the specific location from which any given DLL is loaded by specifying a full path. But if you don't use that method, then the system searches for the DLL at load time as described in this topic. The DLL loader is the part of the operating system (OS) that loads DLLs and/or resolves references to DLLs.

    This article might help you https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.