0

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);
            }
        }
Johannes
  • 41
  • 1
  • 2
    You say this is .NET Core but state your Win server is running 4.7.2. Is .NET Core runtime installed on the server? Also, is the Windows Imaging Component installed on the server? – DavidG Apr 12 '19 at 12:27
  • Possible duplicate of [Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies](https://stackoverflow.com/questions/42755274/visual-studio-2017-could-not-load-file-or-assembly-system-runtime-version-4) – smolchanovsky Apr 12 '19 at 12:27

0 Answers0