System.ArgumentNullException: 'Value cannot be null. (Parameter 'key')' when calling TextLayer.GetFonts()

After loading a psd and wanting to do Textlayer.GetFonts(), it throws an error:
“System.ArgumentNullException: ‘Value cannot be null. (Parameter ‘key’)’ ”.

This part of the code works without problems with version 23.8 but after updating to 23.9 I get this error everytime I try to acces this code and with a multiple types of files. In order to fix a bug i need the update to 23.9 but this error doesn’t let me do that.

One of the file I used:
SimpleText.zip (20.0 KB)

And the code looks like this:
public virtual void ProcessContentFromTextLayer(TextLayer textLayer)
{
var textLayerFonts = textLayer.GetFonts(); - here i get the problem
int portionIndex = 0;

foreach (var textPortion in textLayer.TextData.Items)
{
    textPortionFont = textLayerFonts[textPortion.Style.FontIndex];
    textPortionInfo = _cfTagPairBuilder.CreateTextPortionInfo(textPortion.Style, textPortionFont);

}
}

@afaluta
I made investigation and can not reproduce the issue. But according to our statistics, some customers faces the similar issue too. Could you please provide more information. What’s configuration of Aspose.PSD is used (.NET Framework 2 - 4, .net standard, .net 5-7). What’s operation system is used. Could you please sned us the full exception information, with the stacktrace if it’s available.

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): PSDNET-1756

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.

I’m using Aspose.PSD with .net6 on Windows as operating system.
The stack trace looks like this:
Message:
Test method Sdl.FileTypeSupport.Filters.Photoshop.AcceptanceTests.Specs.ContextInformationFeature.DisplaysContextInformationsForASimpleTextLayer threw exception:
System.ArgumentNullException: Value cannot be null. (Parameter ‘key’)

Stack Trace:
Dictionary2.FindValue(TKey key) .() .(Boolean ) .(String ) .(String ) .(String ) TextLayer.GetFonts() TextContentProcessor.ProcessContentFromTextLayer(IParagraphUnit paragraphUnit, TextLayer textLayer) line 45 TextLayerConsumer.ProcessParagraphUnit(TextLayer textLayer) line 81 TextLayerConsumer.OutputTextParagraphUnit(TextLayer textLayer) line 61 TextLayerConsumer.Consume(ImageElementMessage1 message) line 54
Consumer1.TryConsume(T message) line 20 Consumer1.TryConsume(IMessage message) line 14
InMemoryMessageBus.Publish(IMessage message) line 17
ImageTraverser.PublishImageElementMessage[T](T imageElement) line 64
ImageTraverser.PublishLayer(Layer layer) line 54
ImageTraverser.TraverseLayers(IReadOnlyList`1 layers) line 47
ImageTraverser.TraverseImage(PsdImage image) line 32
PhotoshopParser.ParseNext() line 63
ParserContext.Parse() line 65
ParserSteps.WhenTheDocumentIsParsed() line 52
BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
TestExecutionEngine.OnAfterLastStep()
TestRunner.CollectScenarioErrors()
ContextInformationFeature.ScenarioCleanup()
ContextInformationFeature.DisplaysContextInformationsForASimpleTextLayer() line 9

Hope this is ok . If there is any further information needed, let me know!

@afaluta thank you for the stacktace. It will help us.

Could you please additionally tell us the version of the Windows (10-11) and the Windows Architecture x86, x64, ARM.

I added your information to the ticket.

I’m on a Windows 11 with x64 architecture

1 Like

@afaluta I’ve updated the issue with new details. Thank you.

The issues you have found earlier (filed as PSDNET-1756) have been fixed in this update. This message was posted using Bugs notification tool by yaroslav.lisovskyi

Even with the latest version of Aspose.PSD and .net6 this issue isn’t fixed. I created a small project that reproduces exactly the problem maybe it helps.
TestAsposePsd23.11_net60.7z (70.7 KB)

@afaluta we need time to investigate it. I’ll text you later.

Could you please check fix with this code:

string src = Path.Combine(baseFolder, "SimpleText.psd");

FontSettings.RemoveFontCacheFile();

using (var psdImage = (PsdImage)Image.Load(src))
{
    foreach (var layer in psdImage.Layers)
    {
        if (layer is TextLayer textLayer)
        {
            textLayer.GetFonts();
        }
    }
}

Adding FontSettings.RemoveFontCacheFile(); before the call of GetFonts seems to fix the problem but i’ll play a little more with this fix to be sure.

@afaluta

This issue was because Aspose.PSD in some rare cases was writing broken cache. We’ve fixed this issue, and it will not affect the using of library in the future, but for the customers who already faced with this, RemoveCacheFile() is the best solution.

1 Like