Visual studio 2013 crashes while using winforms designer - c#

Visual studio 2013 often crashes when I use drag and drop functionality in winforms designer, like adding a new control, resizing controls, or just click on a control in order to see/change properties of the control. OS - Win 7x86, verson of VS - VS2013 ultimate 12.0.21005.1 rel. I tried to run VS as an administrator, but it still crashes almost all of the time when I use drag and drop functionality.
I debugged VS with the help of the second instance of VS(attached to a first VS process), here is the result: (i run it many times, it looks like that it throws 3 different kind of exception)
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Drawing.dll
Additional information: Object is currently in use elsewhere.
> System.Drawing.dll!System.Drawing.Image.RawFormat.get() Unknown
System.Drawing.dll!System.Drawing.Graphics.DrawImage(System.Drawing.Image image, int x, int y) Unknown
System.Design.dll!System.Windows.Forms.Design.Behavior.DesignerActionGlyph.Paint(System.Windows.Forms.PaintEventArgs pe) Unknown
Or the same exception but different call stack:
> System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, int x, int y, int width, int height) Unknown
System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect) Unknown
System.Design.dll!System.Windows.Forms.Design.Behavior.SelectionBorderGlyph.Paint(System.Windows.Forms.PaintEventArgs pe) Unknown
Another exception:
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
> mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) Unknown
And the last one:
An unhandled exception of type 'System.AccessViolationException' occurred in System.Drawing.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
> System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, int x, int y, int width, int height) Unknown
System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect) Unknown
System.Design.dll!System.Windows.Forms.Design.Behavior.SelectionBorderGlyph.Paint(System.Windows.Forms.PaintEventArgs pe) Unknown
ETA: #GRUNGER 's answer helped, but what was the problem then?
It crashes even in a new empty project.

I have the same problem. Mouse cursor is blinking?
Try this (on admin mode CMD):
netsh winsock reset
Sometimes it helps, but the problem comes back after reboot.

This can be due to putting some dangerous/crashing code into constructor that prevents control from being created. Re-factor your code and move it to Load handler instead.

Related

Difference between actual OOM and 2GB object OOM?

