Hi there,
We are utilising Aspose.Cells in an application and have a problem in the following scenario:
- We have a class library that references Aspose.Cells.dll. The Aspose license is embedded in this class library. This class library targets Any CPU.
- We have a WinForms application that references the above mentioned class library. This application targets x64.
- When we start the WinForms application, it fails to start and crashes. I will paste the event viewer error later in this post.
- This crash only occurs when built in 64bit, and in release mode. I.e. the issue does not occur if we build in 32bit, or debug mode.
- This crash does not occur for Aspose.Words.dll. Our application also utilises Aspose.Words.
- This crash does not occur if I also embed the Aspose license to the WinForms application. However, this is not a viable solution for us.
- I have tried various versions of Aspose.Cells.dll, e.g. 8.8, 8.9, 7.x. They all have the same problem.
My question is, given that this issue does not occur for Aspose.Words, or any other configuration other than 64bit release mode, is there workaround for this crash?
3 event viewer events are logged from the crash:
- Source: Windows Error Reporting
Fault bucket 129213755327, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 129182535269
Problem signature:
P1: DatalogicsTest.exe
P2: 1.0.0.0
P3: 57d217c8
P4: Aspose.Cells
P5: 8.9.2.0
P6: 57b66add
P7: 1ccb
P8: 95
P9: System.IO.FileNotFoundException
P10:
Attached files:
C:\Users\sid\AppData\Local\Temp\WER8AE.tmp.WERInternalMetadata.xml
C:\Users\sid\AppData\Local\Temp\WER114A.tmp.appcompat.txt
C:\Users\sid\AppData\Local\Temp\WER115A.tmp.dmp
These files may be available here:
C:\Users\sid\AppData\Local\Microsoft\Windows\WER\ReportArchive\AppCrash_DatalogicsTest.e_bc5831bb20662a57e91cef35457b84aec89651c5_cab_300717b1
Analysis symbol:
Rechecking for solution: 0
Report Id: 36557e4b-7631-11e6-bee0-fc4dd43d84e7
Report Status: 24
Hashed bucket: f1849fc84871079b157b424b1cec396a
- Source: Application Error
Faulting application name: DatalogicsTest.exe, version: 1.0.0.0, time stamp: 0x57d217c8
Faulting module name: KERNELBASE.dll, version: 6.2.9200.16864, time stamp: 0x531d34d8
Exception code: 0xe0434352
Fault offset: 0x0000000000047b8c
Faulting process id: 0x413c
Faulting application start time: 0x01d20a3df8871915
Faulting application path: C:\Users\sid\Documents\Visual Studio 2015\Projects\DatalogicsTest\DatalogicsTest\bin\x64\Release\DatalogicsTest.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll
Report Id: 36557e4b-7631-11e6-bee0-fc4dd43d84e7
Faulting package full name:
Faulting package-relative application ID:
Application: DatalogicsTest.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
at ? .(System.String, System.Reflection.Assembly)
at ? .(System.String, System.Reflection.Assembly)
at DatalogicsTest.Form1…ctor()
at DatalogicsTest.Program.Main()
Thanks in advance for your assistance.
Regards,
Sid
Hi Sid,
Thank you for contacting Aspose support.
It would be of great help if you can provide us an executable sample application covering your complete scenario. This will serve the starting point to the investigation, and we will be in a far better position to assist you with it.
Please note, as you are embedding the license in a class library and accessing the class library from a WinForm application, we suggest you to create a single solution having two projects (class library & WinForm application) in it. Please copy paste the code from your original application to new project just to replicate the issue, then share it here for investigation. Please note, you do not need to embed your license in the test project, however, please paste the code to get the embedded resource and set the license.
Thanks for your reply Babar.
I’m happy to share the code with you, as it is a bare bones sample application just to prove the issue. However, I don’t see an option to share code, so I’ll just paste it.
I have a WinForms project with no controls, all it does is invoke the class library in the constructor:
using System.Windows.Forms;
using ClassLibrary;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Test();
}
public void Test()
{
CompareDocs compareDocs = new CompareDocs();
}
}
}
I have a class library with 1 class:
using AsposeCells = Aspose.Cells;
namespace ClassLibrary
{
public class CompareDocs
{
public CompareDocs()
{
AsposeCells.License cellLicense = new AsposeCells.License();
cellLicense.SetLicense(“Aspose.Total.lic”);
}
}
}
Notes:
- I compile the class library separately, and add a reference to its output DLL as a reference (instead of adding as project reference)
- Class library targets any CPU release mode
- WinForms application targets x64 release mode
- Class library embeds Aspose license, Winforms application does not
- To reproduce issue, simply attempt to open WinForms output exe, and it shouldn’t open
Regards,
Sid
Hi Sid,
Thank you for sharing the code snippets.
I will start the investigation with the provided information and keep you posted with updates in this regard. Please note, you can share your complete project by clicking the Add/Update button found at the bottom of post window, however, you have to first zip the project/solution files before attaching them here.
Hi Sid,
This is to update you that I have performed a few tests on my side however, I was not able to observe any problem while starting the Windows Form application. Following are the steps that I have carried out in order to investigate the matter.
- Created a project of type Class Library.
- Embedded the license file in the Class Library and set it using the License.SetLicense method.
- Build the project to generate the DLL.
- Created a project of type Windows Form Application and referenced the DLL generated in above steps.
- Set the Configuration to Release and Platform to x64.
- Build the project to generated EXE.
- Executed the EXE.
Moving forward, I need more information such as target .NET Framework and what Aspose.Cells assembly you have used in the project. It would be of great help if you could share a sample application to replicate the issue on my side. Please include everything in the archive excluding the license file only.
Moreover, as you are passing just the license file name to the SetLicense method in your Class Library, and it should exhibit the desired behaviour, however, there is another way to access the embedded resource, that is; while using the System.Reflection as demonstrated below. Could you please give the following approach a try on your side?
C#
Aspose.Cells.License l = new Aspose.Cells.License();
using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(“ClassLibrary1.Aspose.Total.lic”))
{
l.SetLicense(stream);
}
Thanks again for your fast reply.
I will attach my project so that hopefully you can reproduce the issue. I created a brand new one just to make sure I didn’t make any mistakes. The code is not identical but is pretty much doing the same thing as the code I pasted previously
Please perform the following steps:
- Add license to ClassLibrary (I had license file at same level as Aspose.Cells.dll), and change to embedded resource.
- Build ClassLibrary targeting any CPU Release mode
- Add reference to built DLL as reference to AsposeTest
- Build AsposeTest in x64 Release mode
- Attempt to open the build AsposeTest executable
In case you still can’t reproduce, some more notes about my environment. I’ve tested on my development environment, which is a Windows 8 64bit. I’ve also tested on a Windows 8 64bit and Windows 10 VM.
Also, I did try your suggestion regarding setting the license, but it did not help.
Thanks again for your help.
Sid
Hi Sid,
Thank you for the sample project.
First of all, please note that I am evaluating the presented scenario on Windows 10 x64, and I am able to replicate the said issue if I execute the AsposeTest.exe after adding the license file to the Class Library and adding the reference of Class Library to Windows Form Application. The Event Viewer dialog shows the System.ArgumentNullException at Aspose.Cells.License.SetLicense method. The problem cause is that the Assembly.GetManifestResourceStream method could not find the resource with supplied name. Please note, the parameter consists of 2 parts where first part is the namespace and second part is resource name. Could you please modify the code as follow and give this scenario another try on your end as well? Please note, I am no longer getting any exception in the Event Viewer with following modifications.
C#
Aspose.Cells.License l = new Aspose.Cells.License();
using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(“ClassLibrary.Aspose.Total.lic”))
{
l.SetLicense(stream);
}
Babar,
This worked! It immediately fixed my sample app, but I had to do a bit more tweaking on our actual product. Because the license and class were in a folder, I had to change the string to “..Aspose.Total.lic”.
My last question is: is there a reason that this happens to Aspose.Cells.dll in x64 release mode? Currently, all our products use:
AsposeCells.License cellLicense = new AsposeCells.License();
cellLicense.SetLicense(“Aspose.Total.lic”);
Would you recommend us changing these 2 lines in our products to what you have recommended above?
Thanks again,
Sid
Hi Sid,
Thank you for the confirmation on provided solution. You may use this approach for the time being, in the meanwhile, I will perform more tests against your original scenario and share my findings here.
Hi again,
This is to update you that I am able to observe the problem as per your original scenario therefore I have raised this incident with the product team under the ticket CELLSNET-44744. Please spare us little time to properly analyze the case. In the meanwhile, we will keep you posted with updates in this regard.
Thanks Babar.
We will use your suggested workaround in the meantime.
Hi Sid,
Thank you for your patience with us.
Please note, product team has concluded the analysis, and have suggested to use the attribute
[MethodImplAttribute(MethodImplOptions.NoInlining)] with Class Library’s constructor in order to avoid the said problem. I have tested the solution on my side to get the expected behaviour. Could you please give it a try on your end as well? Moreover,
here is an article on this subject.
C#
namespace ClassLibrary
{
public class Class1
{
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public Class1()
{
Aspose.Cells.License clic = new AsposeCells.License();
clic.SetLicense(“Aspose.Total.lic”);
}
}
}
Babar, this also works.
Thanks for your time on this problem. Our team is very appreciative of the quick response rate, as well as the quality of your responses.
Hi,
Thanks for your feedback and using Aspose.Cells.
It is good to know that your issue is resolved with the suggested solution. Let us know if you encounter any other issue, we will be glad to look into it and help you further.