Block retrieving ProjectItem.FileCodeModel and Project.CodeModel until Roslyn is aware of the file
We should block retrieving ProjectItem.FileCodeModel/Project.CodeModel until Roslyn has become aware of the file. This lets us provide the same guarantee as the legacy project system. Useful for extensions and wizards.
When testing this, please check two cases:
- [ ] When a Code Diagram is part of the "active" restored documents it displays an error due to CodeModel returning null.
- [ ] https://github.com/dotnet/project-system/issues/2999#issuecomment-389762981
- [ ] Reenable code fix in Roslyn that renames file to match type name
We should make this work:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.InvisibleEditor..ctor(IServiceProvider serviceProvider, String filePath, IVisualStudioHostProject projectOpt, Boolean needsSave, Boolean needsUndoDisabled)
at Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace.OpenInvisibleEditor(IVisualStudioHostDocument hostDocument)
at Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace.OpenInvisibleEditor(DocumentId documentId)
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.FileCodeModel.InitializeEditor()
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.FileCodeModel.EnsureEditor[T](Func`1 action)
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.FileCodeModel.AddClass(String name, Object position, Object bases, Object implementedInterfaces, vsCMAccess access)
at EnvDTE.FileCodeModel.AddClass(String Name, Object Position, Object Bases, Object ImplementedInterfaces, vsCMAccess Access)
Hello. Mr. Davkean. I am the one who raised the same issue in #3596. in my visx application, using .net core with FileCodeModel is critical part. is there no work-around to use FileCodeModel for .net core project? I need to release my vsix application asap.
There is no workaround.
Moving to 16.1 because the API that we depend on is on 16.1 #3425
👃🏻
The fix for this will be similar enough to #3425 that we should consider fixing both at the same time.
@drewnoakes I think there might be other cases of this, such as TempPE code that @davidwengier wrote.
Two more places we have called this out:
https://github.com/dotnet/project-system/blob/f11b6d17601e4e0ffe20776982dcd586a3358712/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/FileMoveNotificationListener.cs#L223-L227
https://github.com/dotnet/project-system/blob/f11b6d17601e4e0ffe20776982dcd586a3358712/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/RenamerProjectTreeActionHandler.cs#L146-L152