Runtime Error always disappears after clean build - c#

I have a WPF MVVM application. When I start Visual Studio for the first time, and run the app in debug mode, I get an exception as described below. Following a clean build, the application runs fine until re-starting Visual Studio and running again.
'The invocation of the constructor on type 'MyView' that matches the specified binding constraints threw an exception.' Line number '135' and line position '8'.
{"Cannot locate resource 'views/myview.xaml'."}
MyView is a UserControl, exists in the folder it's being searched for in and is contained in the main project.

This is a case of a spurious exception, I don't think it had anything to do with not finding the view. I noticed when I disabled a custom logging mechanism I had set up, the errors went away so likely an exception further up was causing this.

Related

The application is in break mode -- cannot properly debug

I have a wpf application that I am creating and whenever I try to debug my code and reach an exception I am given the message "The application is in break mode". I am able to see the exception thrown but I am not given the line that the error was thrown.
I did look through some threads and the solution most people gave was to go to Tools > Options > Debugging > General > then to uncheck Enable Just My Code. I did this and I get a similar error but instead the error message is "AsyncMethodBuilder.cs not found". I then looked for a solution to that error and was told to check Enable Just My Code.
Is there a solution to "The application is in break mode" that does not consist of unchecking Enable Just My Code?
I decided to rebuild the entire project and that seemed to fix my issue.

Compile time error occur bit it did not affect anything xamarin forms

I am getting this error:
Error Unable to remove directory "obj\Debug\81\android\bin\classes". The directory is not empty. DipsDemoXaml.Android
But It does not affect my code for building. But it causes when I try to test my code with unit testing and try to run all test once. Run them selecting one by one is not a problem.
What's the reason for this error?

Editing XAML leads Visual Studio's Designer to crash

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 :
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.
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 :
End of the object :
Answers to comments :
The value of this._targetFrameworkProvider at the line where the exception occurs is below.
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..
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.
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.
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..
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.
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
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?
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.

C# SystemNullReferenceException in WindowsForms

I'm having the following error when closing a form in an application
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
***** Exception Text *******
System.NullReferenceException: Object reference not set to an instance of an object.
at Infragistics.Win.UltraWinGrid.UltraCombo.get_Text()
at Infragistics.Win.UltraWinGrid.UltraCombo.OnEnter(EventArgs e)
at System.Windows.Forms.Control.NotifyEnter()
at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
I'm almost sure that this has something to do with the fact that I'm using multithreading to populate some data, but my problem is that I'm not able to determine the place in which the call to the method is being made.
A .Net framework appears and I can only click continue or close, but what I really wanted was an application crash to determine what is causing the error. This is even more complicated because it only happens with compiled code. Do you know any profiler or technic to catch the error?
Can I attach the debugger to my exe to capture the method throwing the error?
UPDATE:
What I really want is to enable JIT debugging and have access to the stacktrace tho determine the cause of the error, I've done that by adding the
<system.windows.forms jitDebugging="true" />
to the config file as described in MSDN to my config file, but now I'm not getting any error at all.
Bottom like, can I do anything else for the framework give additional details about the error?
You can set Visual Studio up to break on specific types of exceptions. There is an Exceptions dialog under the Debug menu. Just check the exception you wish to break on and run the code with the Visual Studio Debugger attached.

C# gives anonymous error

while i am calling a method which is declared in another project. calling project and called project are presented in same solution.
I am getting a error window that says:
Window Tile : Test.vshost.exe
Test.vshost.exe has encountered a problem and needs to close. we are sorry for the inconvenience.
(I will make disappear the error window by clicking "Dont Send" button)
what is the reason for such this error.
Note: I have included the refereed project in reference.
I used call a methode as follows
ReconcileDBService.InsertRecordInT_AUDIT_Incident(keyCase);
Above methode declared as follows
public static void InsertRecordInT_AUDIT_Incident(string keyCase)
We can't really help you based on the data you provide...
Is your program using Win32 or COM interop ?
Try to add breakpoints and debug messages to pinpoint the problem. Once you know the exact location where the problem occurs, it will be easier to understand it.
Turn off the "Visual Studio hosting process" and start your session again. Maybe you get some better or more information about an exception that is raised by your programm.
You can do this under the Project-Properties-->Debug-->Enable the Visual Studio hosting process (uncheck)
Also you could check the build order of your projects. It may be that the "Visual Studio hosting process" uses a diffrent assembly version than your programm expects.
Press Ctrl-Alt-E (Debug->Exceptions) and in the 'Break when an exception is:' selection, select everything.
Start a debug session with the application.
The debugger should now stop at the crash and you should be able to look what you are sending to the other project, and maybe solve your problem.

Categories

Resources