c# - 如何修复: Object must be an array of primitives. 参数名称:src

标签 c# .net src primitive

当用户尝试从我的 Web 应用程序下载 pdf 时,我收到大量这些错误报告:

    System.ArgumentException: Object must be an array of primitives. 
Parameter name: src 
at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count) 
at System.Web.StaticFileHandler.ProcessRangeRequest(HttpContext context, String physicalPath, Int64 fileLength, String rangeHeader, String etag, DateTime lastModified) 
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

我已经看过 http://support.microsoft.com/kb/2026272并尝试了第 3 点(其他建议在这种情况下并不是真正可行的解决方案),但它并没有解决问题。

我在其他地方看到的另一个建议是将以下内容添加到 Global.asax 中的 Application_PostRequestHandlerExecute 方法:

HttpApplication app = (HttpApplication)sender;

if(app.Context.Request.RawUrl.Contains(".pdf"))
    app.Response.AppendHeader("Accept-Ranges", "none");

但这似乎并没有解决问题。

任何想法表示赞赏...

最佳答案

问题是由.Net框架本身引起的。似乎存在一个常见问题,即 StaticFileHandler 对 Buffer.BlockCopy 的调用无法正确处理 PDF 文件。我在其他地方找到的唯一解决方案,也是我自己能想到的,是编写您自己的不使用 Buffer.BlockCopy 的文件处理程序。

这里是一个 HTTP 处理程序实现的链接,用于修复这种情况: http://forums.asp.net/t/1471292.aspx/1

您还可以按照 Microsoft 的指南创建 http 处理程序并调整示例以特定于 PDF 文件: http://msdn.microsoft.com/en-us/library/ms972953.aspx

关于c# - 如何修复: Object must be an array of primitives. 参数名称:src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9802789/

相关文章:

c# - 需要帮助来理解 c# 语句

c# - 字典使用对象作为键。 key 在字典外更新

c# - 处理嵌套代码条件的更好模式?

jquery - 将 onerror 与 jquery 中动态创建的图像标签绑定(bind)

javascript - 用 jquery 改变 img src

c# - 如何在W10的不同屏幕上正确适配应用程序UI

asp.net - 中继器 View 状态不刷新输入

c# - 获取整数的第七位

android - 创建新应用程序时 src 和布局文件夹为空

c# - 在c# 3.0 中,是否可以将隐式运算符添加到字符串类中?