I'm working on an application with a GUI and a Powershell module in the same solution. On Windows 2008 R2 framework 4.5.2 I have the error message :
System.TypeInitializationException: The type initializer for 'ClassName' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
I fixed it quickly on the GUI module by using in the app.config :
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
But no way to fix it on the powershell dll module with the same fix :
I tried to add the System.Net.Http nuget package, removing the existing reference to 4.0.0.0 before installing this nuget package.
I know that installing the Framework 4.7.2 fixes the problem (I tested), but for reasons I cannot do it on 2008 R2 machines.
I have tried what is there : Build error "An attempt was made to load an assembly with an incorrect format " after upgrade net framework 4.5.2 to 4.7.1
also
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
and more...
But still no way to solve this problem with the PowerShell dll module only.
Thanks per advance for your answers.