我正在为内部部署创建一个wpf应用程序。
使用该软件的用户在尝试创建excel互操作实例时遇到以下错误。
Retrieving the COM class factory for component with CLSID (...) failed due to the following error: 80070002 The system cannot find the file specified
捕获错误的部分如下
try
{
_excelApplication = new Microsoft.Office.Interop.Excel.Application();
GetWindowThreadProcessId(_excelApplication.Hwnd, out ExcelAppProcessId);
_excelApplication.ScreenUpdating = false;
}
catch(Exception e)
{
//TODO Move message box to parents
MessageBox.Show($"Termination Error: Could not open Excel Application: {e.Message}");
Environment.Exit(110);
}
[以前,同一用户在尝试打开Access时遇到问题(不记得确切的错误是什么,我实施了以下修复方法。
try
{
//MessageBox.Show($"OS: {EnvironmentFunctions.is64BitOperatingSystem} Process: {EnvironmentFunctions.is64BitProcess}");
if (EnvironmentFunctions.is64BitOperatingSystem && !EnvironmentFunctions.is64BitProcess)
{
string PathValue = "";
string sAdd = "";
string strCommonFiles =
Environment.GetEnvironmentVariable("CommonProgramFiles(x86)");
sAdd = ";" + strCommonFiles + "\\microsoft shared\\DAO";
PathValue = Environment.GetEnvironmentVariable("Path");
PathValue += sAdd;
Environment.SetEnvironmentVariable("path", PathValue);
}
_accessApplication = new Microsoft.Office.Interop.Access.Application();
GetWindowThreadProcessId(_accessApplication.hWndAccessApp(), out AccessAppProcessId);
}
catch
{
MessageBox.Show("Termination Error: Could not open Access Application");
Environment.Exit(110);
}
除了Excel互操作之外,会有类似的解决方案吗?
关于用户的注释:它们是少数几个正在运行的窗口7之一。
由于以下错误,为具有CLSID(...)的组件检索COM类工厂失败:80070002系统找不到指定的文件
通常,此错误仅由几个问题引起,我将在下面列出。
我之前询问您的目标是什么,因为您有一些代码正在检查PC是否为64位,并且您已经遇到了一些问题。然后,这会导致我在创建Excel实例时遇到一些问题。
我对您的确切问题的建议和解决方案是,因为最终计算机是32位的,所以针对x86 / 32bit进行编译应该可以解决此问题。
另一方面,您也许可以删除旧代码,因为不再需要它。