No intellisense in Razor Views (ArgumentException in VS2015)

De repente, un día, vemos que el intellisense ha desaparecido de nuestras vistas en Razor, al abrirlas un mensaje nos indica que consultemos el fichero ActivityLog.xml en el que encontramos esto:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.ArgumentException: Item has already been added. Key in dictionary: ‘RazorSupportedRuntimeVersion’ Key being added: ‘RazorSupportedRuntimeVersion’ at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) at System.Collections.Specialized.HybridDictionary.Add(Object key, Object value) at Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object key, Object property) at Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer textBuffer) at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version& razorVersion) at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer) — End of inner exception stack trace — at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at Microsoft.Html.Editor.ContainedLanguage.Common.ContainedCodeErrorTaggerProvider`1.CreateTagger[T](ITextBuffer textBuffer) at Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.GatherTaggers(ITextBuffer textBuffer)

Es un bug de Visual Studio 2015 en todas sus versiones y en el que ya está trabajando MS, pero de momento la solución es borrar la caché de VS:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /ResetUserData

🙂

Anuncios

Binding Complex Types in MVC5

A la hora de editar tipos complejos de un ViewModel, olvídate de usar el “foreach” tal que:

public ViewModel()
{
Plantillas = new List<Informe>();
}

VIEW:

@foreach (var plantilla in @Model.Plantillas)
{

@Html.HiddenFor(x => plantilla.Id)

@(Html.EditorFor(x => plantilla.Orden))

}

De este modo al controlador no le llega nada, la solución sería usar un “for” :-):

@for(var i=0;i<Model.Plantillas.Count;i++)
{
@Html.HiddenFor(x => Model.Plantillas[i].Id)
@(Html.EditorFor(x => Model.Plantillas[i].Orden))

}

Pero en MVC4 ni por esas: http://guysherman.com/2013/04/12/asp-net-mvc4-binding-to-a-list-of-complex-types/

Este artículo actualiza a https://pdcuevas.wordpress.com/2015/02/20/editing-a-variable-length-list-with-aspnet-mvc/