C#C
C#3y ago
swagrid

❔ Roslyn analyzer test project can't compile `where T : unmanaged` type constraint

I've made a roslyn analyzer for some marshaling stuff. In my test project I try to analyze this source code:
    struct FooTest<T> where T : unmanaged
    {
        T good;
    }

but when I try to compile this code I get:
error CS0518: Predefined type 'System.Runtime.CompilerServices.IsUnmanagedAttribute' is not defined or imported

Why the error? I know there are similar issues with IsExternalInit, but my test project runs on .net 6.0 and the test code above is compiled with the latest C# version. AFAIK, the unmanaged constrain came with C# 7.3 / .net core 2.0.
Was this page helpful?