gpt4 book ai didi

c# - 使用 Rotativa 导致 'Could not load file or assembly' 错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:23:07 24 4
gpt4 key购买 nike

我正在尝试在 MVC 应用程序(使用 Visual Studio 下载 NuGet 包)中使用 Rotativa 将 View 打印为 PDF,但每当调用该方法时,我都会收到“无法加载文件或程序集”错误。我试过在线寻找解决方案,但找不到合适的解决方案。以下是错误的完整堆栈跟踪:

Server Error in '/' Application.

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

Line 48: "ViewOrder", Line 49: new { id = id }) { FileName = "Order.pdf" }; Line 50: } Line 51: Line 52: [HttpGet]

Source File: c:\Users\André\Documents\WAD\Assignment1\7-10-2015\Controllers\OrdersController.cs Line: 50

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

=== Pre-bind state information === LOG: DisplayName = System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/Users/André/Documents/WAD/Assignment1/7-10-2015/ LOG: Initial PrivatePath = C:\Users\André\Documents\WAD\Assignment1\7-10-2015\bin Calling assembly : Rotativa, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\André\Documents\WAD\Assignment1\7-10-2015\web.config LOG: Using host configuration file: C:\Users\André\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/André/AppData/Local/Temp/Temporary ASP.NET Files/root/66e12f45/a5c0a521/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/André/AppData/Local/Temp/Temporary ASP.NET Files/root/66e12f45/a5c0a521/System.Web.Mvc/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/André/Documents/WAD/Assignment1/7-10-2015/bin/System.Web.Mvc.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Stack Trace:

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
_7_10_2015.Controllers.OrdersController.PrintOrder(Int32 id) in c:\Users\André\Documents\WAD\Assignment1\7-10-2015\Controllers\OrdersController.cs:50 lambda_method(Closure , ControllerBase , Object[] ) +161
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +435<br/>
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +60
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) +73<br/>
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +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) +47<br/>
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +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 asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult
asyncResult) +42<br/>
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +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) +70<br/>
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult
asyncResult) +62<br/>
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +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) +70<br/>
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +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" };
}

如果有人能帮我解决这个问题,我将不胜感激。

最佳答案

我猜,Rotativa 可能是使用 ASP.NET MVC 构建的,并引用特定版本(即 System.Web.Mvc 版本 - 3.0.0.1),并且您的 MVC 应用程序可能使用不同版本的 System. Web.Mvc。尝试在项目的 web.config 的 assemblyBinding 部分中添加类似于以下内容的程序集绑定(bind)。

  <dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

这里,您可能需要将5.0.0.0替换为您项目中System.Web.Mvc的版本。

关于c# - 使用 Rotativa 导致 'Could not load file or assembly' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34680809/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com