How do I skip an iteration of a foreach loop using C Sharp

How do I skip an iteration of a foreach loop using C Sharp

How do I skip an iteration of a foreach loop using C Sharp

A question that came to mind was, how do I skip an iteration of a foreach loop using C Sharp? I am currently working on a project that deals with a lot of XML requests and responses. In a method that I am working on, I have a foreach loop that that sends out reporting requests for items I need using a solution provider ID. Sometimes those items belong to a different provider ID. For the provider ID, I put them in a dictionary that is iterated by the foreach loop. As I read the response, it may tell me that the item I need reporting for belongs to another solution provider ID. So, as the XML response is read, if the return status code indicates to me that it belongs to another solution provider ID, I break the current iteration of the foreach loop by using the continue command. The continue statement is used to pass control from the current iteration of the foreach loop, or other loops such as the while, do and for loops, to the next iteration in which it is enclosed. Initially, I thought I could use the break statement, but the break statement completely terminates the closest enclosing loop. Break statements in my experience was mainly used in switch statements, but I tried to apply it to the foreach loop, but alas, that did not work. So, a refresher on the differences between the break and continue statement, the break statement exits the closest enclosing loop completely, while the continue statement skips the current iteration of the closest enclosing loop to the next iteration.


Evernote saved my career

Well it saved it for now. I am not the sharpest tool in the shed, however, I am the most hard working tool in the shed. With that said, Evernote, is really a helpful tool. A little background first, at my job, I work with a lot of brilliant individuals, so brilliant, I think they forget they are talking Aramaic to me. When they try to explain things to me, at their intelligence level and experience, sometimes it feels like the 1 Ceres asteroid smashing into my weak feeble body. So much technical lingo, so many variables, scenarios, and systems that interact with one another. In my line of business, I am fairly new to it. I work with remote monitoring, dealing with remote devices receiving and sending packets of data to and from satellites. All this is new to me. Very interesting stuff, yet hard to comprehend. For the past few months, I have been using Evernote to help close my understanding gap. Normally, when things are trying to be explained to me, it takes me a bit of time to process it. I have to sit down, and really think about what is being said. But in this industry, there is no time. Having to deal with scrums on a consistent basis, explaining where we are, what road blocks we encountered (if any), and what we will be working on next, and trying to process what your colleagues are going through is just so much information for one to process.

My memory sucks, it really does. I barely can remember where I put my car keys, nevertheless how our systems interact. I am currently reading a book that I am hoping will help with my memory, “Moonwalking with Einstein: The Art and Science of Remembering Everything” by Joshua Foer. Till I find out new techniques to increase my ability to remember things, I have been using Evernote on my Windows Phone. The one feature I use religiously is the audio recording feature. Every meeting that I attend, I record it. Every bit of detail of that discussion is archived for my use. Typically after meetings, I sit down and listen to what was discussed. This helps further to my comprehension of the topic our meeting was about. As well, it removes all doubt I would have if I didn’t do so. “Now what satellite were we supposed to receive packets from again?…”, “Was that a GSM unit or a Satellite unit?…”. That doubt and confusion is now removed from my mind. Just this past weekend, I was processing some meetings we had about this newer project I am supposed to work on. Man o’ man, what a relief to have this information by my side. Come Monday, I knew the right questions to ask, and my path to the project was made clearer. I highly recommend you use Evernote, or some form of data capture app. It will help you rest easier at night and have concrete info for what is to come with  your current task.

Evernote for Windows Phone:


The blockbuster phenomenon that charts an amazing journey of the mind while revolutionizing our concept of memory

An instant bestseller that is poised to become a classic, Moonwalking with Einstein recounts Joshua Foer's yearlong quest to improve his memory under the tutelage of top "mental athletes." He draws on cutting-edge research, a surprising cultural history of remembering, and venerable tricks of the mentalist's trade to transform our understanding of human memory. From the United States Memory Championship to deep within the author's own mind, this is an electrifying work of journalism that reminds us that, in every way that matters, we are the sum of our memories.

List Price: $17.00 USD
New From: $5.19 USD In Stock
Used from: $3.00 USD In Stock

How to force ‘Get Latest Version (Recursive)’ in your Visual Studio solution

Quick tip here. I needed to get the latest version, but I needed it to overwrite everything I had in my local solution. The easiest way to go about this is to go to ‘Source Control Explorer’, find the folder that you want to force get, right click it and select Advanced->Get Specific Version…

