Json does not exist in the namespace *using System.Runtime.Serialization.Json*

Asked

Viewed 155 times

-1

An error occurred while trying to import using System.Runtime.Serialization.Json. How to solve?

The code converts Json to Object and vice versa, I’m only posting a part of it.

using System.Text;
using System.IO;
using System.Runtime.Serialization.Json;
namespace Converte_Object_Json
{
    public class JsonConversao
    {
        public string ConverteObjectParaJSon<T>(T obj)
        {
            try
            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
                MemoryStream ms = new MemoryStream();
                ser.WriteObject(ms, obj);
                string jsonString = Encoding.UTF8.GetString(ms.ToArray());
                ms.Close();
                return jsonString;
            }
            catch
            {
                throw;
            }
        }
    }
}

Error: Erro

App information:

Microsoft Visual Studio Community 2019 Version 16.0.4 Visualstudio.16.Release/16.0.4+28803.452 Microsoft . NET Framework Version 4.7.03190

Installed Version: Community

ASP.NET and Web Tools 2019 16.0.12313.64372

ASP.NET Web Frameworks and Tools 2019 16.0.12313.64372

*It’s amazing how most Brazilians are so rotten, no matter how much you dedicate yourself to something will always have a child of the p*** that will negatively answer your question without contributing shit*

  • Check out this https://stackoverflow.com/questions/22255640/why-cant-i-reference-system-runtime-serialization-json-in-c-sharp

1 answer

1

Most likely you don’t have the reference added. For this go in the references > right button > add reference and select the dll below:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.