Code inspection: Accessing managed methods is not supported
This inspection identifies calls to managed methods (typically methods belonging to System.Object or System.ValueType) within a context compiled by the Burst compiler. Since Burst targets a high-performance, restricted subset of C#, it does not support most methods that involve boxing, reference types, or other managed behaviors.
How it works
The analyzer monitors method calls (IInvocationExpression) within Burst-compiled code. It determines if a call is prohibited based on the following rules:
Prohibited: Methods belonging directly to
System.Object(such asToString,GetType,Equals) orSystem.ValueTypeare generally prohibited because they often require boxing or interact with the managed heap.Exception (GetHashCode): In a struct, calling
GetHashCodeis allowed only if it doesn't cause boxing. Callingbase.GetHashCode()in a struct that overrides it is still problematic if it reaches the managed implementation.Overrides: If a struct overrides a method like
Equals(object), calling it inside Burst is prohibited because theobjectparameter itself forces boxing.
This inspection only triggers if the code is within a method or job marked with the [BurstCompile] attribute.
Example
In this example, the ToString() and GetType() methods are called on an integer within a Burst-compiled job. These calls are not supported and will be flagged.