Fix error when opening a document.