1

I wrote a VSMacro (in VS2010) that parses a solution and adds try and catch statements to cpp files. It's been working fine up until now. I had to reformat my pc and reinstall VS2010 and now it crashes. Here's a snippet from the macro.

Sub Foo(ByVal file As EnvDTE.ProjectItem)
    Dim fileCM As EnvDTE.FileCodeModel
    fileCM = file.FileCodeModel
End Sub

I've checked to see if that file is a valid object, and it does point to a cpp file. But for some reason file.FileCodeModel = Nothing. Why would FileCodeModel be Nothing?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Ernesto Rojo Jr
  • 163
  • 1
  • 1
  • 11

2 Answers2

0

There are several scenarios in Visual Studio where a ProjectItem will not return a FileCodeModel object. For example if the ProjectItem points to a folder or a non-code file item in solution explorer.

Can you verify what the ProjectItem represents in this scenario. In particular

  • Is it pointing to a file?
  • What type of project is this in (Web, console app, etc ...)?
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
0

Usually, it happens when the project is not compilable. You need to try to build the solution first.

Anton K
  • 4,658
  • 2
  • 47
  • 60