I am trying to convert stream to SKManagedStream. In one pc its working find and in another pc its giving below exception for same image. I am using same code and same package of skiasharp(1.57.0) on both the pc
Code....
public static Stream ResizeImage(Stream imageStream, int mySize, int myQuality = 75)
{
int size = mySize;
int quality = myQuality;
imageStream.Position = 0;
using (var inputStream = new SKManagedStream(imageStream))
{
//SomeCode....
}
}
Exception....
System.TypeInitializationException occurred
HResult=0x80131534
Message=The type initializer for 'SkiaSharp.SKManagedStream' threw an exception.
Source=SkiaSharp
StackTrace:
at SkiaSharp.SKManagedStream..ctor(Stream managedStream)
at ImageUploadOWIN.Controllers.ImageUploadController.ResizeImage(Stream imageStream, Int32 mySize, Int32 myQuality) in Controllers\ImageUploadController.cs:line 271
Inner Exception 1:
BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
This appears to be an issue with your compiler architecture... "An attempt was made to load a program with an incorrect format."
I am assuming you are running Windows as this is where this type of error usually occurs.
Are you building for x86, x64 or Any CPU? Is this .NET Core or Full .NET Framework? One machine may be running an x86 OS and the other a x64 OS. Because we are using a native library, you may need to build for each architecture separately. If you are building for Any CPU, both platform native files will be copied into the output directory, as well as the current platform in the bin. If you are running on a specific architecture, you can just copy the required native file out of the sub folder into the bin.
Hi @mattleibow ,
I am running on Full .NET Framework with Any CPU. Both the machine running on X64 Windows 10 OS.
Both have native file for each CPU architecture in separate folder and X64 one in bin folder.
The only difference is working one is running on IIS 8 on Xeon Processor. Non working on is using IIS express on Core I7 in debug mode.
I have made simple console application on core i7 Full .NET Framework with Any CPU its working fine.
Its working after changing from x86 to x64. Thanks.
The build should work for the machine that it is building on (and from the IDE). but as soon as you change it, there is no way for the build to know.
The reason for the two "x86" and "x64" folders is that depending on the destination architecture, you are supposed to copy the contents out of the sub folder and next to the main exe.
Most helpful comment
Its working after changing from x86 to x64. Thanks.