0

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?

1

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.
1
  • Thank you , i only "Sign the DLL with a strong key", it is ok. when i build deploy, dll will auto copy to bin folder. – D T Jan 6 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.