.Net Core Job - reading resource image is crashing runtime in Azure.

Z_0rr0 101 Reputation points

Suddenly my Azure Job started failing runtime. Works fine on my local. The build machine was migrated (not aware much on details of migration).

var bmp = new Bitmap(100, 100); // Works ok. Since loads it from System.Drawing.Common 4.5

var resourceBmp = TestResources.First; // Crashes runtime trying to load System.Drawing.Common

Could not load file or assembly 'System.Drawing.Common, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)

Stack Trace:

at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark,
ObjectHandleOnStack assemblyLoadContext, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)

at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext
assemblyLoadContext, Boolean loadTypeFromPartialName)

at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark) at
System.Type.GetType(String typeName, Boolean throwOnError) at System.Resources.ResourceReader.FindType(Int32 typeIndex)

at System.Resources.ResourceReader.DeserializeObject(Int32 typeIndex)

at System.Resources.ResourceReader._LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)

at System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)

at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode)

at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)

at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase)

at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)

at System.Resources.ResourceManager.GetObject(String name)

My assumptions is that ResourceManager is probably having reference to version, and is not respecting reference to 4.5 of the Job itself (I am using version System.Drawing.Common 4.5 for our third party Nuget as well).
All this was working fine.

Can it be affected by some newer version of .Net SDK?
How to force ResourceManager to use new version? I mean some kind of bindingRedirect for .NetCore App

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,131 questions
0 comments No comments
{count} vote

Accepted answer
  1. Z_0rr0 101 Reputation points

    So the issue was in newer .Net SDK (5.0) which was installed on build machine. It was not compatible for some reason with System.Drawing.Common.dll coming from nuget packages <5.0
    Updated that package to 5.0 and it fixed the issue. Still strange issue, and strange exception, why it was referring to (which seems that does not even exist in Nuget)

    0 comments No comments

0 additional answers

Sort by: Most helpful