Force Get Latest Version

Force Get Latest Version

Once you select that, a new dialog will show with the folder you selected. Below that, check both check-marks that are for ‘Overwrite writeable files that are not checked out’ and ‘Overwrite all files even if the local version matches the specified version’. Finally, click ‘Get’ and wahla you have gotten the latest files from your ‘Team Foundation Server.

Force Get Latest Version

Force Get Latest Version

Using Sql Server Profiler to trace only stored procedures you want, and nothing else

Seems like I am full of blog posts lately. Anyways, I came across this need yesterday when working on our project. I was needing to trace a particular stored procedure, and only this stored procedure with nothing else. Everything else to me was just noise. So, in order to do this fire up SQL Server Profiler, tab over to the ‘Event Selection’ tab for the ‘Trace Properties’, set ‘Security Audit’, ‘TSQL’ events to unchecked, and leave ‘Stored Procedures – RPC:Completed’ to checked.

Trace Properties

Trace Properties

Next thing you would want to do is to customize the column filters. So, click the ‘Column Filters’ button on the lower right side of the ‘Trace Properties’ window. Once the dialog pops up, this is where you can edit any filter you want. For my needs, I needed to adjust the ‘Application Name’, ‘LoginName’, and ‘TextData’ filters. By default, the ‘Application Name’ is set for you.

Filter Application Name

Filter Application Name

I like to filter to only my application’s username. Since, we have numerous apps running hitting the same database instance I have to filter by username. If not, I’d get even more noise when running the profiler. So, I filtered by ‘LoginName’ as so.

Filter Login Name

Filter Login Name

And lastly, the granddaddy of them all, we finally filter by the stored procedures name. In this case we use the ‘TextData’ filter. I use SQL like query using the percent % wild card notation. It works like normal T-SQL. I am filtering anything before and after my filter for a match. I ran a few queries to see if it match each time, and to no surprise it did.

Filter Text Data

Filter Text Data

Here is the result list of the trace by SQL Server Profiler.

SQL Server Profiler Results Set

SQL Server Profiler Results Set

For the record, I hate SQL. So, anything I can learn to ease my use of SQL is great. What is your favorite debugging feature?





View data in table variables using SQL Server Management Studio’s debugger

While working on this current project’s stored procedure, it did a lot of inserts into a table variable called @results. While running the debugger on the stored procedure, I notice when inserts were performed on the table variable I could not look at the data that was inserted into the variable. I tried looking through the Locals window, but the only thing that was shown was the variable name, its value, and type. Yet, the value that it was displaying was not what I was looking for. I was wanting an actual dataset. It only showed the value as (table)

Local window in SQL Server Management Studio

Local window in SQL Server Management Studio

There was no way to view the value. As you can see from above, the other variables had an inspector to view their values. However, in regards to this table variable it did not. I then tried using the Immediate window to run a SELECT * command. Nope, that did not work either. The result was that the SELECT * command cannot be evaluated. SQL debugger is so pointless at times.

Immediate window in SQL Server Management Studio

Immediate window in SQL Server Management Studio

After mucking around, trying to figure this out. I came across a StackOverflow post and saw someone else had this same issue. To view a table’s data set you would SELECT * everything while converting it to an XML document. You can then store the results into an XML data type, which then allows you to use SQL’s inspector to view its dataset.

Sorry about all the blurring of the result set. I cannot show that for business purposes, but you get the idea. Have a good one.



ClaimsPrincipalPermission and unit testing

Recently, I was trying to take a stab at unit testing using NUnit and FakeItEasy. My first unit test started with the following code:


All I really wanted to do was to see if the method does return a instance of ActionResult. Upon executing the unit test, I came across this error:

A first chance exception of type ‘System.InvalidOperationException’ occurred in System.IdentityModel.dll

Additional information: ID7027: Could not load the identity configuration because no <system.identityModel> configuration section was found.

The error specifically pointed out that this was occurring at the ClaimsPrincipalPermission attribute.


ClaimsPrincipalPermission InvalidOperationException occurred.

ClaimsPrincipalPermission InvalidOperationException occurred.

After some research, I came across that the reason that this was occurring was that ClaimsPrincipalPermission becomes invoked at the CLR level, which in turn it affects unit testing.

This approach typically gets in your way, e.g. ClaimsPrincipalPermission gets invoked directly by the CLR, which means it will also run in unit tests, and unhandled exceptions short-circuit your processing pipeline.

