I am trying to make work some code I created in an add-in, from console.
I am getting errors:
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
The code:
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)
{
...
}
}
}
}
Initially, Intellisense was telling me
Interop type 'DTE2.ProjectKinds' cannot be embedded. Use the applicable interface instead.
I found a reference telling me that I can go to my Reference Properties, and set the Embed Interop Assembly
to False
That allowed me to build without error.... but the execution gives me the error above.
Please help - how can I fix this ?
VS2010... It works in an add-in...
Will's comment above was the answer to my question -
I ended up using the following reference: http://msdn.microsoft.com/en-us/library/ms228772(v=vs.100).aspx
User contributions licensed under CC BY-SA 3.0