尝试使用现有数据在dvd-rw上写入数据后,Visual Studio抛出System.AccessViolationException。 我使用它来写在https://www.codeproject.com/Articles/24544/Burning-and-Erasing-CD-DVD-Blu-ray-Media-with-C-an上,但是在移至Windows 10之后,它似乎不再起作用。可能是什么原因造成的? N.B:使用CD并完全擦除DVD上的数据后,它可以正常工作。 对不起,英语不好。
private bool _CreateMediaFileSystem(IMAPI2.Interop.IDiscRecorder2 discRecorder
, Object[] multisessionInterfaces
, ref System.Runtime.InteropServices.ComTypes.IStream dataStream
, String driveLetter
, List<KeyValuePair<String, String>> directoryList)
{
IMAPI2.Interop.MsftFileSystemImage fileSystemImage = null;
try {
fileSystemImage = (IMAPI2.Interop.MsftFileSystemImage)new IMAPI2.Interop.MsftFileSystemImageClass();
fileSystemImage.ChooseImageDefaults(discRecorder);
fileSystemImage.FileSystemsToCreate = IMAPI2.Interop.FsiFileSystems.FsiFileSystemJoliet | IMAPI2.Interop.FsiFileSystems.FsiFileSystemISO9660;
fileSystemImage.VolumeName = "ISIX_" + DateTime.Now.ToString("yyyyMMdd");
if (multisessionInterfaces != null) { // If multisessions, then import previous sessions
fileSystemImage.MultisessionInterfaces = multisessionInterfaces;
fileSystemImage.ImportFileSystem();
}
if (directoryList.Count <= 0) {
BLLogFilesSvc.GetInstance().WriteLogDicomDebugFile("CreateMediaFileSystem failed because no directory to insert is present.");
return false;
}
foreach (KeyValuePair<String, String> directoryItem in directoryList) {
if (directoryItem.Value == "") {
fileSystemImage.Root.AddTree(directoryItem.Key, false);
}
else {
IMAPI2.Interop.IFsiDirectoryItem iFsiDirectoryItem = fileSystemImage.CreateDirectoryItem(directoryItem.Value);
fileSystemImage.Root.Add((IMAPI2.Interop.IFsiItem)iFsiDirectoryItem);
iFsiDirectoryItem.AddTree(directoryItem.Key, false);
}
}
dataStream = fileSystemImage.CreateResultImage().ImageStream;
}
catch (System.Runtime.InteropServices.COMException ex) {
BLLogFilesSvc.GetInstance().WriteLogDicomDebugFile("COMEXception thrown in _CreateMediaFileSystem(): " + ex.Message);
return false;
}
finally {
if (fileSystemImage != null) {
System.Runtime.InteropServices.Marshal.ReleaseComObject(fileSystemImage);
}
}
return true;
罪魁祸首似乎是这样的:
dataStream = fileSystemImage.CreateResultImage().ImageStream;