Mvc: Edit and Continue with Windows host to Linux container

Created on 30 Jul 2018  Â·  6Comments  Â·  Source: aspnet/Mvc

Moved from https://github.com/aspnet/Docs/issues/7707. See that issue for more context. Originally opened by @djhmateer. /cc: @mkArtakMSFT

I've been unsuccessful getting Edit and Continue mentioned above working.

Windows 10 host to Linux container using ASP.NET Core 2.1 being able to update a .cshtml and see the changes in the browser (after doing F5 in browser) without doing a Ctrl F5 in Visual Studio.

Details of what I did are in: https://stackoverflow.com/questions/51441893/visual-studio-2017-docker-edit-and-continue


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

3 - Done 1 - Required bug S

Most helpful comment

@djhmateer, you could try using a custom implementation of IActionDescriptorCollectionProvider as a workaround until we've addressed this in the framework. Here's what you'd do:

C# services.AddSingleton<IActionDescriptorCollectionProvider, PollingActionDescriptorCollectionProvider>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

I was able to verify locally that this addressed the issue you were seeing.

All 6 comments

The issue is an side effect of the way ActionDescriptorCollectionProvider listens for changes. On a Linux based docker container, the file system watching is passive i.e. IChangeToken.ActiveChangeCallbacks = false. The ChangeToken.OnChange pattern that we rely in here does not account for passive IChangeToken instances. A possible fix for this would be to stash the result of GetCompositeChangeToken() and query if it's different. Alternatively, we could modify ActionDescriptorCollectionProvider.ActionDescriptors to always update the collection on demand. E.g.

```C#
public ActionDescriptorCollection ActionDescriptors
{
get
{
if (_collection == null || _changeToken.HasChanged)
{
UpdateCollection();
_changeToken = GetChangeToken();
}

    return _collection;
}

}
```

@djhmateer, you could try using a custom implementation of IActionDescriptorCollectionProvider as a workaround until we've addressed this in the framework. Here's what you'd do:

C# services.AddSingleton<IActionDescriptorCollectionProvider, PollingActionDescriptorCollectionProvider>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

I was able to verify locally that this addressed the issue you were seeing.

Many thanks @pranavkm. The https://gist.github.com/pranavkm/10759ca15205c49e94ecd8739ae3a44a link gave me a compile error: Method must have a return type. I'm not quite sure how to resolve.

public ActionDescriptorCollectionProvider1(
IEnumerable actionDescriptorProviders,
IEnumerable

@djhmateer Looks to me like that should be a constructor. Try the following constructor signature:

public PollingActionDescriptorCollectionProvider (
            IEnumerable<IActionDescriptorProvider> actionDescriptorProviders,
            IEnumerable<IActionDescriptorChangeProvider> actionDescriptorChangeProviders)

Yup, @scottaddie got it right. Fixed the gist with the correct type name.

@scottaddie and @pranavkm much appreciated - yes I can confirm that this works. Very interesting and thank you for the explanation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nefcanto picture nefcanto  Â·  3Comments

CezaryRynkowski picture CezaryRynkowski  Â·  4Comments

DamianEdwards picture DamianEdwards  Â·  3Comments

hikalkan picture hikalkan  Â·  4Comments

saf-itpro picture saf-itpro  Â·  3Comments