Reputation: 519
I have app, which is running in both Windows and WinPE. In Windows is running ok, in WinPE running ok too but when I save file it returns error. If anybody had this issue please help me with info. I tried dependency walker and moved dlls, installed any packages available, but still same error.
An error occurred while generating the report: Creating an instance of the COM component with CLSID {C0B4E2F3-BA21-4773-8DBA-335EC946E8B8} from the IClassFactory failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).
This is the part where file save happens
string fileName = string.Empty;
if (IsWinPE())
{
string exeDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string reportsFolder = Path.Combine(exeDirectory, "Reports");
if (!Directory.Exists(reportsFolder))
{
Directory.CreateDirectory(reportsFolder);
}
fileName = Path.Combine("C:\\", "ErasureReport.pdf");
}
else
{
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
saveFileDialog.FileName = $"ErasureReport_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
fileName = saveFileDialog.FileName;
}
else
{
return;
}
}
}
DebugCheckpoint("About to save document to: " + fileName);
document.Save(fileName);
MessageBox.Show("Report saved successfully!\nPlease open the file manually.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
try
{
Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true });
}
catch (Exception ex)
{
MessageBox.Show("The report was saved but could not be opened automatically.\n" + ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
if (!IsWinPE())
{
try
{
Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true });
}
catch (Exception ex)
{
MessageBox.Show("Report saved successfully, but the file could not be opened automatically. Please open the file manually.\n\n" + ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
Upvotes: 0
Views: 59
Reputation: 519
Kind people in the comments pushed me into different ideas and I was able to find and fix the issue.
The issue was the path in this method below, System32
was missing.
private bool IsWinPE()
{
string windowsDir = "X:\\Windows\\System32";
return File.Exists(Path.Combine(windowsDir, "winpeshl.ini")) ||
File.Exists(Path.Combine(windowsDir, "startnet.cmd"));
}
It was my mistake, but this error misguided me and I was looking completely different directions. So if someone will have same problem, this answer may be the solution. Thanks
Upvotes: 0