Watson: Fix crash when accessing CodeProperty.OverrideKind property for...
Watson: Fix crash when accessing CodeProperty.OverrideKind property for property not contained by a type The root cause is based on analysis of a Watson crash dump with ~300 hits. The call stack looks like this: ``` microsoft_visualstudio_languageservices_csharp_ni!Microsoft.VisualStudio.LanguageServices.CSharp.CodeModel.CSharpCodeModelService.GetOverrideKind microsoft_visualstudio_languageservices_implementation_ni!Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.AbstractCodeMember.get_OverrideKind envdte80!EnvDTE80.CodeProperty2.get_OverrideKind microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeController+AllLanguages+AttributeIsNew.GetAttribute microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeController.GetAttribute microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeController.GetProperties microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler+CodeModelCache.FireAddEvent microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler+CodeModelCache.AddElement microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler.WalkCodeElement microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler+CodeModelCache.AddElementWithChildren microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler+CodeModelCache.RebindChildren microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler+CodeModelCache.ChangeElementUnknown microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler+CodeModelCache.ChangeElement microsoft_visualstudio_modeling_artifactmapper_vshost!Microsoft.VisualStudio.Modeling.ArtifactMapper.VSHost.CodeHandler.codeModelEvents_Changed ``` After analysis of the dump, I was able to reproduce the call stack using the following steps: 1. Create new Class Library 2. In the Solution Explorer, right-click on Class1.cs and choose View->View Class Diagram from the context menu. 3. Add a new property inside Class1. 4. Copy and paste that property *twice* inside the enclosing namespace of Class1. This causes an "Unknown" code model event to fire which the Class Designer responds to by digging through its elements and accessing various properties. One of those properties (`OverrideKind`) retrieves the containing type of the element, but that's null for the properties contained in a namespace and the call throws. So, the fix is to add a couple of simple null checks. Note that this affects all members, so I added tests for fields, events and methods as well.
Showing
想要评论请 注册 或 登录