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

Running dotnet watch with a EditForm component with @bind-Value breaks with error "condition `<disabled>' not met" #33152

Closed
ShoarW opened this issue May 31, 2021 · 8 comments · Fixed by #33263
Assignees
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI bug This issue describes a behavior which is not expected - a bug. feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Milestone

Comments

@ShoarW
Copy link

ShoarW commented May 31, 2021

Running my project I've noticed that the hot reload will exit/crash if it finds a with a @bind-Value inside of it.

Files looks like

<EditForm Model="@Login" OnValidSubmit="HandleValidSubmit">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <InputText @bind-Value="Login.Email" />
    <InputText @bind-Value="Login.Password" />
    <button class="btn btn btn-lg btn-primary" type="submit">Sign in One</button>
</EditForm>

@code {
    private LoginResult Login = new LoginResult();
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount += 30;
    }

    private void HandleValidSubmit()
    {
        Navigation.NavigateTo("/");
    }
}

Crashes with when navigating to the page

* Assertion at /__w/1/s/src/mono/mono/metadata/assembly.c:1373, condition `<disabled>' not met
dotnet.6.0.0-preview.4.21253.7.js:1:18291

Downgrading the preview packages to Preview 3 (not the SDK) will not crash the application.

I have created a reproduction of the issue here - You will need Preview4 and latest Visual Studio Preview

https://github.com/ShoarW/BlazorHotReloadPreview4

@pranavkm pranavkm added area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-hot-reload This issue is related to the Hot Reload feaature and removed area-razor.tooling feature-razor.vs feature-hot-reload This issue is related to the Hot Reload feaature labels Jun 1, 2021
@mkArtakMSFT mkArtakMSFT added the feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) label Jun 1, 2021
@mkArtakMSFT
Copy link
Member

@lambdageek do you have a separate issue tracking this already?

@lambdageek
Copy link
Member

Very strange: the assert is hit when you start the app via dotnet watch and navigate to the Counter page - you don't need to edit any code.
That assertion is hit if a managed AppDomain.CurrentDomain.AssemblyLoad event throws an unhandled exception.
Does the hot reload agent hook up to that event? /cc @pranavkm

@pranavkm
Copy link
Contributor

pranavkm commented Jun 1, 2021

It does. That sounds like a bug in Blazor's hot reload agent. I'll look at this further.

@ghost
Copy link

ghost commented Jun 3, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@pranavkm
Copy link
Contributor

pranavkm commented Jun 3, 2021

I should have a fix out for this soon. The exception is triggered because a "Anonymously Hosted DynamicMethods Assembly" is loaded and accessing it's Module property throws:

System.NullReferenceException: Object reference not set to an instance of an object.
blazor.webassembly.js:1    at System.Reflection.Emit.AssemblyBuilder.GetModules(Boolean getResourceModules) in System.Private.CoreLib.dll:token 0x6004ca7+0x0
blazor.webassembly.js:1    at System.Reflection.Emit.AssemblyBuilder.GetLoadedModules(Boolean getResourceModules) in System.Private.CoreLib.dll:token 0x6004caa+0x0
blazor.webassembly.js:1    at System.Reflection.Assembly.get_Modules() in System.Private.CoreLib.dll:token 0x6004778+0x0

We can do a better job handling this case, but I'm curious if you happen to know what could be loading that particular assembly? @lambdageek?

@pranavkm
Copy link
Contributor

pranavkm commented Jun 3, 2021

I have a targeted fix that prevents the exception from AssemblyLoad event. Once that is resolved you run in to dotnet/runtime#51855.

pranavkm added a commit that referenced this issue Jun 3, 2021
Accessing Assembly.Modules for arbitrary loaded assemblies may throw which currently results
in the hot reload agent to produce an unhandled exception crashing the app. This change attempts
to perform a targeted fix for that issue.

Fixes #33152
@pranavkm pranavkm added bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Jun 3, 2021
pranavkm added a commit that referenced this issue Jun 4, 2021
…3263)

Accessing Assembly.Modules for arbitrary loaded assemblies may throw which currently results
in the hot reload agent to produce an unhandled exception crashing the app. This change attempts
to perform a targeted fix for that issue.

Fixes #33152
@lambdageek
Copy link
Member

lambdageek commented Jun 4, 2021

I should have a fix out for this soon. The exception is triggered because a "Anonymously Hosted DynamicMethods Assembly" is loaded and accessing it's Module property throws:

System.NullReferenceException: Object reference not set to an instance of an object.
blazor.webassembly.js:1    at System.Reflection.Emit.AssemblyBuilder.GetModules(Boolean getResourceModules) in System.Private.CoreLib.dll:token 0x6004ca7+0x0
blazor.webassembly.js:1    at System.Reflection.Emit.AssemblyBuilder.GetLoadedModules(Boolean getResourceModules) in System.Private.CoreLib.dll:token 0x6004caa+0x0
blazor.webassembly.js:1    at System.Reflection.Assembly.get_Modules() in System.Private.CoreLib.dll:token 0x6004778+0x0

We can do a better job handling this case, but I'm curious if you happen to know what could be loading that particular assembly? @lambdageek?

@pranavkm Those modules are created by new DynamicMethod (string, Type, Type[]) (and probably a few other overloads).

I just tried this in a console app:

using System;
using System.Reflection;
using System.Reflection.Emit;

namespace q
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
	    var d = new DynamicMethod ("ababa", typeof(void), new Type[]{ });


	    foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
		foreach (var m in a.Modules) {
                    Console.WriteLine ($"{a.FullName}: module {m}, {m.ModuleVersionId}");
		}
	    }
        }
    }
}

And on both CoreCLR and Mono it prints out:

...
Anonymously Hosted DynamicMethods Assembly: module RefEmit_InMemoryManifestModule, 96267b54-2435-47eb-917a-680e98cf5815

So it doesn't seem like there's an obvious bug in System.Reflection.Emit.AssemblyBuilder.GetModules.

Is the IL trimmer running for this project? Maybe it is removing some reflection enumeration code that the hot reload agent depends on?

@pranavkm
Copy link
Contributor

pranavkm commented Jun 4, 2021

No trimmer's running during development. More specifically, nothing in the code explicitly creates and loads a dynamically loaded assembly. Perhaps the presence of the anonymous lambda causes one to load and that has different semantics?

@ghost ghost locked as resolved and limited conversation to collaborators Jul 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI bug This issue describes a behavior which is not expected - a bug. feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants