【发布时间】:2016-12-24 23:02:59
【问题描述】:
我知道以前有人问过此类问题,并且我知道何时抛出此异常。但是,我无法在我的代码中解决它。
我拥有的是DataSet,我正在尝试将其架构和数据写入xml 文件。
这是我的代码:
//Handler to Application.Startup Event of current Application
private void App_Startup(object sender, StartupEventArgs e)
{
DataFile = new FileInfo("Data.xml"); //DataFile is a `System.IO.FileInfo`
Data = new DataSet("Data"); //Data is a `System.Data.DataSet`
if (!DataFile.Exists)
{
DataFile.Create();
// Some code here that initializes `Data` (not referencing DataFile here,
// nor doing any IO operation)
Data.WriteXml(DataFile.FullName, XmlWriteMode.WriteSchema); //Exception is caught here
}
}
在我运行程序之前,我正在删除“Data.xml”文件。
我确信没有其他进程正在访问它,所以我的代码中肯定有一些调用没有释放文件。
我的代码有什么问题?
【问题讨论】:
-
你希望你的代码做什么?你的文字说你想写,你的方法叫做读,你的文件是空的。
-
@nvoigt 对不起,我的错。问问题时犯了错误。 PL。检查编辑。