I am writing to a file from the solution in the ExecuteInternal of a context action. It works fine without any errors but if I go look at the file to see the changes, any subsequent usages of the context action gives me the error "All documents should be commited, but these are dirty"
I am finding the IDocument like this:
FileSystemPath directory = Provider.Solution.SolutionFilePath.Directory;
IList<IProjectItem> projectItems = Provider.Solution.FindProjectItemsByLocation(directory.Combine("myFile.xml"));
foreach (var projectItem in projectItems)
if (projectItem.Name == "myFile.xml")
IProjectFile projectFile = projectItem as IProjectFile;
if (projectFile != null)
IDocument document = DocumentManager.GetInstance(Provider.Solution).GetDocument(projectFile);
using (ModificationCookie cookie = document.EnsureWritable())
if (cookie.EnsureWritableResult != EnsureWritableResult.SUCCESS)
// in here I find the line number I want to insert into and then...
document.InsertText(document.GetLineStartOffset(insertionLine + 1), componentEntry + Environment.NewLine);
In desperation I have tried adding Provider.PsiManager.CommitAllDocuments(); in both ExecuteInternalPostPSITransaction and ExecuteBeforeTransaction but I still have the same error message when I try to execute the action after viewing the myFile.xml file in visual studio.