解决再送100分 XDocument.Save方法出现异常,求可能原因
public void MakeIDListFile(string fileName, string[] idList)
{
XDocument doc = new XDocument();
XDeclaration declaration = new XDeclaration("1.0", "shift_jis", "yes");
doc.Declaration = declaration;
XElement idListElement = new XElement("ID_LIST");
doc.Add(idListElement);
XElement idElemtent;
for (int i = 0; i < idList.Length; i++)
{
idElemtent = new XElement("ID");
idElemtent.Add(idList[i]);
idListElement.Add(idElemtent);
}
doc.Save(fileName); }
异常信息如下
System.IO.IOException: 要求された操作はユーザー マップ セクションで開いたファイルでは実行できません。
場所 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
場所 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
場所 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
場所 System.Xml.XmlWriter.Create(String outputFileName, XmlWriterSettings settings)
場所 System.Xml.Linq.XDocument.Save(String fileName, SaveOptions options)
場所 System.Xml.Linq.XDocument.Save(String fileName)
場所 XXXXXXXXX.common.util.CommonService.MakeIDListFile(String fileName, String[] pnList)
这个异常的可能的汉语意思:请求的操作无法在使用用户映射区域打开的文件上执行
程序一直正常运行,某日连续发生几次这个异常,过了段时间又正常运行。
什么原因可能导致这个异常呢? 文件不存在,文件无法访问,路经错误等都不是报这个错。