c# - 为什么我得到 ObjectReference 空错误,而参数有一个值?
问题描述
这是我的代码,为什么会产生错误?
sMailBody=MailstrBody.ToString();
StringBuilder sample = new StringBuilder();
sample = MailstrBody;
string passno = dsMail1.Tables[0].Rows[0]["PASSNO"].ToString();
HttpResponse Response = HttpContext.Current.Response;
EmailContentDAL example = new EmailContentDAL();
example.Pdf(sample, Response, passno);
public void Pdf(StringBuilder sample, HttpResponse currentResponse, string passno)
{
StringReader sr = new StringReader(sample.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc,
currentResponse.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
currentResponse.Clear();
currentResponse.ContentType = "application/pdf";
currentResponse.AddHeader("Content-Disposition", "attachment; filename=GetPass_" + passno + ".pdf");
currentResponse.Buffer = true;
currentResponse.Cache.SetCacheability(HttpCacheability.NoCache);
currentResponse.Write(pdfDoc);
currentResponse.End();
}
上面的代码在 处产生空引用错误htmlparser.Parse(sr)
,但在 处StringReader sr = new StringReader(sample.ToString())
显示sample.toString()
一个值。
解决方案
推荐阅读
- java - Java 约束的执行顺序是什么
- asp.net-mvc - Visual Studio 2019 和 Git 更新视图问题
- amazon-web-services - 将网络摄像头数据放入 kinesis 视频流
- java - 带有 Java、Parse 和 Heroku 的 Android Studio 项目
- annotations - testng 注释 @Beforemethod 和 beforeinvocation() 监听器有什么区别?
- javascript - 从颜色池中获得不同的颜色
- ios - 当我更改分支时,除非我重新编译项目,否则某些本地化键不会被翻译
- c# - .net 核心获取证书私钥以使用 GRPC
- autotools - 自动工具(AX_PYTHON_DEVEL 和 AM_PATH_PYTHON)
- java - 解释为什么我的方法不采用以下参数