Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipped internal properties on InvokeAsync<T> calls #42768

Closed
1 task done
msynk opened this issue Jul 17, 2022 · 3 comments
Closed
1 task done

Skipped internal properties on InvokeAsync<T> calls #42768

msynk opened this issue Jul 17, 2022 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-jsinterop This issue is related to JSInterop in Blazor ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@msynk
Copy link

msynk commented Jul 17, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The internal properties are getting skipped/ignored on calls to InvokeAsync of JS interop calls.

for example:

public class Bounds
{
    public double Width { get; set; }
    internal double Height { get; set; }
}
function getBoundingClientRect(element) {
    const bounds = element.getBoundingClientRect();
    return {
        width: bounds.width,
        height: bounds.height
    };
}

you can see the problem in the result of the following line:

var bounds = await js.InvokeAsync<Bounds>("getBoundingClientRect", element);

It's probably because of the limitations of the STJ (discussed here: dotnet/runtime#31511) or something similar, but to be more clear it is a blocking issue for assemblies that don't want to expose their internal types to the outside world.
Btw, I can bypass this issue by making the type itself Internal and changing the properties access modifier to public.

Expected Behavior

The internal properties should receive their corresponding values from js interop calls.

Steps To Reproduce

you can see this problem in action in this repo:

https://github.com/msynk/blazor-internal-props-skip-invokeasync

it has both Blazor Server and Wasm.

Exceptions (if any)

No response

.NET Version

6.0.302

Anything else?

No response

@msynk msynk changed the title Skipped Internal properties on InvokeAsync<T> calls Skipped internal properties on InvokeAsync<T> calls Jul 17, 2022
@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-blazor-jsinterop This issue is related to JSInterop in Blazor labels Jul 18, 2022
@javiercn
Copy link
Member

@msynk thanks for contacting us.

This is by design. The data gets serialized under the hood using System.Text.Json and that does not serialize internal properties. You can write a custom converter to change that. In addition to that, if you trim the app during publish and the property is not used elsewhere, the trimmer might not infer its usage and remove it.

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Jul 18, 2022
@ghost ghost added the Status: Resolved label Jul 18, 2022
@msynk
Copy link
Author

msynk commented Jul 18, 2022

@msynk thanks for contacting us.

This is by design. The data gets serialized under the hood using System.Text.Json and that does not serialize internal properties. You can write a custom converter to change that. In addition to that, if you trim the app during publish and the property is not used elsewhere, the trimmer might not infer its usage and remove it.

@javiercn thank you for your response.

I've already mentioned in the issue's body that it might be because of the limitation of the STJ and the GitHub issue discussing this limitation, and also a possible workaround (making the type itself internal).
it seems you didn't read the issue completely and missed that paragraph 😕

the feature required to resolve such a problem is planned for dotnet 8.0 now, so we need to wait until next year :(
meanwhile, we need to stick to the converter solution or make only the type internal.

@ghost
Copy link

ghost commented Jul 19, 2022

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jul 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-jsinterop This issue is related to JSInterop in Blazor ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants