System.Type.GetTypeFromProgID(VisualStudioProgId) 返回 null

问题描述

请帮帮我:

机器 1:win2007(工作正常)
机器 2:winServer 2019 Datacenter(面临问题)
在两台机器上:在 VS2019 上执行相同的 C# 代码,我想调用 VS2017

C# 代码:

string VisualStudioProgId = "VisualStudio.DTE." + vsVersion;
Type type = System.Type.GetTypeFromProgID(VisualStudioProgId);
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)System.Activator.CreateInstance(type,true);
  1. 代码在机器 1(win2007) 上运行良好
  2. 在机器 2(winServer 2019) 上 - 报告了未处理的异常:

    enter image description here

我尝试在两台机器的 VS2019 中进一步调试 C# 代码
观察到 type 的不同 Class System Type

机器(win2007)(工作正常):
Class System Type 观察为
Value: {Name = "__ComObject" FullName = "System.__ComObject"}
Type: System.Type {System.RuntimeType}

enter image description here

机器(winServer 2019)(面临问题):
Class System Type 观察为
Value: null
Type: System.Type

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)