question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.Numerics.Vectors reference assembly has reordered fields compared to runtime implementation

See original GitHub issue

Description

We have a tool that generates some code based on a C# reference file. This file uses System.Numerics.Vectors for its math types. When we parse the Vector4 and Quaternion structs, Roslyn returns the components in WXYZ order. We thought this looked strange and maybe a bug on our side at first, because on C++ WindowsNumerics.h uses XYZW, but indeed it seems it’s not us and there’s a discrepancy here (I’ll take Quaternion as example):

The actual layout is important for us to decide if we generate some code for a blittable type or not (we assume Vector4 and Quaternion are, but previously we couldn’t consider them blittable because we used WXYZ internally whereas they are projected in C++ in WindowsNumerics.h as XYZW). As @tannergooding pointed on another project comment we assume that the layout of those types is Sequential (should be the default for structs) and will not change since they’re intrinsics.

Configuration

.NET 5.0 (but was already in .NET Core 3.x) Windows 10 x64 (though it shouldn’t matter)

Regression?

Probably not.

Other information

Copying some internal analysis from @tannergooding for reference (and tagging @ericstj as requested):

These are autogenerated by GenAPI https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.GenAPI/Program.cs which uses CCI. At least browsing through the code that writes the fields (https://github.com/dotnet/arcade/blob/4873d157a8f34f8cc7e28b3f9938b32c642ef542/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.cs#L182-L187) and which traverses the fields (https://github.com/dotnet/arcade/blob/4873d157a8f34f8cc7e28b3f9938b32c642ef542/src/Microsoft.Cci.Extensions/Writers/CSharp/CSharpWriter.cs#L155) it looks like we are reordering the members here: https://github.com/dotnet/arcade/blob/4873d157a8f34f8cc7e28b3f9938b32c642ef542/src/Microsoft.Cci.Extensions/Writers/CSharp/CSharpWriter.cs#L188 and that is likely causing the difference.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ericstjcommented, Jul 6, 2022

@tannergooding no issue fixing manually for .NET 7. I suspect the GenAPI change for this isn’t too difficult so it won’t be much in the way of dead code. @ViktorHofer are you tracking this for a rule in the new API compat as well? cc @smasher164

1reaction
tannergoodingcommented, Dec 8, 2020

LayoutKind.Explicit probably also needs to be considered, but I don’t think we have any such types today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Numerics.Vectors reference assembly has ...
Description We have a tool that generates some code based on a C# reference file. This file uses System.Numerics.Vectors for its math types....
Read more >
Conflicts between different version of 'System.Numeric. ...
I am getting the following error when trying to "Archive for Publish" my iOS build - "Conflicts between different version of 'System.Numeric ......
Read more >
Could not load file or assembly System.Numeric.Vectors in ...
I think either trying to install the System.Numerics.Vector package as Jon suggested, or maybe update to net472 or .
Read more >
https://raw.githubusercontent.com/dotnet/samples/m...
Vectors reference *Steps to Reproduce*: 1. docker run -it --rm microsoft/dotnet:2.0-sdk 2. ... FileLoadException: Could not load file or assembly 'System.
Read more >
LLVM Language Reference Manual
This document is a reference manual for the LLVM assembly language. LLVM is a Static Single Assignment (SSA) based representation that provides type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found