20

Original Question


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

I have been dealing with a lot of crashes everytime I use the designer : clicking on a element, changing its position, even changing its name leads to a crash, and displays the following exception :

System.ArgumentNullException
Value cannot be null.
   to System.RuntimeType.MakeGenericType(Type[] instantiation)
   to Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(Type type)
   to Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.TryGetRuntimeType()
   to Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeType(Type type)
   to Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkProvider.GetRuntimeType(Type reflectionType)
[...]

I tried the following things :

  • Uninstall and reinstall Telerik;
  • Uninstall and reinstall .NET 4.0;
  • Uninstall and reinstall Visual Studio.

None of these attempts worked.

This morning, I noticed that the designer didn't crashed at all, and I understood why : the designer crashes when I have opened or edited XAML.

After opening XAML, Visual Studio begin to freeze and the designer crashes everytime I try to click something. If I close Visual Studio and Build the solution (without opening XAML), everything works fine with the designer.

My guess is that something goes wrong when Visual Studio tries to "convert" XAML code to graphical elements in the designer, and only in that direction.


Question : Have you ever experimented this kind of thing ? Have you any idea of why modifiying XAML causes crashes and how to solve it ?

Thank you in advance.


New attemps done after reading answers

  • Debug the Visual Studio instance itself when the designer opens. The method which leads to the ArgumentNullException is GetRuntimeTime. I've been able to see the .NET code but I couldn't determine the source of the problem. See the full stack trace below :

enter image description here

Additionally, this is the exact line where the error occurs and the exception details. Note that the file is VSIsolationProviderService.cs and that I am able to see the source thanks to the .NET Reflector Object Browser.

enter image description here

  Message=Value cannot be null.
  Source=mscorlib
  StackTrace:
       to System.RuntimeType.MakeGenericType(Type[] instantiation)
  InnerException: null

Finally, the Local Variables inspector at the moment of the Exception shows the following object :

enter image description here

End of the object :

enter image description here

Answers to comments :

  • The value of this._targetFrameworkProvider at the line where the exception occurs is below. enter image description here
Chostakovitch
  • 965
  • 1
  • 9
  • 33
  • have you got AnkhSVN add-on ? – Muds Feb 18 '15 at 10:33
  • @Muds I don't know exactly where I can check this, but I'm pretty sure that not. I use `TortoiseSVN` outside of Visual Studio. – Chostakovitch Feb 18 '15 at 10:37
  • What is the actual XAML you're using? Can you make a small project that reproduces the error? – JJS Apr 27 '15 at 22:53
  • @JJS The XAML I am using is part of a big project. My whole team has this problem with the designer crash. I have been able to determine that the crash occurred with the method `GetRuntimeType` ( http://puu.sh/hssuL/4919e1cee5.png ). I start to think that it is a bug with VS2010. – Chostakovitch Apr 28 '15 at 08:21
  • Can you post an activity log as well? http://blogs.msdn.com/b/visualstudio/archive/2010/02/24/troubleshooting-with-the-activity-log.aspx – JJS Apr 28 '15 at 16:11
  • Is _targetFrameworkProvider null? – JJS Apr 28 '15 at 16:20
  • can you reproduce the issue in VS2012 or VS2013? – JJS Apr 28 '15 at 16:20
  • @JJS I don't have and can't install posterior versions of VS. Can you precise to what `_targetFrameworkProvider` does reference ? I will answer you tomorrow. – Chostakovitch Apr 28 '15 at 16:23
  • _targetFrameworkProvider refers to the field of "this" in the VSIsolationProviderService.cs sample you posted. I'd like to know which variable is null. – JJS Apr 28 '15 at 16:25
  • have you tried completely removing/reinstalling all the 3rd party libraries you're usinig? – JJS Apr 28 '15 at 16:26
  • @JJS I will tell you that. I tried it, as I wrote I totally removed and reinstalled Telerik, which is the only third party library I use. – Chostakovitch Apr 28 '15 at 16:28
  • @Chostakovitch I'd suggest you try the VS2013 Express with Expression Blend for Visual Studio - http://go.microsoft.com/fwlink/?LinkId=240162. – JJS Apr 28 '15 at 16:33
  • @JJS I can't, as all my society doesn't want to migrate to posterior version of VS. – Chostakovitch Apr 28 '15 at 16:34
  • VS2013 can edit / compile a VS2010 project file. There is no need to make your whole group migrate w/ you. I'm suggesting the other version to find out whether it's a problem isolated to VS2010. – JJS Apr 28 '15 at 16:36
  • @JJS You mean just trying ? In this case I'll try, but I don't have a lot of time (install Telerik, etc.) – Chostakovitch Apr 28 '15 at 16:38
  • @Chostakovitch yes I mean just try. Telerik is already installed, Shouldn't need to 'install' again w/ 2013. The assemblies are in the GAC. – JJS Apr 28 '15 at 16:43
  • @JJS I updated my question. I can't get the log activity, VS2010 throws an exception. – Chostakovitch Apr 30 '15 at 15:11

8 Answers8

9

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..
  • You did it ! The breakpoints were not working, but catching the ArgumentNullException works perfectly. So I catched the exception but I don't know what to do because I have machine code : http://puu.sh/hsst3/1119ca74e2.png Additionaly, this is the new stack trace : http://puu.sh/hssuL/4919e1cee5.png Any idea ? – Chostakovitch Apr 27 '15 at 08:29
  • Getting close :) Go Debug->Windows->Locals that should show you the variables in the current stack frame (including hopefully parameters). Look for the value of "instantiation" to find the offending type.. If the variables do not have values (due to optimisation) then go up the stack (double click on the individual frames starting from the top). The locals window should show new variables every time you switch frames... hopefully you will hit a type that will tell you the offending control. – Mo the Conqueror Apr 28 '15 at 09:14
  • I have edited my answer and added screenshots of what you asked. I can't find `instanciation` parameter, may you be more precise ? Thank you for your help. ;) – Chostakovitch Apr 28 '15 at 09:30
  • I think you should check if `this` or `_targetFrameworkProvider` is null – csharpwinphonexaml Apr 28 '15 at 22:45
