[CSHARP-2393] Driver is not compatible with .NET 4.7.1 Created: 23/Sep/18 Updated: 08/Mar/19 Resolved: 08/Mar/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Build |
| Affects Version/s: | 2.7.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Maxime Rossini | Assignee: | Robert Stam |
| Resolution: | Duplicate | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 10, Visual Studio 2017 15.8.5, .NET framework 4.7.1 |
||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Case: | (copied to CRM) | ||||||||||||||||||||||||||||||||
| Description |
|
I created a simple console app running under .NET 4.7.1, added the MongoDB.Driver nuget package with highest versions dependencies. I end up with a very simple project with the following files:
When I execute this program, I get the following error at runtime:
The exact same program works when I target .NET framework 4.7 instead of 4.7.1 (and update the package.config accordingly). It seems to be related to the fact that .NET 4.7.1 includes the DLL System.Runtime.InteropServices.RuntimeInformation in-box, whereas .NET 4.7 does not. Maybe the Mongo.Driver.Core package should not reference this nuget package when targeting .NET framework 4.7.1. |
| Comments |
| Comment by Antuan [ 23/Oct/18 ] |
|
>>mrossini@maskott.com added a comment - Oct 02 2018 09:25:43 AM GMT+0000 You are absolutely right! I have encountered with the same problem with MongoDb Driver, System.Runtime.InteropServices.RuntimeInformation and .NET 4.7.1. And i also think, that strict dependence of target version 4.0.0.0 should be removed from Mongo nuget for frameworks 4.7.1 or higher. Current situation is very painful for us, because our application depends on different components with 4.7.1, therefore we can not decrease framework version.
Anyone can tell (approximately) when the fix is planned to be released? Thanks
|
| Comment by Maxime Rossini [ 02/Oct/18 ] |
|
Just to clarify:
To actually fix the bug without using a workaround, you need to add a TargetFramework in your solution with ID net471. This target will be used by applications built against .NET framework >= 4.7.1. You need to remove the dependency on the System.Runtime.InteropServices.RuntimeInformation NuGet for this target framework. To be fair, it's a lot easier to do that with a single solution for all target frameworks using the new .csproj format / packageReference syntax. What I personnaly don't understand is the fact that the binding redirect from 0.0.0.0-4.0.2.0 to 4.0.2.0 breaks the application, since the same code without any binding redirect actually works. It must be related to the way the assembly linker loads dependent assemblies: one of the conflicting dependencies may be loaded without using the binding redirect instruction, or the binding redirect does not find the 4.7.1 GAC assemblies for some other reason. |
| Comment by Melvin Go [ 01/Oct/18 ] |
|
Is there an ETA for a fix? |
| Comment by Robert Stam [ 01/Oct/18 ] |
|
I must confess that I don't completely understand every nuance of what's going on here, but I have been able to reproduce this and have verified a workaround that appears to work. Note that the C# driver depends on version 4.0.0 of System.Runtime.InteropServices.RuntimeInformation. Version 4.0.0 was the current version number at the time we took the dependency. Since then version 4.3.0 has come out. (Note: confusingly the Assembly Version for 4.3.0 is 4.0.1.0). I was able to get the test program working when targetting .NET Framework 4.7.1 by:
Our current Nuget package has assets for two target frameworks: .NET Framework 4.5 and .NET Standard 1.5. We are not yet in a position to add more, but will be soon (when we finish updating our solution to target multiple frameworks from a single solution). We also intend to update the dependency on System.Runtime.InteropServices.RuntimeInformation from 4.0.0 to 4.3.0. We have been delaying that because of uncertainty as to whether that would break any existing applications. |
| Comment by Maxime Rossini [ 30/Sep/18 ] |
|
Interestingly, your workaround is effective. Some elements of context:
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. When removing the binding redirect completely, it works, but I don't understand why. Well, actually I don't understand why it doesn't work with the 4.0.2.0 binding redirect while this DLL is located in a folder accessible to the application ("C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\Facades"). Anyway this should be fixed by adding a new framework target in the MongoDB.Driver package (net471) which should not depend on the System.Runtime.InteropServices.RuntimeInformation nuget package, as this DLL is included in the framework starting with net471. By using the workaround, I am afraid any package update/reinstallation will break our application again by re-adding the binding redirect. |
| Comment by Melvin Go [ 27/Sep/18 ] |
|
My team is running into a very similar issue with .NET 4.7.2 and we have a workaround. These links contain the other info I think is relevant to the problem you're facing: https://github.com/dotnet/standard/issues/567 https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes
Check if you have a binding redirect in your App.config. If so, try to remove the binding redirect and see if your code works at runtime. This is the workaround mentioned in the github link above. I linked to the visual studio 15.8 release notes because that is the version of Visual Studio that officially supports .NET Framework 4.7.2. When I tried to the MongoDB.Driver nuget to a console app while using VS 15.7.4, the redirects were not added. After I upgraded to the latest version, VS 15.8.5, the redirects started happening. I know you're using 4.7.1, but I mentioned 4.7.2 because that is the version our team was testing with and getting similar results to you.
I think the fix is to have the MongoDB.Driver nuget retargeted to .NET 4.7.2. |