我正在尝试从控制台使我在加载项中创建的一些代码工作。
我收到错误:
Error in solution file: C:\x\x.sln
System.Runtime.InteropServices.COMException (0x80010001): Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
at EnvDTE.Project.get_Kind()
at p.Program.Projects(DTE2 dte) in C:\z\p\Program.cs:line 764
at ..
at p.Program.Main(String[] args) in C:\z\p\Program.cs:line 60
编码:
using EnvDTE;
using EnvDTE80;
...
class Program
{
[STAThread]
static void Main(string[] args)
{
EnvDTE80.DTE2 dte;
object obj = null;
System.Type t = null;
t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);
obj = System.Activator.CreateInstance(t, true);
dte = (EnvDTE80.DTE2)obj;
string[] solutionFile = ...
dte.Solution.Open(solutionFile);
EnvDTE.Solution solution = (EnvDTE.Solution)dte.Solution;
IList<Project> projects = Projects((DTE2)dte);
...
}
private static IList<Project> Projects(DTE2 dte)
{
Projects projects = dte.Solution.Projects;
List<Project> list = new List<Project>();
var item = projects.GetEnumerator();
while (item.MoveNext())
{
var project = item.Current as Project;
if (project == null)
{
continue;
}
if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, project.Kind, System.StringComparison.OrdinalIgnoreCase) == 0) // this is line 764
{
throw some_exception;
}
if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder)
{
...
}
}
}
}
最初,Intellisense 告诉我
Interop type 'DTE2.ProjectKinds' cannot be embedded. Use the applicable interface instead.
我找到了一个参考,告诉我我可以转到我的参考属性,并将其设置Embed Interop Assembly
为False
这让我可以毫无错误地构建......但是执行给了我上面的错误。
请帮忙 - 我该如何解决这个问题?
VS2010 ...它在加载项中工作...