Repository navigation
Description
Copied from https://github.com/dotnet/corefx/issues/39980, filed by @Symbai
Accessing a resource file throws a System.MissingMethodException: Constructor on type 'System.Byte[]' not found.
Please see linked issue for repro.
ResX contains
<data name="TestFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TestFile;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>GenerateResource is treating this as an Activator resource and adding it via AddActivatorResource.
https://github.com/microsoft/msbuild/blob/d31fdbf016616835b237d2846f3f1535560bb2d5/src/Tasks/ResourceHandling/FileStreamResource.cs#L44
Here's the relevant desktop code: https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/Resources/ResXFileRef.cs,313
if(toCreate.Equals(typeof(byte[]))) {
created = temp;
} else {
MemoryStream memStream = new MemoryStream(temp);
if(toCreate.Equals(typeof(MemoryStream))) {
return memStream;
} else if(toCreate.Equals(typeof(System.Drawing.Bitmap)) && fileName.EndsWith(".ico")) {
// we special case the .ico bitmaps because GDI+ destroy the alpha channel component and
// we don't want that to happen
Icon ico = new Icon(memStream);
created = ico.ToBitmap();
} else {
created = Activator.CreateInstance(toCreate, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, new Object[] {memStream}, null);
}
}It looks like we missed a special case for byte[]. There is also a special case here for MemoryStream that is likely also relevant.
Activity
ericstj commentedon Aug 5, 2019
/cc @rainersigwald @livarcocc
rainersigwald commentedon Aug 5, 2019
Investigate
MemoryStream/UnmanagedMemoryStreammagic (definitely some in StronglyTypedResourceBuilder).rainersigwald commentedon Aug 12, 2019
@ericstj do you know if things will work if I instantiate a
MemoryStreamin .NET Core and pass that as a live object toAddResource, and then try to access it at runtime in .NET Framework? Or will the type names/assemblies mismatch and cause problems?(Likewise the other possible combinations of building on
{netcoreapp,net472}and targeting{netcoreapp,netstandard,netXX})#4607 has a fix for
byte[], and it'd be easy enough to wrap it with aMemoryStreambut I don't understand the implications.ericstj commentedon Aug 13, 2019
It should work if you call one the stream overloads. For these type name isn't stored, but its treated as a primitive type and will provide an UMS at runtime.