Dependecy Injection Framework like Unity, Autofac not working with .NET framework 4.7 and above RRS feed

  • Question

  • There was a project on .NET framework 4.5 which has been migrated to .NET 4.7

    My project is a class library consumed by 3rd party application in which i am calling another WPF project where i am using Dependency injection.

    I was using Unity as Dependency Injection Framework which was working fine.


    The above DLL's were imported with Nuget package "Unity".

    Now in Framework 4.7 this DLL "System.Runtime.CompilerServices.Unsafe" stopped working as it is not supported.

    I also tried using Autofac in 4.7 but that also did not work because of the DLL "System.Threading.Tasks.Extensions".

    Can someone suggest another stable framework or help me in fixing the above issues?

    Wednesday, February 26, 2020 11:56 AM

All replies

  • Try the suggestions here and see if they helps.

    In particular, I would try to see if it is "a referenced project or library is loading a different version of component" case.

    Thursday, February 27, 2020 1:42 AM
  • The link is not working
    Thursday, February 27, 2020 3:50 AM
  • If occurs to me that the "System.Runtime.CompilerServices" is not in the referencesource website of .NET Framework (only exists in .NET Core as standalone DLL in MSIL format), also it is nowhere to find in my machines except those .NET Core library folders. The documentation page also said it is for .NET Core or .NET Platform Extension code to use.

    Have you accidentially included library/projects that need .NET Core/.NET Platform Extension libraries in your project in the past? What if you manually add back the missing packages via the Package Manager? (this package has .NET Framework 4.5 support, should still work fine in v4.7)

    Thursday, February 27, 2020 5:55 AM
  • I added unity framework from Nuget which imported this "System.Runtime.CompilerServices" DLL.

    This has come from .NET Framework. When i created an independent WPF Project with .NET Framework 4.7 it is working which i have just tested.

    But when my 3rd party application is calling DLL which is consumed by the application it is throwing the exception

    Thursday, February 27, 2020 6:53 AM
  • Not sure what caused the problem then.

    Regarding DI frameworks, I've used Ninject some years ago. Check their website on how to use it. However I'm not sure whether it'll suit your need. And there is a major problem for new users - both the Documentation website and Wiki for this project is down. If you plan to use this you may need to go search the StackOverflow forum for possible instructions.

    Thursday, February 27, 2020 10:46 AM