Skip to content

AllowNullAttribute, bad reference in CoreUtilities #4624

Closed as not planned
Closed as not planned
@wasabii

Description

@wasabii

This is an odd one.

I have a custom process which is trying to parse the assemblies of this project, and generate stubs in another language. As part of that, I've found what might be an error in the assemblies. And I cannot figure out exactly whether it is an error, or some artifact of my process.

Working against the assemblies in the 17.4.0 NuGet package.

Within Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestSessionPool class, there is a method named set_Instance. It's the setter for the static Instance property. Applied to this method is an "AllowNullAttribute". You can see this in code:

https://github.com/microsoft/vstest/blob/f6dc2a108da42736d0a1bb50372c599799d7c322/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/TestSessionPool.cs#L40C14-L40C14

However, within the assembly within the Nuget package, this attribute is of type [Microsoft.TestPlatform.CoreUtilities]System.Diagnostics.CodeAnalysis.AllowNullAttribute. Notice that it's supposed to be located in the Microsoft.TestPlatform.CoreUtilities assemby. It appears as a TypeRef.

The output of ildsm against TestSessionpool:

.method assembly hidebysig specialname static 
        void  set_Instance(class Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestSessionPool 'value') cil managed
{
  .param [1]
  .custom instance void [Microsoft.TestPlatform.CoreUtilities]System.Diagnostics.CodeAnalysis.AllowNullAttribute::.ctor() = ( 01 00 00 00 ) 
  // Code size       9 (0x9)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  volatile.
  IL_0003:  stsfld     class Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestSessionPool modreq([netstandard]System.Runtime.CompilerServices.IsVolatile) Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.TestSessionPool::s_instance
  IL_0008:  ret
} // end of method TestSessionPool::set_Instance

See the attribute applied.

However, Microsoft.TestPlatform.CoreUtilities from the same NuGet package has no such attribute.

I suspect this has something to do with how ya'll are adding these custom attributes for down level assemblies: https://github.com/microsoft/vstest/blob/main/shared/NullableAttributes.cs

But I'm not sure. Not sure what you could be doing wrong.

Maybe what I'm seeing is that the NuGet package has a mix of assemblies? I don't know. I see that you've got NullableAttributes.cs included into CoreUtilities. There's a bunch of IFDEFs. Is it possible that the version of CoreUtilities being distributed is different than the one the CrossPlatEngine is built against?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions