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.

Mon Apr 24, 2017 9:28 am

Hello

Spire.xls, Spire.pdf, Spire.common, Spire.license are loaded to appdomain manually by mother application. While loading an excel stream in that appdomain, I received the following exception. This exception is not throwing if I load the whole package in a usual exe application. I think there may be another dll that I'm not loading. could you please help?



The type initializer for 'Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill' threw an exception.

Inner exception message:

Could not load file or assembly 'Spire.XLS.resources, Version=7.9.0.55040, Culture=en-US, PublicKeyToken=663f351905198cb3' or one of its dependencies. The system cannot find the file specified.

Stack trace:

at Spire.Xls.Core.Spreadsheet.Shapes.XlsShapeFill..ctor(spr2469 A_0, Object A_1)
at Spire.Xls.Core.Spreadsheet.Shapes.XlsShape.get_Fill()
at Spire.Xls.Core.Spreadsheet.Shapes.XlsBitmapShape..ctor(spr2469 A_0, Object A_1, Boolean A_2)
at spr4315.0(XmlReader A_0, XlsWorksheetBase A_1, String A_2, List`1 A_3, Dictionary`2 A_4)
at spr4315.1(XmlReader A_0, XlsWorksheetBase A_1, String A_2, List`1 A_3, Dictionary`2 A_4)
at spr4315.4(XmlReader A_0, XlsWorksheetBase A_1, String A_2, List`1 A_3, Dictionary`2 A_4)
at spr511.0(XlsWorksheetBase A_0, spr5002 A_1, Dictionary`2 A_2)
at spr511.0(XlsWorksheetBase A_0, String A_1, Dictionary`2 A_2)
at spr4315.0(XmlReader A_0, XlsWorksheet A_1, Dictionary`2 A_2)
at spr4315.0(XmlReader A_0, XlsWorksheet A_1, MemoryStream& A_2, String A_3, Dictionary`2 A_4)
at spr511.1(XlsWorksheet A_0, Dictionary`2 A_1)
at Spire.Xls.Core.Spreadsheet.XlsWorksheet.ParseData(Dictionary`2 dictUpdatedSSTIndexes)
at spr4315.0(Dictionary`2 A_0)
at spr262.0(List`1& A_0)
at spr262.1(List`1& A_0)
at spr846.0(Object A_0, Stream A_1, ExcelVersion A_2, ExcelParseOptions A_3)
at spr995.0(Stream A_0, ExcelVersion A_1, ExcelParseOptions A_2)
at Spire.Xls.Workbook.LoadFromStream(Stream stream)

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

Mon Apr 24, 2017 10:12 am

Hello,

Thanks for your feedback. AS per your describtion, you have added the dlls into the mother application, but I think when you only run the exe application in that appdomain, the dlls won't be loaded, hence you also need to reference our product dlls once you use the product in subroutine. Hope this helps.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Tue Apr 25, 2017 9:20 am

Hello and thanks for your effort

This is the code that creates appdomain and loads Spire in it:

Code: Select all
    public class Sandboxer : MarshalByRefObject
    {
        Dictionary<string, Assembly> AlreadyLoadedDLLs = new Dictionary<string, Assembly>();
        AppDomain ad = null;

        public void Execute(Object[] Arguments, string MainProgramDLL)
        {
            ad = AppDomain.CurrentDomain;
            ad.AssemblyResolve += MyHandler;

            Assembly Current = ad.Load(MainProgramDLL + ".dll");

            //The following lines are for finding entery point  of our own macro and running it.
            Assembly MacroBase_Library = AlreadyLoadedDLLs["MacroBase_Library"];
            MethodInfo MacroBase_Library_Execute = MacroBase_Library.GetType("MacroBase_Library.ProgramManager").GetMethod("Execute");
            MacroBase_Library_Execute.Invoke(null, Arguments);
        }

        Assembly MyHandler(object source, ResolveEventArgs e)
        {
            string name = e.Name.Split(',')[0];
            if (!AlreadyLoadedDLLs.ContainsKey(name))
            {
                Assembly ASM = Assembly.LoadFile(ad.BaseDirectory + name);
                MacroBaseSpecialTreatment(ASM);
                return ASM;
            }
            else
                return AlreadyLoadedDLLs[e.Name];
        }

        private void SweepReferences(AssemblyName[] ANs)
        {
            foreach(AssemblyName AN in ANs)
            {
                string name = AN.FullName.Split(',')[0].Replace(".dll","");
                if (!AlreadyLoadedDLLs.ContainsKey(name))
                {
                    Assembly ASM = ad.Load(AN.FullName);
                    AlreadyLoadedDLLs.Add(name, ASM);
                    MacroBaseSpecialTreatment(ASM);//This line ensures that our own macro is early loaded to appdomain by calling a dummy method
                }
            }
        }
    }


And it successfully loads all dlls to appdomain before executing it. This is the standard way of loading an appdomain and I think it is loading dlls to appdomain correctly, not to mother applicatio as your guess.

I have also attached snapshot of QuickWatch window showing the assemblies that are already loaded. I t seems that dlls are correctly loaded. One more important point is that I can successfully run :

Code: Select all
SpireWorkbook = new Spire.Xls.Workbook();

Then in next line :
Code: Select all
SpireWorkbook.LoadFromStream(stream);

I receive the exception.

I could not find to where or which dll this missing component belongs.

Thanks
Attachments
1.rar
snapshot of dlls which are successfully loaded
(41.36 KiB) Downloaded 390 times

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

Tue Apr 25, 2017 9:44 am

Hello,

Thanks for your detailed information. The reason should be that it is lacking of Spire.Pdf or Spire.Common assembly, please load all assemblies and try it again.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Wed Apr 26, 2017 4:28 pm

Hello

I loaded Spire.pdf.dll and Spire.common.dll manually. Unfortunately the problem persists. Please see attached file.

Thanks
Attachments
2.rar
(42.51 KiB) Downloaded 339 times

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

Thu Apr 27, 2017 9:33 am

Hello,

Let’s try to narrow down the problem to a simple application. Please try creating a simple Console application, add references in AppDomain and try it. Does the problem occur with such a simple application?
If you will be able to reproduce the problem with such a simple application, please attach the whole solution here for testing. We will check it on our side and provide you more information.

Thanks,
Gary
E-iceblue support team
User avatar

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

Fri Apr 28, 2017 9:53 pm

Hello

File size was larger than 2MB. I have emailed the solution to Jane.

Thanks

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

Mon May 01, 2017 3:18 am

Hello,

Thanks for the sharing. I have noticed the issue and posted it to our Dev team, once it is resolved, or we have some other update, we will let you know ASAP.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Wed May 10, 2017 2:53 pm

Hello

Any news?

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

Thu May 11, 2017 6:55 am

Hello,

Unfortunately, the issue is not resolved yet, and it is being analyzed. You will surely be notified as soon as it is resolved. Sorry for the inconvenience.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Fri May 12, 2017 7:02 am

Hello,

Glad to inform you that we have located the reason that caused the exception. The solution is to cancel the MyHandler event after loading the dlls. Here is the code segment for your reference.
Code: Select all
ad.AssemblyResolve += MyHandler;
Assembly Current = ad.Load(MainProgramDLL + ".dll");
ad.AssemblyResolve -= MyHandler;


Sincerely,
Gary
E-iceblue support team
User avatar

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

Fri May 26, 2017 9:58 am

Hello
Thanks for your efforts. I did extensive try and error on matter of loading dlls for this reason and other reasons. This is the result:

If you want to load all referenced dlls in advance, you would almost need to load the whole GAC all at once. The reason is that dlls have reference to each other. Dot net loads referenced dlls when needed. If you want to sweep all references and load them, the list gets larger and larger. That is the reason Microsoft has provided this system of handler event. This event gets fired once it is needed, during execution of code.

If we want to delete the handler, then we need to load all levels of references at once, which is not practical. I hope there could be another solution.

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

Mon May 29, 2017 6:01 am

Hello,

Thanks for your response. We will look into this further and try to find out another solution, once there is new update, we will let you know ASAP.

Thanks,
Gary
E-iceblue support team
User avatar

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

Tue Jul 04, 2017 8:51 am

Hello

Any news?

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

Tue Jul 04, 2017 9:41 am

Hello,

Sorry that there is still no any new update, we will update the thread once there is news.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Return to Spire.XLS