我发现我的应用程序生成Telerik报告后
var result = new ReportProcessor().RenderReport("PDF", new InstanceReportSource { ReportDocument = new MyTelerikReport(data) }, null);
var stream = new MemoryStream(result.DocumentBytes);
return CreateHttpFileResponse("MyReport.pdf", stream, "application/pdf");
我无法在
CurrentDomain
中获取所有类型var typesWithAttribute = (from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetTypes() //error appears here
//some filtering logic
select t).ToList();
我遇到错误
System.Reflection.ReflectionTypeLoadException:无法加载一个或
更多要求的类型。检索LoaderExceptions属性
想要查询更多的信息。
LoaderExceptions:
System.IO.FileNotFoundException:无法加载文件或程序集
'DocumentFormat.OpenXml,版本= 2.0.5022.0,区域性=中性,
PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。的
系统找不到指定的文件。文档名称:
'DocumentFormat.OpenXml,版本= 2.0.5022.0,区域性=中性,
PublicKeyToken = 31bf3856ad364e35'
经过一番调查后,我发现程序集无法加载:
Telerik.Reporting.OpenXmlRendering, Version=8.0.14.311, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
,并且在生成报告之前,该程序集在AppDomain.CurrentDomain.GetAssemblies()
中不存在(我假定该程序集由Telerik.Reporting, Version=8.0.14.311, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
动态加载)。我可以过滤掉该程序集,因为我不需要任何类型,但是我有点担心在无法加载域中的程序集的情况下-我觉得有点不对劲。
有人可以解释发生了什么吗?是我的问题,还是那是由于第3方库没有加载所有必需的程序集而引起的错?
最佳答案
问题不是程序集,而是Type
来自尚未加载的从属程序集。
如果在程序集上调用GetTypes方法,并且该程序集中的类型取决于尚未加载的程序集中的类型(例如,如果它是从第二个程序集中的类型派生的),则将引发ReflectionTypeLoadException。
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettypes(v=vs.110).aspx