I ran into the same problem
You can fix this by specifying what type of document you want to get from the window object
public static void SetCode(ProjectItem projectItem, string newCode)
{
Window EditWindow = projectItem.Open(Constants.vsext_vk_Code);
EditWindow.Visible = true; //hide editor window
TextDocument TextDocument = (TextDocument)EditWindow.Document.Object("TextDocument");
EditPoint EditPoint = TextDocument.StartPoint.CreateEditPoint();
EditPoint.Delete(TextDocument.EndPoint); //delete content
EditPoint.Insert(newCode);
EditWindow.Close(vsSaveChanges.vsSaveChangesYes);
}
you'll have to convert that back to VB.NET yourself