You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dependency Injection using ILEmit is generating additional MSIL nop operations in the DynamicMethod #59624
When inspecting MSIL code generated by Dependency Injection dynamic compilation using ILEmit, everytime there is a ldloca.s instruction, 3 nop operations are also generated.
Configuration
Which version of .NET is the code running on? .NET Framework 4.62
What OS and version, and what distro if applicable? Windows 11 (22000.194)
What is the architecture (x64, x86, ARM, ARM64)? x64
Other information
To reproduce the issue, compile Microsoft.Extensions.DependencyInjection using SAVE_ASSEMBLIES symbol. Then run ServiceProviderILEmitContainerTests.ScopedServiceCanBeResolved and inspect MSIL code in artifacts\bin\Microsoft.Extensions.DependencyInjection.Tests\net462-*\Test*.dll
The ldloca.s instruction expects an 1 byte argument (byte), while we are providing a 4 bytes argument (lockTakenLocal.LocalIndex and resultLocal.LocalIndex are int).
If the opcode parameter requires an argument, the caller must ensure that the argument length matches the length of the declared parameter. Otherwise, results will be unpredictable. For example, if the Emit instruction requires a 2-byte operand and the caller supplies a 4-byte operand, the runtime will emit two additional bytes to the instruction stream. These extra bytes will be Nop instructions.
Activity
allantargino commentedon Sep 26, 2021
The
ldloca.sinstruction expects an 1 byte argument (byte), while we are providing a 4 bytes argument (lockTakenLocal.LocalIndexandresultLocal.LocalIndexareint).runtime/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ILEmit/ILEmitResolverBuilder.cs
Lines 357 to 366 in dff742a
As per documentation, in the remarks section:
Using optimized ILGenerator.Emit function in Dependency Injection
Using optimized ILGenerator.Emit function in Dependency Injection (#5…