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

FieldAccessException when using Blazor and generic async methods #526

Closed
GeertvanHorrik opened this issue May 20, 2023 · 4 comments · Fixed by #527
Closed

FieldAccessException when using Blazor and generic async methods #526

GeertvanHorrik opened this issue May 20, 2023 · 4 comments · Fixed by #527
Assignees
Labels
Milestone

Comments

@GeertvanHorrik
Copy link
Member

When trying to trace some methods in Blazor (WASM) in overridden methods, I get a "FieldAccessException".

NetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer ]  Unhandled exception rendering component:  Field `<GetUserAsync>d__2`1:methodTimerMessage' is inaccessible from method `MyApp.UI.Services.MyAppUserManager/<GetUserAsync>d__2`1<Blorc.OpenIdConnect.User`1<Blorc.OpenIdConnect.Profile>>:StopMethodTimerStopwatch ()'
 
 System.FieldAccessException: Field `<GetUserAsync>d__2`1:methodTimerMessage' is inaccessible from method `MyApp.UI.Services.MyAppUserManager/<GetUserAsync>d__2`1<Blorc.OpenIdConnect.User`1<Blorc.OpenIdConnect.Profile>>:StopMethodTimerStopwatch ()'

I am trying to create a repro with unit tests for this.

@GeertvanHorrik GeertvanHorrik self-assigned this May 20, 2023
@GeertvanHorrik
Copy link
Member Author

When investigating the IL, the methodTimerMessage seems to cast the current class where the others are not doing this:

private void StopMethodTimerStopwatch()
{
	if (<>1__state == -2 && methodTimerStopwatch.IsRunning)
	{
		methodTimerStopwatch.Stop();
		methodTimerMessage = null;
		MethodTimeLogger.Log(MethodBase.GetMethodFromHandle((RuntimeMethodHandle)/*OpCode not supported: LdMemberToken*/, typeof(MyAppUserManager).TypeHandle), methodTimerStopwatch.ElapsedMilliseconds, ((<GetUserAsync>d__2<>)(object)this).methodTimerMessage);
	}
}

Also interesting to see that the methodTimerMessage is set to null first.

@GeertvanHorrik
Copy link
Member Author

Differences where the methodTimerStopwatch uses the correct generic class, where methodTimerMessage does not.

ldfld MyApp.Services.MyAppUserManager/'<GetUserAsync>d__2`1'<!TUser>::methodTimerStopwatch
ldfld MyApp.Services.MyAppUserManager/'<GetUserAsync>d__2`1'::methodTimerMessage

@GeertvanHorrik
Copy link
Member Author

I think the issue is the usage of the definition, not the reference, of the field.

@GeertvanHorrik GeertvanHorrik changed the title FieldAccessException when using Blazor and generic overridden methods FieldAccessException when using Blazor and generic async methods May 20, 2023
@GeertvanHorrik
Copy link
Member Author

Tested the fix, the error is gone now.

@SimonCropp SimonCropp added this to the 3.2.2 milestone May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants