Open gao-artur opened 6 months ago
It looks like the compiler is not checking for the existence of System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray
.
@cston does it mean I can just add this as a workaround?
[Intrinsic]
public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)]
internal sealed class IntrinsicAttribute : Attribute
{
}
It seems to work, but I just want to confirm this is the correct way to do that.
@gao-artur, I'm not sure if re-declaring the existing BCL method as extern
is expected to work.
However, in general, it does appear that re-declaring an existing BCL type in source will essentially hide any well-known members of that type that the compiler may depend on that are not also re-declared.
It works, all tests pass, but ReSharper unit tests runner shows the following error. Is it safe to ignore, or can it explode in runtime?
ERROR TestRunner: JetBrains.ReSharper.TestRunner.Adapters.NUnit3.NUnitTestReporter Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. ----> Could not load type 'System.Runtime.CompilerServices.RuntimeHelpers' from assembly 'Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'InitializeArray' has no implementation (no RVA).
@gao-artur you'd have to try out and see.
Version Used: 8.0.204
Steps to Reproduce:
Expected Behavior: Builds successfully
Actual Behavior: Build fails
There is an exception when building with the
dotnet build
commandNote that the content of the
RuntimeHelpers
doesn't matter. The build fails also when the class is empty. When the class is renamed to anything else butRuntimeHelpers
the build succeeds. For the context, the error was encountered when I tried to add support for the array range operator to the Polyfill library that brings newer compiler features to older TFMs.