Skip to content

Immutable C# "Init-Only" Records "should just work" **WHEN CONSUMED** by VB... but the opposite appears to be true. #49469

@DualBrain

Description

@DualBrain

I was in the middle of demonstrating how you shouldn’t be afraid to “mix” languages and, thus, take advantage of new time saving features that have been recently introduced. The scenario that came to mind (adhoc) was leveraging “records” by creating a simple class library in C# and create several records that could then be utilized (with all the benefits – at least that was the thought) that records brings with equality, immutability, etc.

The way they are being demo'd during the launch and written about in pretty much every blog post that I'm finding... if these classes are made visible/public in libraries in the manner being demo'd... VisualBasic will suffer big time as I see it. If it's adopted heavily by library makers; we are in serious trouble.

As I currently see it, there's no way to initialize this immutable object (record). If people go gung-ho with utilizing this as I'd expect you would encourage; we will have no way to initialize these things (unless I’m completely missing something). That's a HUGE problem!

Version Used:

.NET 5, VS 16.8.1

Steps to Reproduce:

Create a simple .NET 5 C# class library project with a public record:

public record Something {public int ID { get; init; }}

Create a .NET 5 VB console project, add a reference to the C# project.

Attempt to consume the record:

Dim c = New Something With {.ID = 1}

Expected Behavior:

Ability to initialize the record using the, what I would think would be, valid/expected code

Actual Behavior:

Unable to initialize the record due to the following (rather confusing) error:

'ID' has a return type that is not supported or parameter types that are not supported.

TAG: @KathleenDollard

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions