System.BadImageFormatException in .Net Core

0

I have .Net Core 2.1 project with following code:

Tools.Serialize(new Dictionary<string, object> { { "1", null } });

The method Tools.Serialize placed in another project written on .Net Framework 4.5.1 (to which first one refers to). This method looks as follows:

public static string Serialize(Dictionary<string, object> d) { var serializer = new JavaScriptSerializer(); var result = serializer.Serialize(d); return result; }

JavaScriptSerializer placed in .Net Framework's System.Web.Extensions assembly.

So I added reference to System.Web.Extensions in my .Net Core project (through PackageReference). But I constantly have the following exception when running code:

System.BadImageFormatException: 'Could not load file or assembly 'System.Web.Extensions, 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. (Exception from HRESULT: 0x80131058)'

I read the similar issues on the forum, but haven't found solution for my situation. Can anyone give an advice, please?

c#
.net
.net-core
badimageformatexception
packagereference
asked on Stack Overflow Mar 3, 2019 by Anton Davydov

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0