1

Is there any way to convert a JSON object into a Custom object without using serialization in .NET core 1.0 . As I'm using .net framework 4.5 built dll and the models which are defined in it are with [Serialize] attribute over it. So when i try to convert the JSON string into object, I'm facing the below error:

Could not load file or assembly 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

The dll internally is referring to the Serialization class in it. Code snippet which I'm using to convert to object

public void ConvertToObject(string jsonString)
{
   return JsonConvert.DeserializeObject<CustomObject>(json);
   //This line throws error
}

I believe that the problem is only because of the [Serialize] attribute, but we do not have the control to modify the provided dll. And also we just need to stick with NET Core 1.0. I have tried it in Core 2.0 and its working.

2
  • 1
    The process of converting a JSON string to an object is called "serialization", so, no, there's no way of doing it without serialization. If you don't have access to the code where [Serialize] is referenced, then you can't use that code if you want to stick with .NET Core 1. Commented Jan 2, 2018 at 15:49
  • conversion of something from a string representation to an in-memory program object is known as serialisation, in general. So the question makes no sense, really. Anyway it's not a good idea to try and use DLLs for a totally different .NET version (Core vs classic framework). Commented Jan 2, 2018 at 16:00

1 Answer 1

2

There is a mess with loading referenced dll in .Net Core projects (not sure if it's fixed in Core 2.0). Try adding reference to the System.Runtime.Serialization dll for the most top project you are running. E.g. you have the following structure:

(a) Web application (ASP.Net Core) ==> (b) .Net Core DLL ==> (c) .Net 4.5 dll Where (c) is dll with Serialize attribute

Add reference to System.Runtime.Serialization for (a) Note: adding that reference for (b) might also help, but if you have deeper solution structure and have other projects that reference to (b), it may break again, so top project is your choice

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for you answer. I tried this but it didnt work.. same problem.
Check your bin folder, if there is System.Runtime.Serialization.dll. If there is, check it's version, you need 4.0.x (currently I have 4.0.3). If you find version 4.3, see which project requires this dll
If there is no dll in the bin, try put it manually and see if it helps. If so, check again if you have correct reference in the top project
Didn't work. still getting the same error. Seems the core project doesnt import the serialization dll. Even i tried to load manually using Assembly class code, but it didnt work.

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.