Looking at StackOverflow, Dominick suggested you should create a custom ClaimsAuthorizationManager to get around this. You would have your custom ClaimsAuthorizationManager to always return true.

Use a custom ClaimsAuthorizationManager that always returns true for the unit tests.

PrincipalPermissions in general are not very unit testing friendly.

So, I did as he suggested. In my AuthorizationManager class, with my current production AuthorizationManager, I created a unit testing version as so:

Lastly, within my unit testing project I added the following to the app.config file:

When all this was setup, I was able to run my unit test successfully.

Hope this helps you.

Remove unused Using statements in your C#’s code behind

I came across something pretty useful while learning some in and outs of ReSharper. I do not believe this is ReSharper specific, but built into Visual Studio itself. Code can get messy, especially the Using statements in your code behind. I thought ReSharper had some tool to clear this up for me, however, at first glance I did not see anything (maybe you know where it is?). As I right clicked my code behind’s page, the contextual menu popped up as normal, then I noticed “Organize Usings“. Oh, now this is interesting. Could this possibly be what I was looking for? As you can see, it provides the following:

  • Remove Unused Usings
  • Sort Usings
  • Remove and Sort

Yep, “Remove and Sort” is just the thing I was looking for. Take a look at the following screenshot.

Organizing Using Directives

Organizing Using Directives

Linqpad: Using Linqpad as a C# scratchpad

LINQPad is a excellent tool when writing LINQ queries against your database or some form of repository. Not only is it good for writing queries, you could use LINQPad as a scratchpad. Recently, I was tasked into writing a parser for our outbound scheduler service. This service would look into the database and select all current outgoing packets. Once retrieved, the dataset was cast to its respective datatype.  With these packets we commands are embedded into a commands property delimited by semi-colons. Previously, we just put a 1:1 command to command property, so I needed a way to test in quick manner if the parser would work. The parser is pretty simple. As you see I created a string array that held these commands. I would split them based on the character ‘;’. Then I would loop through these commands and output them to the console. I needed to test two versions of this. One with only one command, and another with multiple commands. I supposed I could have written a unit test as well, however, I wanted to illustrate you could use LINQPad for simple logic as this, as well, complex logic.


LINQPad  - C# Scratchpad Demo



Recommended Reading:

List Price: $39.99 USD
New From: $26.09 USD In Stock
Used from: $25.79 USD In Stock

Does my solution use this dll?

Been a while, but here you go. I am currently working on an application that uses Google’s Maps API. Or current project uses older Subgurim and Reimer dlls that take advantage of the API. But did we actually use both set of dlls in order to use Google’s Map API? A quick way to figure this out is to open your object browser (you can open the object browser from the View menu), find the dll in question, right click it, and select ‘Find Usages’. By doing so, it will show you all occurrences of usage of the dll in question. Comes to show, we do not use Subgurim, but we do Reimer. Time to update that dll and move on with this project.


Visual Studio - Find Usages

Visual Studio – Find Usages



QueryString has its limits, try passing data via IRequiresSessionState or IReadOnlySessionState

Oh hey I have a blog, totally forgot about that. Its been busy here lately, but that is no excuse to neglect my blog. So in light of this, I am going to post something I used recently when passing data to a generic handler via query string was just not cutting it. Passing data via query string has limitation in the length of data you can send. Here is a in depth post on these limitations

I’ll sum up these limitations briefly:

  • Internet Explorer
    • 2,038 character limit, boo hiss boo
  • Firefox
    • 65,536, but could work for more
  • Safari
    • 80,000 character limit, but could work for more
  • Opera
    • 190,000 character limit, but could work for more
  • Apache
    • 4,000 character limit, but could work for more
  • IIS – Internet Information Server
    • 16,384, but could work for more
    • IE accepts less, but the server can accept more. Huh?

Since we have to make our web app work with IE there is no choice but to somehow shoe horn our parameters to be passed to generic methods. Instead of using query strings, another approach would be to use the IRequireSessionState or IReadOnlySessionState interface. For my generic handler I used the IReadOnlySessionState interface. In the code behind calling the generic handler, I stuffed the data I needed into session variables, Session[“Key”] = value;

For the generic handler, I had it implement the IReadOnlySessionState. I didn’t want it to do anything, but to read those session variables.

Here’s what I did:

So, I can practically send any type of object I wanted to my handlers and processed that data according to business rules. Well, till next time.