Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Aug 04, 2017 10:05 pm

Hello

I'm going to separate this part of my code from main application and I will load all DLLs manually in advance.
May I have a list of all DLLs(.net and spire) that must be loaded in advance? I only use Spire.Xls

Regards.

ahmadi_rad@yahoo.com
 
Posts: 43
Joined: Thu Apr 13, 2017 3:53 pm

Mon Aug 07, 2017 3:53 am

Hello,

The dlls are used in the Spire.Xls as below.
1.Spire.License
2.Spire.Pdf
3.System
4.System.Data
5.System.Drawing
6.System.Web
7.System.Windows.Forms
8.System.XML

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Sat Aug 19, 2017 2:14 pm

All right
It worked in a very fragile manner. First I loaded all assemblies of spire and my own code plus all necessary references, then I added the event handler. Without event handler, it was not working.
Thanks for your help

ahmadi_rad@yahoo.com
 
Posts: 43
Joined: Thu Apr 13, 2017 3:53 pm

Tue Aug 22, 2017 3:24 am

Hello,

Thanks for your feedback. We will try to find a stable manner, could you please supply the codes you were trying?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Sun Aug 27, 2017 11:59 am

Hello

I've emailed modified sample project to your staff.

Regards

ahmadi_rad@yahoo.com
 
Posts: 43
Joined: Thu Apr 13, 2017 3:53 pm

Mon Aug 28, 2017 1:55 am

Hello,

Thanks for your feedback.
Sorry that I didn't find the project on email, could you please send it again ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Apr 26, 2018 9:52 pm

