ObjectDataProvider in .Net 5 throws System.BadImageFormatException

0

I am trying to use ObjectDataProvider in a .Net-5 Web App. Therefore I need to use System.Windows.Data, which can be used with the PresentationFramework.dll. I included the assembly with NuGet (<PackageReference Include="PresentationFramework" Version="4.6.0" />). Already when I build my app I get the following warnings:

warning NU1701: Package 'PresentationFramework 4.6.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.

Then, when I try to make an ObjectDataProvider object with ObjectDataProvider myODP = new ObjectDataProvider(); my App crashes with:

System.BadImageFormatException: Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (0x80131058)
      File name: 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.

I am running my app in a Linux docker container (mcr.microsoft.com/dotnet/sdk:5.0-focal) on an x64 system if that is of interest.

From my Google searches, I already tried to delete the bin folder and to rebuild, without success.
Other answers seem to suggest that System.BadImageFormatException indicates that an x86 assembly is referenced, while I am building for x64. I seem not to be able to find any other version of the PresentationFramework.dll except the one from NuGet.
Or is ObjectDataProvider just deprecated?

My question is: How can I resolve this issue and make ObjectDataProvider work in .Net-5?
Is it even possible to use PresentationFramework.dll in .Net-5?
By the way, I also tried to make it work in .Net-3.1, resulting in the same issue.

c#
.net
serialization
.net-5
asked on Stack Overflow Mar 9, 2021 by chron0x

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0