DEBUG and RELEASE modeDecoding and encoding this image in RELEASE mode throws the following exception. In DEBUG it works fine.

Message: System.OutOfMemoryException : Array dimensions exceeded supported range.
List`1.set_Capacity(int32 value)
List`1.Add(T item)
IccWriter.WriteTagData(IccDtatWriter writer, List`1 entries)
The last item in the StackTrace can be found here
The following code should be enough to reproduce the error.
c#
using (var image = Image.Load("sample.jpg"))
{
image.Save("sample1.jpg");
}
This is really weird. There's nothing in our code as far as I can see that would cause this issue. It fails every single time in RELEASE and works every time in DEBUG.
Something weird is happening, I did some poor man debugging:
C#
IccTagDataEntry[] items = inData.Where(t => inData[0].Equals(t)).ToArray();
if (items.Length == 0)
{
throw new System.NotImplementedException(string.Join("\n", inData.Select(t => t.Signature.ToString() + "_" + t.TagSignature.ToString())));
}
If I do a break instead the test passes. Off to work now, I hope this will help you further.
I am guessing that there is a funky Equals overload in one of the entries here: https://github.com/JimBobSquarePants/ImageSharp/tree/023cce36aee5d8bd26de17cf131afbb8f1bef3ba/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries. I also wonder about the implementation you chose. I would let
public override bool Equals(IccTagDataEntry other) call public bool Equals(IccChromaticityTagDataEntry other) instead of the other way around.
I think you might be correct. There's a mix here of IEquatable<T> and inheritance plus only Equals(object) is only implemented in the base classes. As far as I know you should only implement it on sealed classes and always do both Equals(object) and GetHashCode()
Bravo @dlemstra you were bang on the money. It took me a few hours but I fixed the IEquatable implementation to work properly with inheritance.
@dlemstra @JBildstein One thing I have noticed since I refactored the inheritance to work is that there appears to be more ICC data coming out than going in. Any idea what could cause it?
Think I've fixed it with the last commit.
good to hear that you were able to resolve it. The equality of the TagDataEntries was something I wanted to discuss with you but I have to admit that I forgot.
The issue with more data going is very likely related to that. An ICC profile can reuse the data for multiple entries and finding out if an entry is the same is done with Equals. I assume that some entries don't appear equal even if they are, so the data is written multiple times.
I think there is also some potential for optimization by reading it only once and reusing the same instance but I'll have to check that again.
@JBildstein It does appear to vary from image to image. Definitely worth looking into. We should get the ball rolling with color transforms based on the profile also. Today I learned that WIC doesn't preserve the profile it just performs the change based on it.