0

I'm developing an application that runs on AutoCAD using .NET Framework 4.8 and Npgsql, following the MVVM pattern. In my project, I use Dependency Injection (DI) to manage the lifecycle of objects through Microsoft.Extensions.DependencyInjection. However, when I use this DI framework, I encounter a conflict and receive the following error:

Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral...'

If I remove Microsoft.Extensions.DependencyInjection, the program runs fine. I would like to know if there's a way to continue using DI in my project while ensuring Npgsql works without issues. I've also tried using Autofac for DI, but I encountered a similar error.

I also tried follow this answer but not working

I tried binding like this:

<dependentAssembly>
  <assemblyIdentity
    name="System.Threading.Tasks.Extensions"
    publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
  <bindingRedirect
    oldVersion="0.0.0.0-4.2.0.0"
    newVersion="4.2.0.0" />
</dependentAssembly>

but it's not working.

Is there a solution to this problem?

I still want to use Dependency Injection (DI) and Npgsql. Is there a way to use both without causing conflicts or encountering the error Could not load file or assembly ?'System.Threading.Tasks.Extensions, Version=4.2.0.0 Culture=neutral

5
  • Seems like you're missing some binding redirects. Commented Aug 12, 2024 at 15:07
  • I tried binding like this <dependentAssembly> <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" /> </dependentAssembly> but it's not working. Could you please explain more details? Commented Aug 12, 2024 at 15:52
  • I bet the full exception message is "Could not load file or assembly ... or one of its dependencies". The problem could, therefore, very well lie in one of System.Threading.Tasks.Extensions's dependencies. I struggled with this myself a few years ago and found it very difficult to find the correct set of binding redirects as there is a quite complex dependency graph below it. Commented Aug 12, 2024 at 20:41
  • You could also consider suppressing binding redirects completely using AssemblyResolve. I use this method in my applications and it prevents me from having to specify a single binding redirect. Commented Aug 12, 2024 at 20:46
  • I tried update Version of Npgsql , error above solved but new other error.System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. it's my Repository github.com/NguyenVung2305/SketchRoute please give me some advice! Commented Aug 14, 2024 at 3:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.