Editing XAML leads Visual Studio's Designer to crash

前端 未结 8 788
长情又很酷
长情又很酷 2021-01-03 21:43

Original Question


I\'m working on a WPF application with Visual Studio 2010, using Telerik.

I have been dealing with a lot of crashes ev

相关标签:
8条回答
  • 2021-01-03 22:17

    I believe the problem you are seeing is related to one of the controls you are using.

    Let me first show you a way of reproducing this problem; if it is the same issue you are seeing. (I'm using VS 2013 which handles this issue a little better than vs 2010)

    Firstly, I created a custom control which is a TextBox; and I have code that looks something like this.

    public class CustomTextBox : TextBox
    {
        public string testText { get; set; }
    
        public CustomTextBox()
            : base()
        {
            if (string.IsNullOrEmpty(testText))
            {
                throw new ArgumentNullException();
            }
        }
    }
    

    then I put this control into the xaml

    <Grid>
        <local:CustomTextBox/>
    </Grid>
    

    All I'm doing is throwing an exception when a property is null when the control calls its constructor (which it will do when in the designer as the designer attempts to new it up and render it).

    In VS2013 I simply have a red line underneath the control in the XAML itself, but from past experience with VS2010 this issue did cause the designer to fall over.

    What I may suggest you do, is go through the XAML without the designer and take out any 3rd party/custom control's one at a time. One of these controls may be throwing an exception which can produce what you are seeing. If its one of the Telerik controls, contacting them is a option.

    0 讨论(0)
  • 2021-01-03 22:17

    Try initializing runtimeType object with typeof(Type) as

    Type runtimeType = typeof(Type)
    

    Also evaluate the value of variables reflectionType,this,this._targetFrameworkProvider and this._targetFrameworkProvider.GetRunTimeType(reflectionType) in a watch during debugging.

    This might help you.

    0 讨论(0)
  • 2021-01-03 22:19

    Also, I read somewhere that if you start vs as an administrator it gives you issues, try starting Visual studio not as Admin

    Read This, a couple of random things you can try..

    0 讨论(0)
  • 2021-01-03 22:20

    If you think that it might be related to a component you are using, you may want to try and debug the Visual Studio Design mode and see in which scenario the ArgumentNullException is thrown or at least get the CallStack when the exception is thrown.

    See this link : How to troubleshoot and debug Visual Studio design mode errors?

    I personally do it with an instance of Blend and one instance of Visual Studio instead of two instances of Visual Studio.

    I would also try from a complete new project without any external dependencies to see if it could be related to your Visual Studio Install

    0 讨论(0)
  • 2021-01-03 22:23

    I guess, your best bet is to debug Visual Studio!

    • Run Visual Studio (instance #1) and load your solution
    • Run a 2nd instance of Visual studio (#2)
    • From instance #2 go, Debug->Attach to process->Select devenv.exe (instance #1, make sure to select Managed debugging)
    • Then select Debug->Exception, press "Find.." and search for System.ArgumentNull then check "Thrown"
    • Go to instance #1, load your view in the designer, this should trigger a break point in instance #2 and it should show you a full stack trace. This information should be enough to identify the offending control/component..
    0 讨论(0)
  • 2021-01-03 22:27

    VS2010 breaking with certain XAML is a fairly well known issue.

    Have you tried adding this code to the Load Event of the offending control?

    if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { return; }
    

    What causes the VS 2010 SP1 WPF Designer to crash?

    0 讨论(0)
提交回复
热议问题