Question: Is there any way in .NET Core 2.0 (netstandard 2.0) how I could apply assembly redirections NOT defined in given application.exe.config
file when running executable? Maybe some programmatic way? Or even by running executable with some special settings/flags?
Scenario: Here is simplified scenario that I'm trying to solve in .NET Core 2.0.
ServiceHost.exe
.dll
, let's call it Service.dll
, which implements some entry interface IService
with method Start()
.ServiceHost.exe --service-assembly Service.dll
it loads service and calls its IService.Start()
implementation.Let's say that the service needs some assembly redirects. It's quite common in .NET Core world when you reference much more packages than in old .NET Framework and not all of them have exact versions for latest .NET Core. Using assembly redirects works quite well and allows you to use library targeting older version just fine.
And here comes the problem with my setup. Since Service.dll
is a library which is loaded by independent executable its app.config
file with assembly redirects is not used. Runtime uses ServiceHost.exe.config
and not Service.dll.config
, which is expected.
Reminder: I'm using .NET Core so solution with creating new Application Domain and setting it to load different config file is not an option.
We use a servicehost that is NetCore targeting NetFramework, you can use Automatic binding redirects:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
This then generates the binding redirects automatically in the Servicehost.exe.config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With