Question

I created a Dai_ExcelLab.dll to output excel file as image: enter image description here

I had add Dai_ExcelLab.dll to my visual web part:

enter image description here

And using:

protected void btnExport_Click(object sender, EventArgs e)
    {
        try
        {
            //Export();   
            Dai_ExcelLab.ComExcel oExcel = new Dai_ExcelLab.ComExcel();
            oExcel.OutputExcel("c:\\test.xlsx", null);
        }
        catch(Exception ex)
        {
    }

}

Build Deploy is ok, but click button Export , it occur error:

[FileLoadException: Could not load file or assembly 'Dai_ExcelLab, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)]

VisualWebPartProject2.VisualWebPart1.VisualWebPart1UserControl.btnExport_Click(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11762420
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5028

How can add a library into visual web part 2016?

Was it helpful?

Solution

This issue usually occurs because the Dai_ExcelLab doesn't have a PublicKeyToken!

So that, try to do the following:

  • Sign the DLL with a strong key
  • Add your signing file in the SharePoint Web App bin folder.
  • Remove the old reference and re-add the signing dll reference again in VS.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top