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

Blazor IJSInProcessObjectReference.Invoke is attributed with RequiresUnreferencedCode #58712

Open
yueyinqiu opened this issue Oct 30, 2024 · 1 comment · May be fixed by #58713
Open

Blazor IJSInProcessObjectReference.Invoke is attributed with RequiresUnreferencedCode #58712

yueyinqiu opened this issue Oct 30, 2024 · 1 comment · May be fixed by #58713
Labels
area-blazor Includes: Blazor, Razor Components
Milestone

Comments

@yueyinqiu
Copy link

Hello, I have recently found that IJSInProcessObjectReference.Invoke<TValue> is attributed under [RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")] here.

However we have add [DynamicallyAccessedMembers(JsonSerialized)] for its TValue, so it seems unnecessary to use RequiresUnreferencedCode?

And we didn't do that in IJSObjectReference, so I believe it should be a mistake.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Oct 30, 2024
@yueyinqiu yueyinqiu changed the title Blazor should IJSInProcessObjectReference.Invoke be attributed with RequiresUnreferencedCode? Blazor IJSInProcessObjectReference.Invoke is attributed with RequiresUnreferencedCode Oct 30, 2024
@yueyinqiu yueyinqiu linked a pull request Oct 30, 2024 that will close this issue
4 tasks
@javiercn
Copy link
Member

@yueyinqiu thanks for contacting us.

I'm not sure what the right thing to do here is. From what I know, I believe that both are required. The challenge with DynamicallyAccessedMembers is that it only "preserves" the first level, and not the entire "object graph".

You could say that DynamicallyAccessedMembers is then not enough to tell the linker what it needs to preserve, and it also only affects the return value itself, and not any other parameter that gets passed in.

RequiresUnreferencedCode provides a broader warning that when calling that API, you might need to ensure other types are preserved.

Based on that, I think the right thing to do would be to annotate the other APIs with [RequiresUnreferencedCode] too. I'm not sure why it wasn't done.

@javiercn javiercn added this to the Backlog milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants