1

I have 2 projects as follow:

First: All reports(rdlc files) are here.

Class Library

Second: SharePoint 2010 solution that shows my reports.

SharePoint 2010 Project

I use following code to access RDLC file in dll and put it in reportviewer control in SharePoint Application Page in second project:

Assembly assembly = Assembly.LoadFrom("ReportsLib.dll");
Stream stream = assembly.GetManifestResourceStream("ReportsLib.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);

When i want to get rdlc file from ReportsLib (for example: MyReport.rdlc) and put it in reportviewer control in SharePoint Application Pages, following error occurred:

[FileNotFoundException: Could not load file or assembly 'file:///c:\windows\system32\inetsrv\ReportsLib.dll' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
   System.Reflection.Assembly.LoadFrom(String assemblyFile) +52
   HRS.ReportsViewer.Layouts.ShowReport.Page_Load(Object sender, EventArgs e) +77
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnLoad(EventArgs e) +101
   Microsoft.SharePoint.WebControls.LayoutsPageBase.OnLoad(EventArgs e) +49
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

What do i do wrong?

Amir
  • 714
  • 1
  • 13
  • 37

1 Answers1

1

The assembly name appears to be ReportsLib, and assuming that you've used the default namespaces, you'll need to adjust like so:

var assembly = Assembly.LoadFrom("ReportsLib.dll");
var stream = assembly.GetManifestResourceStream("ReportsLib.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);

Also, if you move MyReport.rdlc into a folder, then you'll need to add a dotted folder path as well, i.e.

GetManifestResourceStream("ReportsLib.SomeFolder.MyReport.rdlc");

Edit If the assembly has been GAC'ed, try providing the fully qualified assembly name e.g.

 var assembly = Assembly.LoadFrom("ReportsLib.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx");

You can obtain the FQN using one of the methods here: How do I find the fully qualified name of an assembly?

Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285
  • thnx, please checked my edited question. it was my mistake but in code i use `ReportsLib`. – Amir Mar 17 '14 at 04:47
  • `ReportsLib.dll` has deployed in shrepoint bin folder and GAC. – Amir Mar 17 '14 at 05:01
  • Another error raised:`Could not load file or assembly 'file:///c:\windows\system32\inetsrv\ReportsLib.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXX' or one of its dependencies. The system cannot find the file specified` – Amir Mar 17 '14 at 05:18
  • You did replace `xxx` and version with the actual attributes from the FQN of your assembly, right? – StuartLC Mar 17 '14 at 05:27
  • I replaced real `PublicKeyToken` and `Version` with `xxx`, I get them from `C:\Windows\assembly` (GAC) folder. – Amir Mar 17 '14 at 05:30
  • One last thing I can think of is to now right click on the `ReportsLib` assembly reference and copy local=false, global=true because it is now in the GAC. In fact, because it is in the GAC AND you load it dynamically, you probably don't need to reference it from the Sharepoint project at all. – StuartLC Mar 17 '14 at 05:33