OpenXml.Packaging MainDocumentPart 在当前上下文中不存在

OpenXml.Packaging MainDocumentPart does not exist in the current context

我现在脑子坏了很长时间,在这里或 google 找不到任何相关信息。我在 ASP.NET Core 1.0 中开发,所以我使用 OpenXml 库。我有以下基于示例和教程的代码:

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;

namespace AutoDocumentation.Dll
{
    public class WriteToFile
    {
        // Path of the word doc.
        private const string wordFilePath = @"C:\file.docx";

        static WordprocessingDocument wpd = WordprocessingDocument.Create(wordFilePath, WordprocessingDocumentType.Document);
        MainDocumentPart mdp = wpd.MainDocumentPart;
        mdp.Document = new Document();
    }
}

问题是mdp.Document行抛出错误

"The name 'mdp' does not exist in the current context."

这显然不是真的。你能建议转身吗?或者我做错了什么?

只能在class体中声明和初始化字段,此行应放在构造函数中。