Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why It displays error? Pin
Richard MacCutchan31-Aug-17 23:02
mveRichard MacCutchan31-Aug-17 23:02 
QuestionHttp to Https Url redirection Pin
Member 1129085529-Aug-17 1:18
Member 1129085529-Aug-17 1:18 
AnswerRe: Http to Https Url redirection Pin
OriginalGriff29-Aug-17 1:42
mveOriginalGriff29-Aug-17 1:42 
GeneralRe: Http to Https Url redirection Pin
Member 1129085529-Aug-17 2:11
Member 1129085529-Aug-17 2:11 
GeneralRe: Http to Https Url redirection Pin
OriginalGriff29-Aug-17 2:28
mveOriginalGriff29-Aug-17 2:28 
Questionalt keywords problem Pin
Member 1337599027-Aug-17 22:27
Member 1337599027-Aug-17 22:27 
AnswerRe: alt keywords problem Pin
OriginalGriff27-Aug-17 23:32
mveOriginalGriff27-Aug-17 23:32 
QuestionTrying to Use the VCCodeModel Interface Pin
Richard Andrew x6427-Aug-17 13:17
professionalRichard Andrew x6427-Aug-17 13:17 
I'm having a dickens of a time trying to instantiate the VCCodeModel interface. This is part of the Visual Studio object model. I eventually want to extract type information from a C++ project directly from Visual Studio.

First I locate the Visual C++ project in the solution, and then I get a reference to the Project object.

The problem is when I try to cast the Project.CodeModel interface to a VCCodeModel interface, which is what they say to do in the documentation[^].

The error that I receive is:

'Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.VCCodeModel.VCCodeModel'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A590E96B-CC8C-48AF-9E8F-7C3FE7865586}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).'
This is interesting because the GUID in the error message is not the GUID given by the documentation for the VCCodeModel interface! The correct GUID is {E6691CDE-9A41-4891-8D8C-C1E93958E6A0}

Does anyone know what's going on here? Why can't I retrieve the VCCodeModel interface as they do in the docs, and why does it try to cast it to the wrong IID?

My code is below. I'm using Visual Studio 2017.

C#
private void buttonExtract_Click(object sender, EventArgs e)
{
    EnvDTE80.DTE2 dte2 =
        (DTE2) System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.15.0");

    int Count = dte2.Solution.Projects.Count;
    Project P = null;
    Project FW32 = null;

    for (int a = 1; a <= Count; a++)
    {
        P = dte2.Solution.Projects.Item(a);

        if (P.FullName.Contains("ConsoleApplication"))
        {
            break;
        }
    }

    VCCodeModel vcCodeModel = (VCCodeModel) P.CodeModel; // <<<<< BOMBS HERE WITH THE ERROR ABOVE (P is not null)
}




The difficult we do right away...
...the impossible takes slightly longer.

QuestionCoding Challenge Pin
Mycroft Holmes26-Aug-17 15:14
professionalMycroft Holmes26-Aug-17 15:14 
GeneralRe: Coding Challenge Pin
PIEBALDconsult26-Aug-17 15:26
mvePIEBALDconsult26-Aug-17 15:26 
GeneralRe: Coding Challenge Pin
Mycroft Holmes26-Aug-17 15:33
professionalMycroft Holmes26-Aug-17 15:33 
GeneralRe: Coding Challenge Pin
PIEBALDconsult26-Aug-17 16:14
mvePIEBALDconsult26-Aug-17 16:14 
QuestionRe: Coding Challenge Pin
PIEBALDconsult26-Aug-17 16:56
mvePIEBALDconsult26-Aug-17 16:56 
AnswerRe: Coding Challenge Pin
Mycroft Holmes26-Aug-17 22:20
professionalMycroft Holmes26-Aug-17 22:20 
AnswerRe: Coding Challenge Pin
BillWoodruff26-Aug-17 19:44
professionalBillWoodruff26-Aug-17 19:44 
AnswerRe: Coding Challenge Pin
Peter_in_278027-Aug-17 1:41
professionalPeter_in_278027-Aug-17 1:41 
AnswerRe: Coding Challenge Pin
Richard Deeming29-Aug-17 2:28
mveRichard Deeming29-Aug-17 2:28 
GeneralRe: Coding Challenge Pin
Mycroft Holmes4-Sep-17 21:06
professionalMycroft Holmes4-Sep-17 21:06 
SuggestionRe: Coding Challenge Pin
Richard Deeming5-Sep-17 1:55
mveRichard Deeming5-Sep-17 1:55 
GeneralRe: Coding Challenge Pin
Mycroft Holmes4-Sep-17 22:24
professionalMycroft Holmes4-Sep-17 22:24 
GeneralRe: Coding Challenge Pin
Pete O'Hanlon4-Sep-17 23:24
mvePete O'Hanlon4-Sep-17 23:24 
GeneralRe: Coding Challenge Pin
Richard Deeming5-Sep-17 2:04
mveRichard Deeming5-Sep-17 2:04 
AnswerRe: Coding Challenge Pin
Pete O'Hanlon29-Aug-17 3:53
mvePete O'Hanlon29-Aug-17 3:53 
Questionc++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 8:04
User 1106097925-Aug-17 8:04 
AnswerRe: c++ const in c# (I assume, once again) Pin
OriginalGriff25-Aug-17 8:37
mveOriginalGriff25-Aug-17 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.