I was having what appears to be the same issue in my SSIS solution:
Code: Select all
System.TypeInitializationException was unhandled by user code
  HResult=-2146233036
  Message=The type initializer for 'Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill' threw an exception.
  Source=Spire.XLS
  TypeName=Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill
  StackTrace:
       at Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill..ctor(spr13680 A_0, Object A_1)
       at Spire.Xls.Core.Spreadsheet.Shapes.XlsShape.1(0 A_0)
       at Spire.Xls.Core.Spreadsheet.Shapes.XlsShape.ParseOption(0 option)
       at Spire.Xls.Core.Spreadsheet.Shapes.XlsShape.3(spr6703 A_0)
       at Spire.Xls.Core.Spreadsheet.Shapes.XlsShape.0(ExcelParseOptions A_0)
       at Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape..ctor(spr13680 A_0, Object A_1, spr4910 A_2, ExcelParseOptions A_3)
       at spr539.0(TObjType A_0, spr4910 A_1, ExcelParseOptions A_2, List`1 A_3, Int32 A_4)
       at Spire.Xls.Core.Spreadsheet.Collections.ShapeCollectionBase.AddShape(spr4910 shapeContainer, ExcelParseOptions options)
       at Spire.Xls.Core.Spreadsheet.Collections.ShapeCollectionBase.0(spr9698 A_0, ExcelParseOptions A_1)
       at Spire.Xls.Core.Spreadsheet.Collections.ShapeCollectionBase.0(spr6154 A_0, ExcelParseOptions A_1)
       at Spire.Xls.Core.Spreadsheet.Collections.ShapeCollectionBase.0(spr8805 A_0, ExcelParseOptions A_1)
       at Spire.Xls.Core.Spreadsheet.Collections.ShapeCollectionBase.0(List`1 A_0, ExcelParseOptions A_1)
       at Spire.Xls.Core.Spreadsheet.XlsWorksheetBase.ExtractMSODrawing(Int32 startIndex, ExcelParseOptions options)
       at Spire.Xls.Core.Spreadsheet.XlsWorksheetBase.Parse()
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook.11()
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook.1(spr5733 A_0, ExcelParseOptions A_1, Int32 A_2, Int32 A_3, Dictionary`2 A_4, IDecryptor A_5)
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook.0(spr5733 A_0, ExcelParseOptions A_1, String A_2)
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook.0(spr12193 A_0, ExcelParseOptions A_1, String A_2)
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook.0(Stream A_0, String A_1, ExcelVersion A_2, ExcelParseOptions A_3)
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook.0(String A_0, String A_1, ExcelVersion A_2, ExcelParseOptions A_3)
       at Spire.Xls.Core.Spreadsheet.XlsWorkbook..ctor(spr13680 A_0, Object A_1, String A_2, ExcelParseOptions A_3, Boolean A_4, String A_5, ExcelVersion A_6)
       at spr114.0(Object A_0, String A_1, ExcelParseOptions A_2, Boolean A_3, String A_4, ExcelVersion A_5)
       at spr228.0(String A_0, ExcelParseOptions A_1, Boolean A_2, String A_3, ExcelVersion A_4)
       at Spire.Xls.Workbook.LoadFromFile(String fileName, ExcelVersion version)
       at Spire.Xls.Workbook.LoadFromFile(String fileName)
       at ST_be6c98c97a1a4fcdbbd2fb25b60c2358.ScriptMain.GetExcelProperties(String filePath) in c:\Users\user\AppData\Local\Temp\Vsta\d7a55efd172849fea05358dcb64198da\ScriptMain.cs:line 170
       at ST_be6c98c97a1a4fcdbbd2fb25b60c2358.ScriptMain.Main() in c:\Users\user\AppData\Local\Temp\Vsta\d7a55efd172849fea05358dcb64198da\ScriptMain.cs:line 264
  InnerException:
       HResult=-2147024894
       Message=Could not find file 'Spire.XLS.resources'.
       Source=mscorlib
       StackTrace:
            at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
            at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
            at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
            at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
            at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
            at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
            at System.Resources.ResourceManager.GetObject(String name)
            at Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill.GetResData(String strID)
            at Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill..cctor()
       InnerException:


Initially I could see that the Spire.XLS assembly was loaded first, then later when the "Workbook.LoadFromFile()" function was called I could see it trying to load assembly "Spire.XLS.resources, Version=8.4.13.6040, Culture=en-US, PublicKeyToken=663f351905198cb3". Based on the Public Key Token I deduced that this is for Spire.PDF which hadn't been loaded yet. I tried a couple of different methods to force it to load with Spire.XLS but ultimately decided on adding a condition for "PublicKeyToken=663f351905198cb3" in the assembly resolver hack noted below.

As in my case this is for a custom C# Script Task in an SSIS package, and because the Spire.Office assemblies are not loaded in GAC, I'm using a hack/workaround (https://blogs.msdn.microsoft.com/dbrown ... n-the-gac/) to load them from a shared location like so:
Code: Select all
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    string path = @"C:\PDShare\PackageDeployment\Reference\OfflineDocuments\";
    if (args.Name.Contains("Spire.XLS,"))
    {
        return System.Reflection.Assembly.UnsafeLoadFrom(System.IO.Path.Combine(path, @"Spire.Office\Spire.XLS.dll"));
    }
    else if (args.Name.Contains("Spire.Common,"))
    {
        return System.Reflection.Assembly.UnsafeLoadFrom(System.IO.Path.Combine(path, @"Spire.Office\Spire.Common.dll"));
    }
    else if (args.Name.Contains("Spire.Doc,"))
    {
        return System.Reflection.Assembly.UnsafeLoadFrom(System.IO.Path.Combine(path, @"Spire.Office\Spire.Doc.dll"));
    }
    else if (args.Name.Contains("Spire.Pdf,") || args.Name.Contains("PublicKeyToken=663f351905198cb3"))
    {
        return System.Reflection.Assembly.UnsafeLoadFrom(System.IO.Path.Combine(path, @"Spire.Office\Spire.Pdf.dll"));
    }
    else if (args.Name.Contains("Spire.Spreadsheet,"))
    {
        return System.Reflection.Assembly.UnsafeLoadFrom(System.IO.Path.Combine(path, @"Spire.Office\Spire.Spreadsheet.dll"));
    }
    else if (args.Name.Contains("Spire.License,"))
    {
        return System.Reflection.Assembly.UnsafeLoadFrom(System.IO.Path.Combine(path, @"Spire.Office\Spire.License.dll"));
    }
    return null;
}


I Probably could change the condition for "Spire.Pdf" to simply "PublicKeyToken=663f351905198cb3" or for that matter all of the assemblies to their Public Key Tokens, but for now I'll leave it as an OR condition.

Hope this helps someone else!

llindhardt
 
Posts: 1
Joined: Thu Apr 26, 2018 8:37 pm

Return to Spire.XLS