我正在努力调试它,因为它在C#DLL中,我不知道如何从调用它的MFC可执行文件进行调试。
现在,如果我打电话给这个方法:
public void SavePublisherData(out Int64 iResult)
{
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(_strPathXML, true))
{
file.WriteLine("This is a test");
}
iResult = MakeResult(true);
}
如果我从我的MFC应用程序调用它是有效的。我最终得到了一个文件。但如果我做我真正想要的事情,我就没有结果。我有发布商类:
using System.Xml.Serialization;
namespace MSAToolsLibrary
{
class Publisher
{
public Publisher()
{
}
[XmlElement]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
private string _Name;
[XmlElement]
public string Notes
{
get { return _Notes; }
set { _Notes = value; }
}
private string _Notes;
}
}
我有一个家长班:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace MSAToolsLibrary
{
[XmlRoot(ElementName = "PublisherDatabase", Namespace = "http://www.publictalksoftware.co.uk/msa")]
class PublisherData
{
public PublisherData()
{
_Publishers = new List<Publisher>();
}
[XmlArray]
public List<Publisher> Publishers
{
get { return _Publishers; }
set { _Publishers = value; }
}
private List<Publisher> _Publishers;
public void AddStudent(String strName, String strNotes)
{
Publisher _Publisher = new Publisher()
{
Name = strName,
Notes = strNotes
};
_Publishers.Add(_Publisher);
}
}
}
DLL库执行如下保存:
public void SavePublisherData(out Int64 iResult)
{
try
{
XmlSerializer x = new XmlSerializer(_PublisherData.GetType());
using (StreamWriter writer = new StreamWriter("d:\\andrew-test-3.xml"))
{
x.Serialize(writer, _PublisherData);
}
}
catch
{
iResult = MakeResult(false);
return;
}
iResult = MakeResult(true);
}
返回结果为真。我没有提出异常。但我没有创建文件。
我在Publishers数组中添加了4个项目,所以我希望它创建了一个简单的XML文件。
我的错误是什么?
答案 0 :(得分:3)
XmlSerializer仅适用于公共类,包括PublisherData和&amp; Publisher类是内部的。