【发布时间】:2016-04-13 08:35:34
【问题描述】:
我正在尝试在 MVC 应用程序(使用 Visual Studio 下载 NuGet 包)中使用 Rotativa 将视图打印到 PDF,但每当调用该方法时,我都会收到“无法加载文件或程序集”错误。我尝试在网上寻找解决方案,但找不到合适的解决方案。以下是错误的完整堆栈跟踪:
“/”应用程序中的服务器错误。
无法加载文件或程序集'System.Web.Mvc,版本=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其之一 依赖关系。定位程序集的清单定义不 匹配程序集引用。 (HRESULT 异常:0x80131040)
描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。
异常详细信息:System.IO.FileLoadException:无法加载文件或 程序集'System.Web.Mvc,版本=3.0.0.1,文化=中性, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。这 定位程序集的清单定义与程序集不匹配 参考。 (HRESULT 异常:0x80131040)
来源错误:
第 48 行:“ViewOrder”,第 49 行:新 { id = id }) { FileName = "Order.pdf" };第 50 行:} 第 51 行: 第 52 行:[HttpGet]
源文件: c:\Users\André\Documents\WAD\Assignment1\7-10-2015\Controllers\OrdersController.cs 线路:50
装配负载跟踪:以下信息可能有助于 确定为什么程序集 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 无法加载。
=== 预绑定状态信息 === LOG: DisplayName = System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (完全指定)日志:Appbase = file:///C:/Users/André/Documents/WAD/Assignment1/7-10-2015/ LOG: 初始 PrivatePath = C:\Users\André\Documents\WAD\Assignment1\7-10-2015\bin 调用 组装:Rotativa,版本=1.0.0.0,文化=中性, PublicKeyToken=null。 === LOG:此绑定在默认加载上下文中开始。 LOG:使用应用程序配置文件: C:\Users\André\Documents\WAD\Assignment1\7-10-2015\web.config 日志: 使用主机配置文件: C:\Users\André\Documents\IISExpress\config\aspnet.config 日志:使用 机器配置文件来自 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config。 LOG:后策略参考:System.Web.Mvc,Version=3.0.0.1, 文化=中性,PublicKeyToken=31bf3856ad364e35 日志:正在尝试 下载新网址 file:///C:/Users/André/AppData/Local/Temp/Temporary ASP.NET 文件/root/66e12f45/a5c0a521/System.Web.Mvc.DLL。日志:尝试 下载新网址 file:///C:/Users/André/AppData/Local/Temp/Temporary ASP.NET 文件/root/66e12f45/a5c0a521/System.Web.Mvc/System.Web.Mvc.DLL。日志: 正在尝试下载新 URL file:///C:/Users/André/Documents/WAD/Assignment1/7-10-2015/bin/System.Web.Mvc.DLL。 警告:比较程序集名称导致不匹配:主要 版本 ERR:无法完成程序集设置 (hr = 0x80131040)。 探测终止。
堆栈跟踪:
[FileLoadException: 无法加载文件或程序集 'System.Web.Mvc, 版本=3.0.0.1,文化=中性,PublicKeyToken=31bf3856ad364e35' 或 它的依赖项之一。定位程序集的清单定义 与程序集引用不匹配。 (HRESULT 的例外情况: 0x80131040)]
_7_10_2015.Controllers.OrdersController.PrintOrder(Int32 id) 在 c:\Users\André\Documents\WAD\Assignment1\7-10-2015\Controllers\OrdersController.cs:50 lambda_method(闭包, ControllerBase, Object[]) +161
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数)+59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext 控制器上下文,IDictionary2 parameters) +4352 参数)+60
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +76 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__36(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +36
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +731.End() +136
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3c() +117 System.Web.Mvc.Async.c__DisplayClass45.b__3e() +323 System.Web.Mvc.Async.c__DisplayClass30.b__2f(IAsyncResult asyncResult) +44
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +471.End() +136
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
System.Web.Mvc.Async.c__DisplayClass28.b__19() +72 System.Web.Mvc.Async.c__DisplayClass1e.b__1b(IAsyncResult 异步结果)+185
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +421.End() +133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +701.End() +133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult,控制器控制器)+39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +621.End() +133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+37 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +701.End() +133
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, 对象标签)+37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult 结果)+38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9721605 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
以及我使用 Rotativa 的 ActionAsPDF 的代码示例:
[HttpGet]
public ActionResult ViewOrder(int id)
{
Order GetOrder = new CartBL().GetOrderById(id);
return View(GetOrder);
}
[HttpGet]
public ActionResult PrintOrder(int id)
{
return new ActionAsPdf(
"ViewOrder",
new { id = id }) { FileName = "Order.pdf" };
}
非常感谢有人能帮我解决这个问题。
【问题讨论】:
-
你能把你使用 ViewAsPdf 的方法的代码贴出来吗?
-
ActionAsPDF 代码添加到原帖中。
标签: c# asp.net asp.net-mvc rotativa