2

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.

Alan
  • 7,875
  • 1
  • 28
  • 48
  • 1
    Can you show your code behind file contents, as well? Also -w hat version of VS? – Reed Copsey Dec 17 '12 at 20:56
  • @ReedCopsey VS2010 SP1 and I took everything except the InitializeComponent() call out of my code behind – Alan Dec 17 '12 at 21:01
  • Yeah - is it subclassing `Window`, or a custom class (in the code behind)? – Reed Copsey Dec 17 '12 at 21:02
  • @ReedCopsey Window. I checked the Namespaces (since I removed them here in this example to remain anonymous) and they match in the XAML and the Code behind also. See my edit, I added code behind – Alan Dec 17 '12 at 21:04
  • @Alan is this a 64 bit computer? Is the solution compiled as x64? – Blachshma Dec 17 '12 at 21:04
  • @Blachshma This is 64 bit machine, and I'm a bit confused since this is a Prism app with a lot of different DLL modules. I tried changing it to "Any Cpu" it was on "x86" 32-bit... This particular window is in the main .EXE project though. – Alan Dec 17 '12 at 21:05
  • 1
    @Alan And when setting it to x86 it also happens? – Blachshma Dec 17 '12 at 21:06
  • @Blachshma I went to **project properties** of the main .exe project which includes this Window. I changed to x86, recompiled, same result. I've also tried x64, same result, and Any CPU. Doesn't seem to help. – Alan Dec 17 '12 at 21:08
  • Did you realize that in the time it takes you to try to make the crappy VS designer work you could have had a spectacular development in XAML alone with no need for a stupid designer.. ? – Federico Berasategui Dec 17 '12 at 21:10
  • @HighCore I still need the designer to work. First of all I don't like exceptions in my face. Second, How do you know what your XAML code looks like? I write my XAML, but I need to see what it looks like. – Alan Dec 17 '12 at 21:11
  • What I don't understand is why the designer is giving me grief on this project?! I have had it showing correctly before just fine, and I create a new simple project and it works (of course). So what is it about this project that is causing it to be a complete POS? – Alan Dec 17 '12 at 21:12
  • XAMLPad. Expression Blend. F5. Getting used to it. When you learn XAML you already know what it will look like before you even see it. – Federico Berasategui Dec 17 '12 at 21:13
  • 1
    @HighCore You can't be serious.. that you write code 100% no flaws, etc. Pressing F5 and navigating to each view to see what it looks like is hardly efficient. I have DesignTimeData and XAML with designer preview working fine before in other views, now this view gives me random exceptions. – Alan Dec 17 '12 at 21:14
  • 1
    Did you try it in blend? Also, for cosmetic fixes (such as adding margins or alignments etc) I use snoop to modify the UI in runtime and when I get what I want I make the same changes in the XAML. which is faster that waiting 8 hours for the VS designer to load every change. – Federico Berasategui Dec 17 '12 at 21:16
  • @HighCore it is working in Blend, I think, but I'm not really ready or able to incorporate Blend into our development. I understand Blend can be a great tool, but I still need VS to work. It's probably possible this is some sort of VS bug and maybe it still has to do with 32/64 bit. Not sure. – Alan Dec 17 '12 at 21:20
  • 1
    Something got corrupt. Try clean and rebuild. If u delete and start fresh Windows does it work? – paparazzo Dec 17 '12 at 21:22
  • @Blam Cleaned, closed VS, Shutdown and installed 58 updated, restarted, rebuild, same issue. I'm going to look at configuring all the projects to same CPU arch. – Alan Dec 17 '12 at 21:43
  • @Blachshma This only happens in my main application project (exe). I have Views in my DLLs (Prism modules) and if I modify those the designer works. I created a new blank window in my main project, and it fails. I tried setting all projects to X86 and it didn't make a difference. – Alan Dec 17 '12 at 21:50
  • After re-installing and updating and reloading, problem went away temporarily. Now the problem is back again. Weird. – Alan Dec 17 '12 at 22:18
  • @Alan: I had a similar problem with one of the Prism libraries. It was "Interaction" or "Interception". Sorry I cant remember specifically right now. There is a dependency from one of these dlls that is not available in the client framework (if thats what you're targeting). This caused all views to fail with the same designer exception. I think there was a bug filed as well. Try and eliminate all prism dlls you're not explicitly using. Ill try and find out what it was exactly. – bic Dec 17 '12 at 22:28
  • @Alan: sorry, it seems I mis-remembered the details of that bug I had. it would seem its a different stack trace altogether. – bic Dec 17 '12 at 22:46
  • @bic I had to convert my project to full 4 framework earlier anyhow, so if it were client profile related that would not be it. Thanks though. – Alan Dec 17 '12 at 22:46
  • @Alan: Yeah, I got that point wrong initially, sorry it was a long time ago. It was to do with Prism specifically referencing Blend dlls instead of the ones in the 'bin' directory. heres the link which may be helpful. This btw was the cause of my designer crashes so it may be related. http://stackoverflow.com/questions/9650778/prism-assembly-reference-failure-system-windows-interactivity – bic Dec 17 '12 at 22:53

2 Answers2

1

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).

Alan
  • 7,875
  • 1
  • 28
  • 48
0

Try to set the TextBlock's content in the TextBlock.Text property:

<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 Text="Test"/>
</Window>

Maybe that is the issues.

Raúl Otaño
  • 4,640
  • 3
  • 31
  • 65