6

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.

Gavin Lanata
  • 366
  • 2
  • 9
  • Thank you for your answer. I believe this is indeed the problem as several people have the same problem, but I can't isolate one component. My XAML contains a lot of components, and everytime I open the designer to check, it takes 10 seconds to crash. – Chostakovitch Apr 21 '15 at 13:55
  • 1
    About a year ago I was on a job re-building a UI to an older WPF application; it had the same problem. I closed the solution, and opened the xaml files in stand-alone fashion. VS didn't even start the designer and thus I started by eliminating large areas of the xaml in attempts to narrow it down quickly. Then focus on individual controls. It did take a while go through the whole process, about a day I think it was. Some of the exceptions I handled by deriving controls from the 3rd part controls and overriding offending methods where I could. – Gavin Lanata Apr 21 '15 at 15:01
2

As previously said by Gavin, try finding the control that is the issue.

You can still edit the files in VS if you right click the .xaml file select Open With and choose Source Code (Text) Editor.

You can set it to default if you expect this to be in a lot of files, and switch it when you're done.

This solution will open .xaml files without a designer, but with (some) intellisense.

Thomas Bouman
  • 608
  • 4
  • 17
1

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

Community
  • 1
  • 1
Muds
  • 4,006
  • 5
  • 31
  • 53
1

You can try the XAMLPAD to test your XAML page.

Reference : https://msdn.microsoft.com/en-us/library/vstudio/ms742398(v=vs.90).aspx

Hope this helps you.

Sunil Kumar S C
  • 296
  • 2
  • 12
1

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

Community
  • 1
  • 1
Jonathan Naim
  • 229
  • 1
  • 7
  • Once you have isolated from where the issue is coming from with the CallStack, you can disable Debug Just my code to step into dotnet framework or the third party library if you have the PDBs. [Just My Code](https://msdn.microsoft.com/en-us/library/dn457346.aspx) – Jonathan Naim Apr 27 '15 at 16:04
0

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?

Community
  • 1
  • 1
JJS
  • 6,431
  • 1
  • 54
  • 70
0

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.

Adersh M
  • 596
  • 3
  • 19