易截截图软件、单文件、免安装、纯绿色、仅160KB

一个C# xml 序列化错误

一个C# xml 序列化错误
 
事发现场:
xml序列化的数据中存储的节点数据是
   <Module>536870912</Module>  (xml文件中)
对应的类属性是
    public short Module { get; set; }  (C#类中)
 
序列化的代码:
public static FMDSTimeSeriesDefinitionList Deserialize(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(FMDSTimeSeriesDefinitionList));
/* If the XML document has been altered with unknown
nodes or attributes, handle them with the
UnknownNode and UnknownAttribute events.*/
serializer.UnknownNode += new
XmlNodeEventHandler(serializer_UnknownNode);
serializer.UnknownAttribute += new
XmlAttributeEventHandler(serializer_UnknownAttribute);
FMDSTimeSeriesDefinitionList tsList = null;
using (StringReader sr = new StringReader(xml))
{
try
{
tsList = (FMDSTimeSeriesDefinitionList)serializer.Deserialize(sr);
}
catch (Exception ex)
{
throw ex;
}
}
return tsList;
}
 
 
调试时会弹出异常信息:
An unhandled exception of type 'System.InvalidOperationException' occurred in FMTimeSeriesDefinition.exe
Additional information: There is an error in XML document (293, 8).
找到xml文件的293行第8列:
292:      <Module>536870912</Module>
293:      <DurationPeriodsFlag>1</DurationPeriodsFlag>
294:      <DecimalFlag>0</DecimalFlag>
 
是一个"<"标记符,看不出问题,再看前一个节点,突然发现536870912 存入short中,数据溢出。
将short改为int,问题解决。


相关文档:

C# XML注释

作者: J. Andrew Schafer
这篇文章假设你对 XML, XSLT, 和 C# 熟悉
下载这篇文章的源代码: XMLC.exe (76KB)
译者说明:这篇文章是很早以前就发表了,它提供的源代码是基于 VS.net 测试版(RTM 和 Beta 2)的。
摘要
    C# 允许开发人员在源代码中插入XML注释,这在多人协作开发的时候显得特别有用。 ......

[转]使用ASP调用C#写的COM组件

转自: http://www.cnblogs.com/rentj1/archive/2009/02/23/1396187.html
1 新建类库MyTestDLL
2 右击项目“MyTestDLL”-》属性-》生成-》勾选“为COM互操作注册”
3 打开 AssemblyInfo.cs 文件 修改 [assembly: ComVisible(true)]
4 打开Visual Sutdio 2008 的命令提示行工具输入guidgen.exe 选择D ......

XML over TCP

如果要完整的支持XML over TCP,只有两种办法:
1,加一个header去标明数据的长度
2,加一个delimiter去标明数据的结束
这两种方法都不够优雅。我们不需要一个通用的方法,我们只要一个最适合我们的方法。
通常,我们能够自定义数据的格式,而且我们通常一条消息只有一个root node,那么我们可以试试下面的函数:
//re ......

PHP 调用 C# dll

弄了半天, PHP 终于能调用我的C# dll 了.
该死的,我对C# COM注册一向不了解, PHP 文档上只给PHP那部分内容,没告诉我怎么弄dll
我还傻兮兮的用 Regsvr32 注册那个c# dll.
背景:
Windows xp sp3 ; apache 2.2.14 ; php 5.2.12 ;
VS2010 beta ;
语言:
PHP5 , C#
C#部分:
创建一个 C# Class Library . (dll) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号