I'm creating an image resizing middleware for my .net core 2.0 website with https://github.com/saucecontrol/PhotoSauce. After publishing my application to a windows server 2012(.NET Framework 4.7.2) it won't work anymore. What can I do?
2019-04-12 13:34:46.656 +02:00 [ERR] An unhandled exception has occurred while executing the request. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Notenverwaltung.Middleware.MagicScalerImageResizer.Resize(Stream inputStream, Stream outputStream, ImageResizerOptions options) at Notenverwaltung.Middleware.ImageHandlerMiddleware.<>c__DisplayClass6_1.b__0() in C:\ba\work\6b084d553e5d8510\Notenverwaltung\Notenverwaltung\Middleware\ImageHandlerMiddleware.cs:line 45 at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Notenverwaltung.Middleware.ImageHandlerMiddleware.d__6.MoveNext() in C:\ba\work\6b084d553e5d8510\Notenverwaltung\Notenverwaltung\Middleware\ImageHandlerMiddleware.cs:line 43 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d__6.MoveNext()
public async Task InvokeAsync(HttpContext context)
{
var path = context.Request.Path.Value;
if (path.StartsWith($"/{_pathStart}"))
{
var pathToImage = _env.WebRootPath + path.Replace($"{_pathStart}/", default(string)).Replace("/", "\\");
if (File.Exists(pathToImage))
{
int.TryParse(context.Request.Query["w"], out var newImageWidth);
int.TryParse(context.Request.Query["h"], out var newImageHeight);
var options = new ImageResizerOptions(newImageWidth, newImageHeight);
await Task.Factory.StartNew(() =>
{
_imageResizer.Resize(File.OpenRead(pathToImage), context.Response.Body, options); // <-- It's this that goes wrong
});
}
else
{
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
await context.Response.WriteAsync("NOT FOUND");
}
return;
}
await _next(context);
}
public void Resize(Stream inputStream, Stream outputStream, ImageResizerOptions options)
{
using (var memoryStream = new MemoryStream())
{
var settings = new ProcessImageSettings
{
Width = options.NewWidth,
Height = options.NewHeight
};
MagicImageProcessor.ProcessImage(inputStream, memoryStream, settings);
memoryStream.WriteTo(outputStream);
}
}
User contributions licensed under CC BY-SA 3.0