Я занимаюсь разработкой лямбда-функции Aws S3 в ядре .NET.Сейчас я пытаюсь изменить размер изображения и сохранить его как новый файл при загрузке файла изображения в корзину s3.Для изменения размера изображений в ядре .NET я попытался использовать все параметры, упомянутые в этой ссылке .Все параметры работают локально на моем ноутбуке с Windows.Но когда я устанавливаю какой-либо из пакетов или dll-файлов в свой проект и использую его в функции AWS Lambda, я получаю сообщение об ошибке.Для всех библиотек.Похоже, что AWS lambda использует сервер Linux, и библиотекам могут потребоваться дополнительные настройки.
Например, когда я использую в коде CoreCompat.System.Drawing и создаю растровое изображение, подобное этому.
var resized = new Bitmap(100, 100);
Я получил эту ошибку при тестировании на консоли AWS.
{
"errorType": "AggregateException",
"errorMessage": "One or more errors occurred. (The type initializer for 'System.Drawing.GDIPlus' threw an exception.)",
"stackTrace": [
"at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
],
"cause": {
"errorType": "TypeInitializationException",
"errorMessage": "The type initializer for 'System.Drawing.GDIPlus' threw an exception.",
"stackTrace": [
"at System.Drawing.GDIPlus.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0, IntPtr& bmp)",
"at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)",
"at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)",
"at AwsS3Lambda.Function.<FunctionHandler>d__14.MoveNext() in C:\\Users\\Acer\\Desktop\\AwsS3Lambda\\AwsS3Lambda\\AwsS3Lambda\\Function.cs:line 117"
],
"cause": {
"errorType": "DllNotFoundException",
"errorMessage": "Unable to load DLL 'gdiplus': The specified module or one of its dependencies could not be found.\n (Exception from HRESULT: 0x8007007E)",
"stackTrace": [
"at System.Drawing.GDIPlus.GdiplusStartup(UInt64& token, GdiplusStartupInput& input, GdiplusStartupOutput& output)",
"at System.Drawing.GDIPlus..cctor()"
]
}
},
"causes": [
{
"errorType": "TypeInitializationException",
"errorMessage": "The type initializer for 'System.Drawing.GDIPlus' threw an exception.",
"stackTrace": [
"at System.Drawing.GDIPlus.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0, IntPtr& bmp)",
"at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)",
"at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)",
"at AwsS3Lambda.Function.<FunctionHandler>d__14.MoveNext() in C:\\Users\\Acer\\Desktop\\AwsS3Lambda\\AwsS3Lambda\\AwsS3Lambda\\Function.cs:line 117"
],
"cause": {
"errorType": "DllNotFoundException",
"errorMessage": "Unable to load DLL 'gdiplus': The specified module or one of its dependencies could not be found.\n (Exception from HRESULT: 0x8007007E)",
"stackTrace": [
"at System.Drawing.GDIPlus.GdiplusStartup(UInt64& token, GdiplusStartupInput& input, GdiplusStartupOutput& output)",
"at System.Drawing.GDIPlus..cctor()"
]
}
}
]
}
Я знаю, что CoreCompat.System.Drawing имеет кросс-платформенную проблему.Итак, я попытался использовать SkiaSharp, который является компактным для кроссплатформенности.
Как только я вызываю эту строку кода.
using(var inputStream = new SKManagedStream(responseStream))
{
}
Я получил эту ошибку.
{
"errorType": "AggregateException",
"errorMessage": "One or more errors occurred. (The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception.)",
"stackTrace": [
"at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
],
"cause": {
"errorType": "TypeInitializationException",
"errorMessage": "The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception.",
"stackTrace": [
"at SkiaSharp.SKAbstractManagedStream..ctor(Boolean owns)",
"at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream, Boolean owns)",
"at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream)",
"at SkiaSharp.SKManagedStream..ctor(Stream managedStream)",
"at AwsS3Lambda.Function.<FunctionHandler>d__14.MoveNext() in C:\\Users\\Acer\\Desktop\\AwsS3Lambda\\AwsS3Lambda\\AwsS3Lambda\\Function.cs:line 113"
],
"cause": {
"errorType": "DllNotFoundException",
"errorMessage": "Unable to load DLL 'libSkiaSharp': The specified module or one of its dependencies could not be found.\n (Exception from HRESULT: 0x8007007E)",
"stackTrace": [
"at SkiaSharp.SkiaApi.sk_managedstream_set_delegates(IntPtr pRead, IntPtr pPeek, IntPtr pIsAtEnd, IntPtr pHasPosition, IntPtr pHasLength, IntPtr pRewind, IntPtr pGetPosition, IntPtr pSeek, IntPtr pMove, IntPtr pGetLength, IntPtr pCreateNew, IntPtr pDestroy)",
"at SkiaSharp.SKAbstractManagedStream..cctor()"
]
}
},
"causes": [
{
"errorType": "TypeInitializationException",
"errorMessage": "The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception.",
"stackTrace": [
"at SkiaSharp.SKAbstractManagedStream..ctor(Boolean owns)",
"at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream, Boolean owns)",
"at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream)",
"at SkiaSharp.SKManagedStream..ctor(Stream managedStream)",
"at AwsS3Lambda.Function.<FunctionHandler>d__14.MoveNext() in C:\\Users\\Acer\\Desktop\\AwsS3Lambda\\AwsS3Lambda\\AwsS3Lambda\\Function.cs:line 113"
],
"cause": {
"errorType": "DllNotFoundException",
"errorMessage": "Unable to load DLL 'libSkiaSharp': The specified module or one of its dependencies could not be found.\n (Exception from HRESULT: 0x8007007E)",
"stackTrace": [
"at SkiaSharp.SkiaApi.sk_managedstream_set_delegates(IntPtr pRead, IntPtr pPeek, IntPtr pIsAtEnd, IntPtr pHasPosition, IntPtr pHasLength, IntPtr pRewind, IntPtr pGetPosition, IntPtr pSeek, IntPtr pMove, IntPtr pGetLength, IntPtr pCreateNew, IntPtr pDestroy)",
"at SkiaSharp.SKAbstractManagedStream..cctor()"
]
}
}
]
}
Я перепробовал все библиотеки, указанные в ссылке.Все библиотеки работают с ядром .NET локально на моем ноутбуке, когда я создаю новое приложение проекта (Консоль) и тестирую его.Но все библиотеки не работают, когда я использую его в проекте функции AWS Lambda, потому что все библиотеки выдают соответствующую ошибку, когда я тестирую его на консоли AWS.Как изменить размер изображения в лямбда-функции AWS в .NET Core?