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.

[Compatibility issue] VB compiler generates tons of BC36954 errors when I upgrade .NET 6 projects to .NET 7

See original GitHub issue

Version Used: 4.4.0-3.22518.13+7856a68c109b22de70e07580018fec601e944f46

Steps to Reproduce:

The following code reports BC36954 error when I upgrade a .NET 6 project to .NET 7.

Dim s = "123".AsSpan()

https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AbEA3YaAuIUArgHZoAmIA1AD4CSAtgA7T4DOABAMoCe7+GIwCwAKAAKxYBgCWYTgFkIFYhhidxUCAHMoAQxGjOxjVNnzuUxXpmkAFAEoxJl5wAiMxpy4BeTgCIARgAmAGZ/ADoAQXZuZj17JyMTAFFSCh4pMTSMpRU1IA=

Out commercial .NET 6 VB projects have a lot of “Ref Struct” consuming code like this, because many 3rd-party dependencies require it.

The migration to other languages is unacceptable. If we can’t migrate our .NET 6 projects to newer .NET versions smoothly, we have no choice but stop upgrading to newer .NET versions and begin porting these incompatible products to non-.NET platforms.

Diagnostic Id:

BC36954

Expected Behavior: No compilation errors.

Actual Behavior:

error BC36954: Overload resolution failed because no accessible 'AsSpan' can be called:
    Extension method 'Public Function AsSpan() As ReadOnlySpan(Of Char)' defined in 'MemoryExtensions': 'ReadOnlySpan(Of T)' requires compiler feature 'RefStructs', which is not supported by this version of the Visual Basic compiler.
    Extension method 'Public Function AsSpan(start As Integer) As ReadOnlySpan(Of Char)' defined in 'MemoryExtensions': 'ReadOnlySpan(Of T)' requires compiler feature 'RefStructs', which is not supported by this version of the Visual Basic compiler.
    Extension method 'Public Function AsSpan(start As Integer, length As Integer) As ReadOnlySpan(Of Char)' defined in 'MemoryExtensions': 'ReadOnlySpan(Of T)' requires compiler feature 'RefStructs', which is not supported by this version of the Visual Basic compiler.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
jcouvcommented, Nov 14, 2022

@Nukepayload2 From discussion with the team, this API pattern (passing ref structs through) was meant to be supported. I’ll get started to fix this regression. Sorry about that.

1reaction
jcouvcommented, Nov 13, 2022

@Nukepayload2 These Span APIs should have been inaccessible from VB in .NET 6 already. A mechanism was in place (attribute [Obsolete("Types with embedded references are not supported in this version of your compiler.")] emitted on ref structs) to prevent compilers without ref sruct support from using types they didn’t understand/support.

This mechanism was imperfect as the following example shows (compiled against .NET 6 TFM): image

In .NET 7, this mechanism was strengthened, resulting in the message you’re seing: “… requires compiler feature ‘RefStructs’, which is not supported by this version of the Visual Basic compiler.”.

Tagging @333fred @jaredpar @AlekseyTs in case anything to add or if they can think of a possible mitigation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking changes in .NET 7
This article indicates whether each breaking change is binary compatible or source compatible: Binary compatible - Existing binaries will load ...
Read more >
Errors after upgrading app from framework 6 to 7. #11217
NET Runtime from net6.0 to net 7.0 in the project file I get four times this error: NU1105 Unable to read project information...
Read more >
Migrate from ASP.NET Core 6.0 to 7.0
This article explains how to update an existing ASP.NET Core 6.0 project to ASP.NET Core 7.0. Prerequisites. Visual Studio; Visual Studio Code ...
Read more >
How to configure a Visual Studio 2022 solution to compile ...
I just would like to have a single .NET 7 solution on which I can compile the same code to generate dlls for...
Read more >
.NET core vs .NET framework
Wondering about the difference between .NET Core & .NET Framework? Here's a quick guide on how to pick the right runtime environment for...
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