saucecontrol / PhotoSauce

MagicScaler high-performance, high-quality image processing pipeline for .NET
http://photosauce.net/
MIT License
569 stars 49 forks source link

Could not load type 'PhotoSauce.MagicScaler.Converters.ChannelChanger`1' #125

Closed hheexx closed 9 months ago

hheexx commented 9 months ago

After updating to 0.14 (dotnet 7 on linux):

System.TypeLoadException

Could not load type 'PhotoSauce.MagicScaler.Converters.ChannelChanger`1' from assembly 'PhotoSauce.MagicScaler, Version=0.14.0.0, Culture=neutral, PublicKeyToken=fc6b9b7b06809481'.

saucecontrol commented 9 months ago

That type was renamed in https://github.com/saucecontrol/PhotoSauce/commit/4a5048a679b71295fdcf95d0a1eeae3adf1c22e1, but it was internal and is no longer referenced anywhere in my code.

I'd guess either you've got a mismatched codec assembly version (NuGet dependencies should prevent that) or you've got something using it through reflection (in which case you get what you get).

hheexx commented 9 months ago

I'm not using any reflation related to this library, just resizing large number of images from web....

hheexx commented 9 months ago

Here is stack:

System.TypeLoadException: Could not load type 'PhotoSauce.MagicScaler.Converters.ChannelChanger`1' from assembly 'PhotoSauce.MagicScaler, Version=0.14.0.0, Culture=neutral, PublicKeyToken=fc6b9b7b06809481'. ?, in void PngEncoder.writeHeader(int pngfmt, int width, int height, IPixelSource src, IMetadataSource meta) ?, in void PngEncoder.WriteFrame(IPixelSource source, IMetadataSource metadata, Rectangle sourceArea) ?, in ProcessImageResult MagicImageProcessor.WriteOutput(PipelineContext ctx, Stream ostm) ?, in ProcessImageResult MagicImageProcessor.ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings) File "ImageResizePlugin.vb", line 102, col 9, in MemoryStream ImageResizePlugin.ResizeImageMIP(MemoryStream ms)

saucecontrol commented 9 months ago

Ok, that'll be an incompatible version of the libpng codec plugin. You need to update that to https://www.nuget.org/packages/PhotoSauce.NativeCodecs.Libpng/1.6.39-preview1. The dependencies are set up correctly in the packages (e.g. the older codec library is version restricted to < 0.14) https://www.nuget.org/packages/PhotoSauce.NativeCodecs.Libpng/1.6.37-preview1#dependencies-body-tab.

Same applies to all of the codec plugin packages. There are updated versions of all of them tied to the new version of the MagicScaler package.

I'm curious how you got in that state since the SDK should refuse to restore an incompatible combination of dependent packages.

hheexx commented 9 months ago

Aha....Tnx.

Here are my project references:

<PackageReference Include="PhotoSauce.MagicScaler" Version="0.14.0" />
<PackageReference Include="PhotoSauce.NativeCodecs.Giflib" Version="5.2.1-preview1" />
<PackageReference Include="PhotoSauce.NativeCodecs.Libheif" Version="1.13.0-preview1" />
<PackageReference Include="PhotoSauce.NativeCodecs.Libjpeg" Version="2.1.4-preview1" />
<PackageReference Include="PhotoSauce.NativeCodecs.Libjxl" Version="0.7.0-preview1" />
<PackageReference Include="PhotoSauce.NativeCodecs.Libpng" Version="1.6.37-preview1" />
<PackageReference Include="PhotoSauce.NativeCodecs.Libwebp" Version="1.2.4-preview1" />

I updated main MagicScaler package from visual studio but I did not see plugin updates as they are still published as previews and I did not check "include prerelase" in VS package manager.

I'm not sure what SDK does in that situation but I received no warning and everything compiled nicely....

saucecontrol commented 9 months ago

Ah, that's a bummer. I knew they wouldn't show up by default in the VS UI because of the preview version, but I assumed the package restore would fail and give you a clue.

I really prefer to leave the codec packs tagged as preview for now, but that's obviously not a great user experience. Thanks for letting me know about the friction there. For now, I'll add something to the release notes to call out the incompatibility.

saucecontrol commented 9 months ago

FYI, I tried to reproduce this to log a bug against the NuGet client, but I'm getting a warning as expected in both the 7.0 and 8.0RC2 SDKs (also visible in the VS Error List window).

warning NU1608: Detected package version outside of dependency constraint: PhotoSauce.NativeCodecs.Libpng 1.6.37-preview1 requires PhotoSauce.MagicScaler (>= 0.13.2 && < 0.14.0) but version PhotoSauce.MagicScaler 0.14.0 was resolved.

Maybe you missed the warning? I guess they wouldn't make it an error severity because they have no way of knowing whether the incompatibility will actually cause issues at runtime or not...

hheexx commented 9 months ago

yea I missed the warning, i have a lot :) tnx!