Open xiaoyuvax opened 1 year ago
Add --feature:System.Resources.ResourceManager.AllowCustomResourceTypes=true
to the bflat build
command line. Got this mapping from: https://github.com/dotnet/sdk/blob/6692fa1c9b067ce600df9ad504a0a10d56975339/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L467-L470
Custom resource types are unlikely to work well.
I don't know where to find resgen, sorry.
after adding
--feature System.Resources.ResourceManager.AllowCustomResourceTypes=true
--feature:System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true
the ResourceManager still cannot work, due to following exception:
Unhandled Exception: System.MissingMethodException: No parameterless constructor defined for type 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter'. at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0x121 at System.Resources.ResourceReader.InitializeBinaryFormatter() + 0x1bc at System.Resources.ResourceReader.DeserializeObject(Int32) + 0x30 at System.Resources.ResourceReader._LoadObjectV2(Int32, ResourceTypeCode&) + 0x5d5 at System.Resources.ResourceReader.LoadObjectV2(Int32, ResourceTypeCode&) + 0x11 at System.Resources.RuntimeResourceSet.ReadValue(ResourceReader, Int32, Boolean, ResourceLocator&) + 0x35 at System.Resources.RuntimeResourceSet.GetObject(String, Boolean, Boolean) + 0xde at System.Resources.ResourceManager.GetObject(String, CultureInfo, Boolean) + 0x1ab ...
Right, as I wrote above: it's unlikely to work well. Binary serialization is disabled with trimming in .NET in general. It's not a bflat specific thing.
The problem is why BinaryFormatter(enabled with --feature) can't work with class without explicit parameterless constructor (where is the implicitly parameterless constructor here)? as makes bflat can't work with any winform application that uses ResourceManager. need to workaround ResourceManager somehow, and legacy projects would suffer.
You'll need to ensure the BinaryFormatter type is fully preserved. Either use root descriptors, or add something like typeof(BinaryFormatter).GetConstructors()
in your Main. This will tell the compiler that it should generate all constructors on BinaryFormatter. Expect more similar problems to follow. I can't help you with every one of them.
System.NotSupportedException : Use of ResourceManager for custom types is disabled. Set the MSBuild Property CustomResourceTypesSupport to true in order to enable it.
this issue seems relevant with https://github.com/dotnet/runtime/issues/51833
and by the way, where can i find the resgen.exe for net7.0 ? i only find a resgen.exe of net framework4.8 on my machine.