Search code examples
wpfxamlexceptiondesigner

WPF XAML Designer Crashes


I have a Window, the only thing it has in it is a TextBlock. I'm getting ridiculous designer exceptions that is crashing the designer every time I change anything. I started removing everything trying to find the culprit of this error. And now I have nothing left, but the designer keeps throwing exceptions.

<Window x:Class="Company.Product.Views.About"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="397"
    Width="658">
<TextBlock>Test</TextBlock>
</Window>

code behind:

/// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class About : Window
    {
        public About()
        {
            InitializeComponent();
        }
    }

If I "Click here to reload the designer" the window shows up, but then if I modify the text of TextBlock, I get an exception

Exception

System.ArgumentNullException
Value cannot be null.
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(Type type)
   at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.TryGetRuntimeType()
   at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeType(Type type)
   at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkProvider.GetRuntimeType(Type reflectionType)
   at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.VsReflectionResolver.GetRuntimeType(Type reflectionType)
   at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.CachingReflectionResolver.GetRuntimeType(Type reflectionType)
   at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.Microsoft.Windows.Design.Metadata.IReflectionResolver.GetRuntimeType(Type reflectionType)
   at MS.Internal.Metadata.ClrType.get_RuntimeMember()
   at MS.Internal.Metadata.ClrMember`1.Microsoft.Windows.Design.Metadata.Reflection.IReflectionMember.get_MemberInfo()
   at MS.Internal.Metadata.ClrType.Equals(Object obj)
   at System.Collections.Generic.ObjectEqualityComparer`1.Equals(T x, T y)
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.<>c__DisplayClass5.<FindAttachableProperties>b__4(ITypeMetadata walkType)
   at MS.Internal.Design.Metadata.Xaml.XamlType.<GetAllAttachableProperties>d__7.MoveNext()
   at MS.Internal.Design.Metadata.Xaml.XamlType.<FindAttachableProperties>d__0.MoveNext()
   at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.<FindAttachableProperties>d__7.MoveNext()
   at MS.Internal.VirtualModel.VirtualModelPropertyCollection.<GetUncachedProperties>d__0.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MS.Internal.VirtualModel.VirtualModelPropertyCollection.GetEnumerator()
   at MS.Internal.Designer.PropertyEditing.Model.Properties.ModelPropertyMerger.<GetFirstProperties>d__0.MoveNext()
   at MS.Internal.Designer.PropertyEditing.Views.PropertyEntryReader.RedraftEntries(IPropertyViewManager viewManager, Selection selection, Boolean attachedOnly, IEventCodeBehindProxy eventCodeBehindProxy, CategoryList categoryList)
   at MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(Selection selection, Boolean attachedOnly, IEntryReader entryReader)
   at MS.Internal.Designer.PropertyEditing.PropertyInspector.RefreshPropertyList(Boolean attachedOnly)
   at MS.Internal.Designer.PropertyEditing.PropertyInspector.OnSelectionChangedIdle()
   at MS.Internal.Designer.PropertyEditing.PropertyInspector.OnSelectionChangedIdleForced(Object sender, EventArgs e)
   at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

I'm left with no way to debug what the problem is, and frankly I getting frustrated considering there should be nothing on this simple example that should be crashing the designer. Any ideas?

Update

After re-installing and updating and reloading, problem went away temporarily. Now the problem is back again.

Actually, I'm not sure if the problem ever went away. I've also tried VS safe mode, /resetsettings, and deleting my several cache folders in the VS folder.

Update2

Here's a screencast which shows the problem Excuse my resolution, I'm in portrait.


Solution

  • Alright, I believe I fixed the problem. I created a new executable project, copied everything from the old one to the new one and tried deleting or adding items one by one to figure out what was special about that project.

    It turns out that I'm referencing several 3rd party libraries by Actipro. Earlier, I had upgraded the libraries and copied them to a /lib folder and referenced them from there. One of the references was forgotten though, and I believe it was targetting an older version in the GAC instead of the /lib folder. I think I basically had two different versions of Actipro's shared library referenced.

    After removing the erroneous reference to the old build for the 3rd party library, and updating it to the proper version as the others, the problem has gone away

    The strange thing, is that the Window in question used no component or anything from that library. It may be that it was trying to resolve the Attached Properties inside the library (from the stack trace).