I was wondering if there is some difference between the OOM exceptions thrown for an actual OOM (memory runs out), and the exception thrown when the 2GB object limit is hit?
I have the following code for causing the OOMs (no app.config changes, gcAllowVeryLargeObjects is by default set to false):
struct Data
{
double a;
double b;
}
// Causes OOM due to the 2GB object limit.
List<Data> a = new List<Data>(134217725);
// Causes OOM due to actual OOM.
List<Data[]> b = new List<Data[]>();
for (int i = 0; i < 13421772; i++)
{
b.Add(new Data[134217724]);
}
Now, I've executed the code from Visual Studio, and I get the following exceptions:
2GB object limit
System.OutOfMemoryException
HResult=0x8007000E
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=mscorlib
StackTrace:
at System.Collections.Generic.List`1..ctor(Int32 capacity)
at ConsoleApp1.Program.Main(String[] args)
actual OOM
System.OutOfMemoryException
HResult=0x8007000E
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=ConsoleApp1
StackTrace:
at ConsoleApp1.Program.Main(String[] args)
From here, it doesn't seem like there is a significant difference between the two exceptions (other than the stack trace/source).
On the other hand, I executed the exact same thing from LINQPad and got the following:
2GB limit
actual OOM
Executing RuntimeInformation.FrameworkDescription from both places results in .NET Framework 4.8.4341.0
My question is about detecting/differentiating between the two cases, although I am also curious as to why the error messages differ between the LINQPad and VS executions.
I can explain the difference between LinqPad and Visual Studio:
If you run x86 DEBUG and RELEASE .Net Framework 4.8 builds of the following code:
static void Main()
{
try
{
List<Data> a = new List<Data>(134217725);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
try
{
List<Data[]> b = new List<Data[]>();
for (int i = 0; i < 13421772; i++)
{
b.Add(new Data[134217724]);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
For the RELEASE build you get:
Array dimensions exceeded supported range.
Exception of type 'System.OutOfMemoryException' was thrown.
For the DEBUG build you get:
Exception of type 'System.OutOfMemoryException' was thrown.
Exception of type 'System.OutOfMemoryException' was thrown.
This implies that the LINQPAD version is RELEASE and the Visual Studio version is DEBUG.
So the answer is: Yes, there clearly is some difference, but:
Only the message differs
We should not rely on this never changing
It differs between DEBUG and RELEASE builds.
Aside:
On my PC, the DEBUG build of the test code above immediately throws the two OutOfMemoryException exceptions.
However, the RELEASE build quickly throws the first OutOfMemoryException, but it is several seconds before it throws the second exception. During this time, its memory usage increases (according to Task Manager).
So clearly there is some other difference under the hood, at least for .Net Framework 4.8. I haven't tried this with .Net 5 or .Net Core.

WPF coded UI test randomly fails with weird ArgumentException

I have coded UI tests in WPF application and they occasionally fail with the following exception:
Message: Test method MyMethodNameGoesHere threw exception:
System.ArgumentException: Parameter is not valid.
and StackTrace:
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at Microsoft.VisualStudio.TestTools.UITesting.LoggerUtility.GetDesktopImage()
at Microsoft.VisualStudio.TestTools.UITesting.LoggerUtility.CaptureScreenShotAndDrawBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 borderWidth, Boolean isActualControlBounds)
at Microsoft.VisualStudio.TestTools.UITest.Extension.LoggerUtilities.CaptureScreenShotAndDrawBounds(Rectangle bounds, Int32 borderWidth, Boolean isActualControlBounds)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.CaptureScreenShot(UITestControl control)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.GetUITestControlString(UITestControl control)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException(COMException ex, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, String queryId)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<Find>b__175_0()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Find()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyPrivate(String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.GetPropertyOfType[T](String propertyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.get_Exists()
at MyProjectNamespace.UITests.TestButtonExists() in E:\...\UITests.cs:line 177
Any code that tries to access properties of UITestControl like Exists, Checked or Selected throws it. For example:
WpfButton button = UIControlBuilder<WpfButton>.Builder()
.Parent(MainPane)
.AutomationID(MyButtonId)
.Build();
// ...
Assert.IsTrue(button.Exists);
Interestingly, this issue happens randomly, but with some pattern. If I run tests one by one, then they work well. If I run many tests in row, then after some time one test fails and then all consequent tests fail too. I thought that it could be a memory-related issue (leakage or out of memory), but I definitely have lots of memory available and processes don't seem to consume much of it.
From my investigation UI test framework catches an exception in FindFirstDescendant and tries to capture a screenshot to report this exception, but fails to do this too:
// decompiled UI test framework's UITestControl.cs code
internal UITestControl FindFirstDescendant(string queryId, int maxDepth, ref int timeLeft)
{
// ...
try
{
element = this.ScreenElement.FindScreenElement(queryId, maxDepth);
}
catch (Exception ex) // catches exception here
{
// but this method does also throw exception, because of a bug:
Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(ex, queryId);
throw;
}
}
Even more interesting that this is a very generic error which happens in the constructor of .NET's Bitmap (invalid width or height parameter?).
Because of this Bitmap issue I can't get the original exception, so I can't understand what happens. Playback.CaptureScreenShot is marked with compiler warning suppression attribute, which clearly specifies that this method shouldn't throw any exceptions.
Is this a bug in UI testing framework?
One more interesting observation. It creates screenshots in my test directory, but the application's window is highlighted incorrectly on screenshots. This is how it looks like. Red is my display setup, blue is where the main window actually is, green is how WPF highlights on test result screenshot:
The distance of green narrow line and blue narrow line for corners are equal, so for me it seems like like it takes the application's window's offset within single main display, but then it tries to take a screenshot by applying the offset to all displays.
Can it be a cause of a bug (like going out of display's bounds) or is it just another thing?
Since it looked like a bug, I have asked the same question on DeveloperCommunity.
It seems like the multi-screen is just unsupported:
Thanks for investigation on this issue. looks like you are running coded ui test with multi screen. This is actually an unsupported scenario.
Also Coded UI test is in deprecation path. Check https://learn.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code?view=vs-2017
We suggest moving to Selenium or Appium with WinAppDriver as the case may be

System.ArgumentOutOfRangeException when calling Method. How do I find out where the error occurs?

I designed a program with Windows Forms Designer and added functionality that gets executed when pushing a certain Button. After executing my program and clicking on said button I get the following Error:
An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
The weird part is that it tells me the error happens when I call the method; as in:
private void btPPTX_Click(object sender, EventArgs e)
{
PptxConverter.Generate();
}
I had the same error before but it showed me the exact line where it was happening(Inside of the Generate-Method). I corrected my error but now I don't even know where to start looking. The Generate-Method is very extensive and involves a whole set of other methods so it's tough to find the error or post the whole code here.
Is there any effective way to find the error or do I have to go through the code line by line to find it?
I'm using Visual Studio Community 2015
The StackTrace is one of your ways to investigate exception in a method graph (nested calls):
try
{
PptxConverter.Generate();
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
When you print the exception object, you get the exception message and the stack trace which is a detailed call hierarchy that leads you to the exact Method(with line number sometimes) where the last exception was thrown.
Given a method Main that calls A that calls B that calls C (which throws the exception) Stack-trace looks like this:
/*
System.Exception: Some Error Message
at ProjectName.Program.C() in C:\Users\User\Documents\Visual Studio 2015\Proj
ects\ProjectName\ProjectName\Program.cs:line 87
at ProjectName.Program.B() in C:\Users\User\Documents\Visual Studio 2015\Proj
ects\ProjectName\ProjectName\Program.cs:line 82
at ProjectName.Program.A() in C:\Users\User\Documents\Visual Studio 2015\Proj
ects\ProjectName\ProjectName\Program.cs:line 77
at ConsoleTest.Program.Main(String[] args) in C:\Users\User\Documents\Visual
Studio 2015\Projects\ProjectName\ProjectName\Program.cs:line 52
*/

What could possibly cause COMExceptions while dragging file over the Desktop?

It doesn't crash, all the exceptions I mention here can only be seen in Output window of Visual Studio. Here is the implementation of Dragging:
WPF:
<StackPanel Orientation="Vertical"
MouseDown="DragShortcut"
x:Name="Shortcut">
<Image Source="{Binding Icon}"/>
<Label Content="{Binding ShortcutLabel}"/>
</StackPanel>
cs code:
private void DragShortcut(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
var dataObject = new DataObject(DataFormats.FileDrop, new[] { Options.DragDropOptions.ShortcutPath });
DragDrop.DoDragDrop(Shortcut, dataObject, DragDropEffects.Copy);
}
Everything seems to work as expected, but every time I drag something over my Desktop or Explorer window I receive the following messages in the Output window of my Visual Studio:
...
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
A first chance exception of type 'System.NotImplementedException' occurred in PresentationCore.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
...
When Visual Studio is set to stop on that kind of exceptions, I can see the following Exceptions:
System.Runtime.InteropServices.COMException was unhandled
Message: An exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll and wasn't handled before a managed/native boundary
Additional information: Invalid FORMATETC-Structure (Exception HRESULT: 0x80040064 (DV_E_FORMATETC))
and
System.NotImplementedException was unhandled
Message: An exception of type 'System.NotImplementedException' occurred in PresentationCore.dll and wasn't handled before a managed/native boundary
Additional information: The method or operation is not implemented.
It doesn't lead to crash or anything, it's just uncomfortable for me as a developer to have such a thing happening in background. Does anyone have an Idea what could it be?
EDIT:
This problem looks a lot like mine, but seems to have another cause and solution.
This is entirely normal. Whatever window of another process you drag over will make that process poke the object you drag to see if it supports a particular format or can convert the object to another format. Done with COM calls under the hood. If the answer is "yes" then you see the cursor change to indicate that you can drop.
The IDataObject interface implementation in WPF says "no" by throwing an exception. The normal way in which COM failure codes are generated in a .NET program. That exception gets converted by the CLR into a COM error code, an HRESULT, to tell the process that it isn't going to work. Note how the Exeption class has the HResult property, that's what the process sees.
The debugger dutifully displays the "first chance" exception notification if you asked for it. Right-click the Output window, "Exception Messages" option, turned on by default. Nothing actually goes wrong, the exception is caught and handled gracefully. Feature, not a bug.

Emgu.CV , CvBlob.BoundingBox throw System.AccessViolationException

Im using Emgu.CV (OpenCV), to find delta in image, but sometimes I get Access violation exception that cause my app to crash.
After digging in the debug I find that (blobs.Values):
List<CvBlob> listOfBlobs = blobs.Values.ToList();
return 1733 items, and when I do the following:
But when run through the list I get EXCEPTION:
if (resultedRectangles[j].Contains(listOfBlobs[i].BoundingBox))
I check and find the exception occurred at: i = 418 :
+BoundingBox '(new System.Collections.Generic.Mscorlib_CollectionDebugView(listOfBlobs)).Items[418].BoundingBox'
threw an exception of type
'System.AccessViolationException' System.Drawing.Rectangle
{System.AccessViolationException}
As I see the last valid value in the list is in 417.
I have 2 questions:
1. Why blobs.Values.ToList(); return such corrupt data?
2. How I can check the value before access it to prevent System.AccessViolationException ?
Are you having multiple threads in your Process? If there are multiple threads trying to initialize the List, then the list may get corrupted.
This exception is more specific to Memory related issues and you will be in a hard time to debug this, unless the all the code is in your control. The following link may help.
http://msdn.microsoft.com/en-us/library/system.accessviolationexception(v=vs.110).aspx
Me too got trapped in the same error.

Categories

Resources