System.TypeInitializationException

Hello,

Does the following code need to be within an executable project to run as the same code does not run from within a library project?

Exe net5.0 _5_0
    static void Main(string[] args)
    {

        // Instantiate JSON data source
        JsonDataSource jsonDataSource = new JsonDataSource(@"C:\json.json");

        // Pull in template
        string templete = @"C:\Template.pptx";

        // Set the output
        string outputPptxPath = @"C:\Output.pptx";

        try
        {
            DocumentAssembler assembler = new DocumentAssembler();

            assembler.AssembleDocument(templete,
                  outputPptxPath,
                  new DataSourceInfo(jsonDataSource, "managers"));
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

I get the following error when I run from within a library:
image.png (46.5 KB)

Kind regards,
djs

1 Like

@djsomers1000
We are investigating this scenario at our end. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): ASSEMBLYNET-232

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello again,

Also, adding the LoadSaveOptions needs to be investigated as well:

image.png (12.4 KB)

Regards,
djs

@djsomers1000

Can you please share more details on this?

Sure… I also passed the LoadSaveOptions() to the AssembleDocument and I got the same error, please see highlighted text in the image below:

image.png (32.9 KB)

I was testing different overloads to see if it would make a difference, but I’m still getting an error.

I hope that helps.

1 Like

@djsomers1000

Thanks for the details. We’ll continue the investigation and notify you in case of any update.

1 Like

@djsomers1000

We have tested GroupDocs.Assembly for .NET 22.12 in both console application and class library project types. .NET 5 has been used for testing. We could not reproduce this issue. Could you please specify the API version that you used in your Library project?

The version is:

In addition to the above, I asked one of our senior developers to take a look and see if they could spot anything. They discovered that:

“we have narrowed the issue down to being the UseReflectionOptimization not initializing, causing the program to crash”

image.png (16.1 KB)

They asked if there are any permissions they may need for this to run?

@djsomers1000

Your forgot to specify the API version though. I’d be great if you share a sample application with us using that issue could be reproduced.

Sorry, I included a the whole tag and I don’t think it appeared when sent:

Here you go:
image.png (2.3 KB)

With regards to the sample application, we replicated it using our main solution so we can’t share that with you.

@djsomers1000

We had a similar issue for older versions, but it has been fixed in GroupDocs.Assembly for .NET 22.12. Please make sure you are using latest version of GroupDocs.Assembly for .NET.

We are using the latest version:
22.12.0

@djsomers1000

Please take a look at this ConsoleApp.zip (26.3 KB). It contains two projects targeting .NET 5:

  • A class library referencing GroupDocs.Assembly 22.12 and calling DocumentAssembler.AssembleDocument for test purposes.
  • A console application referencing the class library and calling a class method from the library. Note, the project itself does not reference GroupDocs.Assembly directly, so it tests how calling DocumentAssembler.AssembleDocument through a class library works.

However, if issue still persists. Kindly provide us with a sample application and the necessary steps to replicate the issue.

Hey Atir,

I work with djsomers and have been looking into this. It seems we are having the same issues as some other users have been getting with the .NET 6 UseReflectionOptimisation NULL reference issues (ASP.NET Core 6.0.7 Support - #13 by bkbejawada & Groupdocs.Assembly - .NET 6).

The issue we’re getting is that the DocumentAssembler.UseReflectionOptimization isn’t starting when we create a new instance of the DocumentAssembler. (we get the same error messages as the support tickets I linked above).

I’ve included our code below. We are using .NET 5 (windows) with GroupDocs.Assembly v22.12

// Here we set up the JSON Data Load Options based on user info
GroupDocs.Assembly.Data.JsonDataLoadOptions options = new GroupDocs.Assembly.Data.JsonDataLoadOptions();

switch (Message.Documents[0].PowerPointJsonParseMode)
{
  case PowerPointJsonParseMode.Loose:
    options.SimpleValueParseMode = GroupDocs.Assembly.Data.JsonSimpleValueParseMode.Loose;
    break;
  case PowerPointJsonParseMode.Strict:
    options.SimpleValueParseMode = GroupDocs.Assembly.Data.JsonSimpleValueParseMode.Strict;
    break;
  default:
    options.SimpleValueParseMode = GroupDocs.Assembly.Data.JsonSimpleValueParseMode.Loose;
    break;

GroupDocs.Assembly.Data.JsonDataSource ds = new GroupDocs.Assembly.Data.JsonDataSource(stream, options);
GroupDocs.Assembly.DocumentAssembler engine = new GroupDocs.Assembly.DocumentAssembler();
// Here I was attempting to either start the optimizer manually, or set it to false. Neither worked as was NULL
DocumentAssembler.UseReflectionOptimization = new();

// Here we set some more options
if (Message.Documents[0].PowerPointAllowMissingMembers == true)
{
  engine.Options |= GroupDocs.Assembly.DocumentAssemblyOptions.AllowMissingMembers;
}

if (Message.Documents[0].PowerPointRemoveEmptyParagraphs == true)
{
  engine.Options |= GroupDocs.Assembly.DocumentAssemblyOptions.RemoveEmptyParagraphs;
}

if (Message.Documents[0].PowerPointInlineErrorMessages == true)
{
  engine.Options |= GroupDocs.Assembly.DocumentAssemblyOptions.InlineErrorMessages;
}

// And then finally we attempt to assemble the document
engine.AssembleDocument(
  Message.Documents[0].FilePath,
  RDoc.FilePath,
  new GroupDocs.Assembly.LoadSaveOptions(GroupDocs.Assembly.FileFormat.Pptx),
  new DataSourceInfo(ds));

I have read through the other support tickets on this and I have added the referenced projects that you ask for (We already use the Aspose libraries in our solution, so the references were already present when we added our reference for GroupDocs)

One thing that may be of note, we have to target a windows specific build for our solution (we have functions that rely on a full version of windows/windows forms)
<TargetFramework>net5.0-windows</TargetFramework>

  <ItemGroup>
    <PackageReference Include="AngleSharp" Version="0.16.1" />
    <PackageReference Include="Aspose.BarCode" Version="22.10.0" />
    <PackageReference Include="Aspose.CAD" Version="22.10.0" />
    <PackageReference Include="Aspose.Cells" Version="22.11.0" />
    <PackageReference Include="Aspose.Diagram" Version="22.10.0" />
    <PackageReference Include="Aspose.Email" Version="22.9.0" />
    <PackageReference Include="Aspose.HTML" Version="22.9.0" />
    <PackageReference Include="Aspose.Imaging" Version="22.10.0" />
    <PackageReference Include="Aspose.Note" Version="22.9.0" />
    <PackageReference Include="Aspose.OCR" Version="22.9.0" />
    <PackageReference Include="Aspose.PDF" Version="22.10.0" />
    <PackageReference Include="Aspose.Slides.NET" Version="22.10.0" />
    <PackageReference Include="Aspose.Tasks" Version="22.10.0" />
    <PackageReference Include="Aspose.Words" Version="22.10.0" />
    <PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="22.10.0" />
    <PackageReference Include="Aspose.Zip" Version="22.9.0" />
    <PackageReference Include="GroupDocs.Assembly" Version="22.12.0" />

We also set up a Metered License in the Startup of our API (again, we already use Aspose in our solution so we already have a metered license set up function, present)

GroupDocs.Assembly.Metered groupDocsLic = new GroupDocs.Assembly.Metered();

string _asposeLicenseMeteredPublic = Configuration["PATHTOLICENSEKEY"];
string _asposeLicenseMeteredPrivate = Configuration["PATHTOLICENSEKEY"];

groupDocsLic.SetMeteredKey(_asposeLicenseMeteredPublic, _asposeLicenseMeteredPrivate);

I’ve tried the steps mentioned in the other support tickets around this, but no change. I have also downloaded the Console application you supplied above and that works, so not sure as to what this issue could be

Thanks,

Charlie

1 Like

@charlie.lancaster

Thank you for providing the details. We will proceed with the investigation and keep you informed if there are any updates.

@charlie.lancaster

Unfortunately, we still cannot reproduce this issue. The code you provided does not compile. Please provide a minimal standalone console (or WinForms, or whatever) application using that issue could be reproduced.

Hey Atir,

I have created a simple console app that replicates the error. I just tested it and I still get the same issue (The type initializer for ':spades:▬:slight_smile:hrew an exception.)

GroupDocs-reflection-optimisation-error.zip (28.3 KB)

Thanks,

Charlie

1 Like

@charlie.lancaster

Thanks for the application. Please spare us sometime and we’ll notify you in case of any update.

@charlie.lancaster @djsomers1000

The issue appears because you referenced Aspose APIs with versions differing from those used by GroupDocs.Assembly 22.12. For GroupDocs.Assembly 22.12, there is no need to reference Aspose components. However, if you want to use GroupDocs.Assembly and other Aspose APIs within a single project, please use the following versions of Aspose products to resolve the issue:

<PackageReference Include="Aspose.BarCode" Version="20.4.0" />
<PackageReference Include="Aspose.Cells" Version="20.7.0" />
<PackageReference Include="Aspose.Email" Version="20.7.0" />
<PackageReference Include="Aspose.Slides.NET" Version="20.2.0" />
<PackageReference Include="Aspose.Words" Version="21.8.0" />