dotnet / standard

This repo is building the .NET Standard
3.07k stars 428 forks source link

MethodImplOptions.AggressiveOptimization is nmot available in .NET Standard 2.1 #1758

Closed msedi closed 2 years ago

msedi commented 4 years ago

Most of our components are developed in .NET Standard 2.0. With the advent of .NET Core 3.0 MethodImplOptions.AggressiveOptimization was introduced. So we have decided to swithc to .NET Standard 2.1 and were assuming the AggressiveOptimization is available too, but it isn't.

  1. Is there any reason why this is so?
  2. What would be the impact if it's not available?
  3. Is there a workaround to use it?
Dotnet-GitSync-Bot commented 4 years ago

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

0xd4d commented 4 years ago

Is there a workaround to use it?

namespace System.Reflection {
static class MethodImplAttributes2 {
    public const MethodImplAttributes AggressiveOptimization =
        (MethodImplAttributes)0x0200;
}
}
msedi commented 4 years ago

@0xd4d: Thanks, I was assuming that this could to the trick. Did you try? The last time I was doing this was FileOptions. The constructor of FileStream checked the validity and threw an InvalidEnumException.

terrajobst commented 2 years ago

Closing as not planned, as .NET Standard is considered complete.

@0xd4d: Thanks, I was assuming that this could to the trick. Did you try? The last time I was doing this was FileOptions. The constructor of FileStream checked the validity and threw an InvalidEnumException.

This attribute an enum will be interpreted by the runtime. I believe the runtime will simply ignore unknown bits, but I think this puts you in undefined behavior territory.