它专门在 exception
处返回 line 12
。
public void saveToXML()
{
URL newURL = new URL();
newURL.type = type;
newURL.name = name;
newURL.info = info;
newURL.url = url;
newURL.isProtected = isProtected;
newURL.amountOfClicks = amountOfClicks;
XmlSerializer xml = new XmlSerializer(typeof(URL));
string directory = @"C:\Users\PC-User\Documents\Link" + newURL.name + ".xml";
using (var file = File.Create(directory))
{
xml.Serialize(file, url);
}
}
如果需要,异常消息中的更多详细信息:
谢谢!
最佳答案
考虑这样的事情? :
public async Task saveToXml(){
string directory = @"C:\Users\PC-User\Documents\Link" + newURL.name + ".xml";
await Task.Run(()=>
{
Task.Yield();
using (var file = File.Create(directory))
{
xml.Serialize(file, url);
}
});
}
关于c# - 使用 FileStream 创建文件返回 InvalidOperationException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31769505/