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 Answer 1

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. Commented Jan 6, 2021 at 2:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.