DataContractJsonSerializer“遇到意外的名称空间" [英] DataContractJsonSerializer "Encountered unexpected namespace"

查看:107
本文介绍了DataContractJsonSerializer“遇到意外的名称空间"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我遇到了一个错误,Google上的匹配数为0(零).这是一个不好的信号.

这是代码

公共静态字符串ToJson(此对象obj)
{{

MemoryStream流=新的MemoryStream();
串行化器.WriteObject(流,obj);

try
{ ());最终
{
stream.Close();
}
}

我正在序列化的对象具有[DataContract(命名空间="...")),因为它来自WCF服务.在错误消息上没有搜索结果,我很受困扰.

请帮助.

谢谢

Hi

I'm getting an error and there are 0 (ZERO) hits on google. This is a bad sign.

here's the code

    public static string ToJson(this object obj)
    {
      DataContractJsonSerializer serializer = new DataContractJsonSerializer( obj.GetType() );

      MemoryStream stream = new MemoryStream();
      serializer.WriteObject( stream, obj );

      try
      {
        return Encoding.UTF8.GetString( stream.ToArray() );
      }
      finally
      {
        stream.Close();
      }
    }

the object that i'm serializing has [DataContract(Namespace="...")] since this is coming from a WCF service.

This was working a moment ago. Without search hits on the error message i'm pretty stuck.

Please help.

Thanks

推荐答案

可以发送调用堆栈和收到的完整异常消息吗?谢谢.


这篇关于DataContractJsonSerializer“遇到意外的名称空间"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