Selecting Catch Block (in visual studio) with Regular Expression Search - c#

I want to select all catch blocks (in my C# code in visual studio) using regular express search but unable to create a regular expression that selects all catch blocks (including empty blocks and blocks with different exception handling)
I have tried following regular expressions but failed
.*catch.*(\r?\n)*.*(})
.*catch.*(\r?\n)*\s*.*(\r?\n)*.*(\r?\n)*

I have found the solution, regular expression catch(.|\n)*?} will select all catch blocks

Related

Find catch corresponding to a throw in Visual Studio

When using gotos in c# Visual Studio helps quite well with figuring out the controll flow. Shift-F12 on the label shows me from where the part is reached, and F12 on the goto statment goes to the label.
But I usually use no gotos in my code. In allmost all cases stuctured programming or exceptions seem to be better.
However, when using exceptions the controll flow can be just as confusing as using gotos. Has visual studio equivalent functions for exceptions? e.g. find all throws that one catch could catch, and find the corresponding catch for a throw?
Open your project -> Debug -> Windows -> Exceptions -> Check every kind of exception you are interested about
c# don't have a goto like Visual Basic 6:
You only have to do a:
Try
{
....
}
Catch(Exception ex)
{
String err = ex.Message;
}
You can see this as your reference

no logical space left to create more user strings

While trying to compile and debug C# code in Visual Studio I'm hitting this error - "no logical space left to create more user strings". Actually, the code compiles properly, but it crashes with this error while trying to create the executable.
I've looked at C# compile error: "No logical space left to create more user strings" and EF 4.3.1 IMigrationMetadata.Target strings are causing "No logical space left to create more user strings." compile errors but these don't help here, since they talk about C# code that was generated by some other script/process.
In my case, it's normal C# code that's being compiled/linked and hitting this error.
Can someone please help me figure out how I can debug this issue? What may be causing this problem?
There are a total of about 10 string declarations in my code.
Use Strings application to dump out all the strings in your application,from which you will be able to find ,what string is being created multiple times.
Alternatively you may also use Windbg

Import to Excel does not work

I am using the Office Integration Pack
After following instruction correctly I am still not able to get the Excel to Import working
My Visual Studio Lightswitch 2011 application is configured to host on IIS Server and use's Easy Shell (so its the default Shell provided by MS).
So far I have tried is calling the
OfficeIntegration.Excel.Import(
this.States,
#"C:\Users\Mr_Mia_Gie\My Documents\ExcelSheet.xls",
"Sheet1",
"A1:C3");
on _Execute event of a button (the button does not live on the Shell Command Bar)
The exception I get back is "Object variable or With block variable not set."
Any solution or suggestion will be highly appreciated
Cheers
I agree with Nevyn (& I'd vote up his answer, but it's embedded in the question as an edit so I can't).
As Nevyn has pointed out, there are really only three objects in that particular line of code that can be causing a null exception:
the OfficeIntegration object
the OfficeIntegration.Excel object
or, the this.States collection (unlikely though)
As was also pointed out for you, it's most likely that one of those objects isn't correctly initialised. You need to check what the value of those three objects are by putting a break point on that line & checking what their values actually are at that point.
You could also put a guard clause in your code (just above that line):
if (OfficeIntegration == null) || (OfficeIntegration.Excel == null) return;
It won't neccesarily "fix" the problem, but it will stop the null exception from occuring (but this shouldn't be a problem in an Execute method). But it's good programing practice to put a guard clause any time you're referencing an object whose value could be null.
Failing that, the only other advice any of us can give you is to post a question in the questions section of the gallery page, where you downloaded the extension from. The autor of the extension should be able to help you.
Is this a web application, if so I dont think it supports it. It requires an extenstion. I dug up an article for you, try it out:
http://blogs.msdn.com/b/lightswitch/archive/2011/04/13/how-to-import-data-from-excel.aspx
The office integration Pack is for Visual Studio LightSwitch windows application and does work for application that are hosted on IIS hence the below code throws exception
OfficeIntegration.Excel.Import(
this.States,
#"C:\Users\Mr_Mia_Gie\My Documents\ExcelSheet.xls",
"Sheet1",
"A1:C3");
The link show that the extension does not support LS WebBrowser application http://officeintegration.codeplex.com/discussions/374585
Also the extension Import data from Excel does work for IIS hosted LS application that runs in webbrowser

Visual Studio format specifier for C# arrays?

In C++ I could do this, but I don't see how to do it in C#. Basically I want to use a format specifier in the Watch Window of my Visual Studio 2008 debugger to view only a slice or portion of an array. For example, if I have a 2D array like so:
int[,] myArray = new int[5,15]
I might only want to view the last 15 items in the list, so I would like to be able to put this into my watch window (or something similar):
myArray[5],15
Is there anything like this in Visual Studio?
The format specifiers supported by Visual Studio 2008 debugger is described here. Clearly, the C# debugger does not support the same specifiers as C++.
Building on #Omers answer, you could watch a "processed" version of the array using the following watch expression:
System.Linq.Enumerable.Reverse(System.Linq.Enumerable.Take(System.Linq.Enumerable.Reverse(x), 2)), results
Note: the results format specifier is useful when watching IEnumerable results when you're interested in the results only.
This doesn't directly answer your question, but if you have System.Core loaded, and a using System.Linq; in your scope, you could just evaluate myArray[5].Reverse().Take(5).Reverse() to get the last 5 values.
Check this out. This VS plugin increases the number of ways you can visualize data in debug mode.
http://karlshifflett.wordpress.com/mole-2010/
... there is a 2008 version as well
http://karlshifflett.wordpress.com/mole-2010/mole-for-visual-studio/

Visual Studio 2005 Search Memory

I don't think this exists, but I'll throw this out there anyway. Is it possible, while debugging, to search for a value in memory?
For example, if I have a string "uniqueString" cached somewhere in memory, but I don't know under which variable it's stored--can I do a search for it? As in, find out which variable(s) have "uniqueString" as their value?
This is for C# managed code.
windbg will let you do the search directly. 's' is the command you're looking for, here's a very good cheat sheet. sos extension lets you scan for string objects too in managed code though the s command should find them too (must use unicode aware search).
You have the same functionality in Visual Studio, available from the immediate window. Although, you'd have to manually somehow limit the address range to search in (see the syntax in the link).
(edit) BTW, you can easily create dumps from VS too: Debug->Save Dump As.

Categories