5

I am creating a plugin to call a webservice. I need to serialize and deserialize the Json object. So, I need Newtonsoft.Json. I am trying to merge the dll from NewtonSoft.Json and my application dll using ILMerge.MSBuild.Task and ILMerge in Visual Studio 2015.

I get the error below: enter image description here

I looked for solution in internet but could not find any solution.

sabin
  • 233
  • 1
  • 4
  • 18
  • Add **/ndebug:true** help me https://stackoverflow.com/questions/1439721/is-there-a-way-to-merge-pdb-files-with-ilmerge – Vlad Feb 18 '19 at 07:59

3 Answers3

4

For ILMerge in VisualStudio Use the necessary dlls from NuGet Package Manager Only

I was using the MSBuild.ILMerge.Task 1.0.5 and latest verson of Newtonsoft.Json and getting this type of issue.

I tried with to stable version by downgrade to Newtonsoft.Json version 10.0.3 and it works well.

Hope this helps!!!

2

If you're using ILMerge only to serialize/deserialize JSON I'd recommend to drop it and use the DataContractJsonSerializer class instead. This change would remove the dependency with Newtonsoft.Json and ILMerge (not supported) to end up with a lighter plugin library (which is always good):

// Deserialize a JSON stream to a User object.  
public static User ReadToObject(string json)  
{  
    User deserializedUser = new User();  
    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));  
    DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedUser.GetType());  
    deserializedUser = ser.ReadObject(ms) as User;  
    ms.Close();  
    return deserializedUser;  
} 

Full example can be found here.

Federico Jousset
  • 1,661
  • 14
  • 21
1

I was able to fix this issue by taking the latest dll from nuget, & just putting it into side folder & reference the dll direct.

Im not sure why nuget messes it up, but after i took nuget out of the picture the the build worked.

I don't like the fact that i cant use nuget for getting updates for this project, but as least it workes.

CMS
  • 3,657
  • 1
  • 27
  • 46