Feeds:
Posts
Comments

Archive for the ‘c#’ Category

Dotnet DevCon-Speakerbanner

Dear all,

As I am preparing my session for the .NET DevCon conference in Nuremberg, I’d like to give you a idea of what I’m going to talk about. It’ll feature Visual Studio Add-Ins, with a major focus on productivity-increasing add-ins. Furthermore, it will briefly explain the necessary steps to be taken once a developer can’t find a needed functionality. And last but not least, it’ll also include something SharePoint 2010 related. So stay tuned!

 

On the 6th of June, we’ll also be at the OpenNight, to be available for community and developer questions.

 

See you there, at the .NET DevCon!

 

You can find an abstract about my session here.

 

Best regards,

Martin

Advertisements

Read Full Post »

Howdy,

Once again about WADA, but this one will be short. I’ve added a new functionality, which is:

 

  • Filter W3WPs by related Identity (as of the application pool)

 

Thanks to my colleague Patrick  for suggesting this functionality!

The UI has changed a little, offering the new drop down for the identities:

WADA_1.1_Screenshot

The WADA 1.1 download is still available at the Visual Studio Gallery.

 

Please note: The Application Pool- and Identities-Filters are mutually exclusive.

 

Best regards,

Martin

Read Full Post »

Hi fellows,

Today I released the first version of the WADA Visual Studio 2010 extension for web developers – it enables you to being able to attach processes to the VS debugger – not simple processes, but the w3wp. I guess, some of you know the issue:

  • > 1 application pools
  • > 1 w3wp processes

How could we know which process is right for being debugged by us? First, we could use one of the numerous scripts out there (like iisapp.vbs for Windows 2k3), but they provide poor integration into the VS2010 IDE (actually none at all). This is where the strengths of using WADA come into play.

What this Tool Can Do:

  • List all w3wp processes, along with the application pool names
  • List w3wp processes for a specific application pool
  • Attach a selected process to the debugger

Why should I Choose This over Scripts?

  1. You can remain in the IDE
  2. Directly attach W3WP to the Debugger (not possible with e.g. iisapp.vbs)
  3. Filter by Application Pool of Interest (not possible with e.g. iisapp.vbs)
  4. No more need for manually matching IDs (from script output) against the “Attach to Process” window’s process list

Is it Bulletproof?

No. Not at all. Please be aware that this extension comes in its first version and may contain errors and/or undesired behaviour. It also assumes that you have administrative rights on the machine you are working with it (also VS must be run in administrator mode). Hence, I’d like to emphasize that I cannot be held liable for any usage of the code causing undesired behaviour, loss of data, any damages caused to any soft- or hardware (including source code) of the user. Please do not try it in production environments. It is intended for testing purposes only.

In case you intend to test it, it would be really nice if you provided some feedback on it using the post.

Screenshot

WADA_Screenshot

Usage

  1. Go to View -> Other Windows -> WADA Advanced Attacher
  2. Select Application Pool of Interest (optional, otherwise all will be considered)
  3. Click “Get Procs” (ensure that “Only W3WP” is checked)
  4. Select Process from list
  5. Click “Attach”

Download

WADA 1.0 (Visual Studio Gallery)

Installation is done simply through double-clicking on the downloaded .vsix package.

I hope you enjoy it!

Best regards,

Martin

Read Full Post »

Howdy all,

Did you already check out the latest Keybinding Cards of the new VS 2010? If not, you can find them here:

 

http://www.microsoft.com/downloads/details.aspx?familyid=92CED922-D505-457A-8C9C-84036160639F&displaylang=en

 

They are available for C#, C++, VB, and for the newly added F#.

Here are my two of my favourite new keybindings:

 

1. CTRL + COMMA (,) (NavigateTo window)

Cross-solution searching of matching elements of all types (be it file names, source code content, etc.). It’s a really fast searching mechanism. Further information about the NavigateTo feature can also be found in my previous post “Visual Studio 2010: New Features Part 1: UI”.

2. CTRL + SHIFT + PERIOD (.) and CTRL + SHIFT + COMMA (,)

Zoom in/out the source code editor, respectively. Very handy when it comes to presentations. Remember the old days where you had to increase/decrease the font size by going to the Tools menu (while your audience had to wait for it)? Those days are gone!

 

Best regards,

Martin

Read Full Post »

Howdy there,

Now it’s around a month, that Microsoft released the .NET framework 4 to the public – so I wanted to take the occasion to give you a quick view on two nice new features:

1. Optional parameters:

You can specify any parameters to be optional by assigning it a default value directly in the list of parameters (using the assignment operator). It is quite straight-forward:

 

   1: public static void DoSomething(Int32 count = 10)

   2: {

   3:     for (int i = 0; i < count; i++)

   4:     {

   5:         Console.WriteLine(i);

   6:     }

   7:     Console.ReadLine();

   8: }

Snippet 1: The DoSomething method, specifying the count parameter as optional

This changes also the way such a method can be called, i.e. by omitting the parameter it still works fine – it just assigns the default value (in our case 10), and the code can perfectly run like that. Hence, a call to the method may look like in the following example:

   1: static void Main(string[] args)

   2: {

   3:     DoSomething();

   4: }

Snippet 2: Call to DoSomething , omitting the parameter

Even IntelliSense takes notice of the optional parameters, displaying them in square brackets, along with its default value:

image

Figure 1: IntelliSense displaying an optional parameter

Straightforward so far, isn’t it?

2. Named parameters

Now, imagine a case where we have a method that defines two required parameters, followed by an optional parameter and then again followed by another requited parameter. Let’s change the DoSomething method so it looks like in snippet 3:

   1: public static void DoSomething(String name, String surname, String city = "Munich", Int32 age)

   2: {            

   3:     Console.WriteLine(name + " " + surname + " lives in: " + city + " / age:" + age;

   4: }

Snippet 3: The changed DoSomething  method

Now it is basically possible to change the order of the parameter calling by specfying the correct names followed by a colon and again followed by the value. That’s it!

 

   1: DoSomething(surname: "Miller", name: "John", age: 32);

   2: DoSomething(age:32, surname: "Miller", name: "John", city:"Berlin");

Snippet 4: Two ways of calling DoSomething, using named parameters

This feature is especially useful if you use optional parameters, since it may not become clear which parameter is called next if you omit an optional parameter. Again, IntelliSense gives useful hints when calling a named parameter.

Enjoy!

Best regards,

Martin

Read Full Post »

Howdy people,

Me again with some more information of how both Code Contracts and Pex can be used together to write expressive tests (while still specifying a (partial) specification of the code). In the course of this article wel’ll also cover Assertions and Assumptions. In order to point out only the necessary topics, let’s introduce a new (very basic) sample project, and let’s perform the following steps:

  • Create a console application called MusicStore
  • Create the class Artist (as of Figure 1)
  • Create the class Album (as of Figure 2)
  • Enable Code Contracts checking (both static and runtime, as of figure 3)

clip_image002

Figure 1: The Artist class of the MusicStore project.

clip_image004

Figure 2: The Album class of the MusicStore project.

clip_image006

Figure 3: Enabling both Runtime Checking (Full), and Static Checking

Important: Do not forget to also check the Implicit Non-Null Obligations, as of Figure 3

The only critical point for CC should be the SellAlbum method of the Artist class. Why? Simply, because there we might have a parameter of type Album that could be NULL. And the Static Checker gives us the correct hints to it, as expected:

clip_image008

Figure 4: Expected CC’s Static Checker suggestion and warning.

So we have one suggestion to put a precondition, and an effective warning that we might be passing a parameter that could be NULL. This was predictable.

Running Pex over the method SellAlbum reveals the following results (If you need a starting point for Pex, please look at my article First steps with PEX: Automated White box Testing for .NET)

clip_image010

Figure 5: Pex results for 3 test cases, one providing the album parameter = NULL. Please note also the typical Pex exploration results’ table showing one column per parameter (in this case only album ).

What happens if we put an assertion to this critical parameter? Let’s simply add one, as shown in Figure 6:

clip_image012

Figure 6: Adding an assertion using a call to the static method Contract.Assert(bool condition) of the CC framework.

It makes sense to assert a number of AlbumsSold higher or equal to 1 (after 1 album has been sold), right? Does putting an assertion have an impact on Pex? Of course! Let’s run it again to see how:

clip_image014

Figure 7: Effects on Pex of using Code Contracts’ Assertions. Pex clearly identifies this as an assertion failure, hence letting the generated test case fail. Line 2 (highlighted the additionally created Pex test for the Code Contracts assertion).

So far, so good. Let’s look at Figure 6 again. We can also put such an assertion for the album object. This clearly makes sense – since selling an album should increase the album’s TimesSold count. Let’s do this in Figure 8:

clip_image016

Figure 8: Added another assertion for the album.TimesSold property.

And immediately, let’s look at the Static Checker warnings and the generated Pex test cases (Figures 9 and 10):

clip_image018

Figure 9: One more unproven assert warning for our newly added Assertion in the SellAlbum method. This was expected. Let’s run Pex again!

clip_image020

Figure 10: Line 3 shows the newly generated (and failed) test case of Pex. Again, this was expected.

Great coverage – but What About the Meaning?

This is a good question. Is this still an expressive test? Let’s recap the meaning. We could have an Album -type parameter passed, which could be theoretically NULL. Would it make any sense to then test its property TimesSold? I am sure, we can agree on that this would not be the case.

So, what we need, is the possibility to prevent Pex from generating test cases in such a case, hence producing only meaningful tests. And who is going to provide us with such a capability?

Code Contracts’ Assumptions

Important: Assumptions only work when the Full contract option is checked in the Code Contracts pane (under our project’s properties)

Figure 11 gives a brief example of how to put such an assumption into our code of the SellAlbum method.

clip_image022

Figure 11: Creating assumptions.

Figure 11 needs some explanations:

The first three assumptions simply protect us from getting the current object, the passed album, or the passed album’s artist as NULL. Makes sense, so far. The following two assumptions ensure that this.AlbumsSold and album.TimesSold both are non-negative values.

(Note also that now we put our assertions INSIDE the artist comparison’s block – makes sense, since we do not need to assert when there happened no increase of AlbumsSold and TimesSold properties).

What do We Expect?

Well, we pretty much thought at everything, didn’t we? So we expect Pex to not issue any errors or failures again. A simple re-run of Pex will show us the result, as can be seen in Figure 12.

clip_image024

Figure 12: Unexpected error on line 3, a failed assertion.

An unexpected failure? How could that happen? Let’s look at what the parameters looked like in the case of failure:

image

Did you see it? AlbumsSold is equal to int.MaxValue ! I guess, I do not need to explain what happens, if you try to increase an integer (in SellAlbum ) which is already equal to its maximum value! But why did that happen?

Simply put, this is one of the boundary test cases we explained in First steps with PEX: Automated White box Testing for .NET article. Pex guesses from the type of variables which are the boundary values (and also intermediate values).

To summarize shortly & sweetly today’s lecture:

Code Contracts & Pex: meaningful, expressive tests

(by preventing test case generation for assumed parameter values)

Let’s stop here today. There are more interesting topics regarding Code Contracts and Pex, and I am quite sure this will keep us busy for another while!

Enjoy playing around with Pex and Code Contracts, and see you next time!

Best regards,

Martin

Read Full Post »

Howdy folks,

Here we are back again with an introduction of the new features of the upcoming Visual Studio 2010. Its release has been postponed to the 12th of April, so in the meantime we’ll have to stick to the Beta 2, which is pretty stable already. There are so many improvements that we’ll have to divide it into multiple parts. Let’s dive right in!

1. UI: WPF-Based

The UI is now WPF based, which means a better usability and more extensibility options for us developers. Clearly, introducing VS2010 as a WPF-based application is a big push in the direction of visualization and diagramming. We’ll see later how this can be performed using the new IDE.

The editor, for example, is now WPF-based. Cool, but what does that mean for us? Here are the advantages:

Change font size w/ mouse only, or better: No more Options->Change font size during presentations!

Extension Manager allows easy-to-install-and-use add-ins: Also from online galleries – Single click install and enabling!

Highlighting of related variable/method names (Figure 1)

clip_image002

Figure 1: Highlighting related variable. Note that the highlighter correctly references only the name variable passed as a parameter

You can navigate between the highlighted elements using CTRL + SHIFT and the ARROW keys!

2. Intellisense – Improvements:

Method Matching: When VS2010 brings up the list of available methods (after you typed something), it performs not a simple .StartsWith name comparison, but a .Contains. This leads to the results shown on the next screenshots:

Filtered list is gone: When typing letters, the auto completion list that pops up won’t give you all objects/methods/variables that start with the same letter, but only those who are truly related. Consider Figure 3: We typed IF. In the old version, VS would have brought up not only the items shown in the completion list, but possibly many many more, all starting with I (but not containing or continuing with F). Now the IntelliSense search is narrowed, which makes it a lot easier for the developer to select the correct entry.

clip_image004

Figure 2: Highlighting the related object/variable/method.

Case sensitivity: Another nice feature highlighted in figure 2 is the Pascal-Case typing of the capital letters IF, which brings correctly up our method, since its signature contains both I and F as of the method name. Try typing If (f is lowercase), and you won’t find the IsFasterThan method in the auto completion list anymore.

3. References dialog improvements

Remember the Add References dialog in figure 3?

clip_image006

Figure 3: Add references underwent some perception changes.

First of all, Microsoft realized that most people are using it to reference other projects, so they brought up the Projects tab by default. But that’s not all: We all LOVED to wait 30 seconds for the list of .NET or COM objects to appear, right? Because of that, while we are browsing by default the projects, VS2010 is asynchronously loading the available assemblies already. Saves time and nerves.

4. Search and Navigation

Let’s press CTRL + , anywhere in the editor. The window Navigate To will appear, providing us a very powerful search across the entire solution. The search results are updated as we type. From here, we can navigate directly to the found item. Figure 4 shows the dialog.

clip_image008

Figure 4: The Navigate To dialog is a powerful search and navigation mechanism, providing also essential information about the found items. Big improvement over the VS2008 style’s CTRL+SHIFT+F (and subsequent find results crawling without navigation to the desired item)!

5. Call Hierarchy

Remember the Find All References option in the editor’s context menu? It provided us information about where a method/variable has been used. Tell you what. We have a much more powerful way of doing this now: The Call Hierarchy option (Figure 5).

clip_image010

Figure 5: Context menu for the IsFasterThan method, highlighting the new View Call Hierarchy option.

This is the result: A list of all callers (“Calls To”) and callees (“Calls From”) of IsFasterThan (Figure 6). Every caller/callee can be expanded into its own callers/callees. As of figure 6, e.g. Main. This is a really expressive feature which outperforms Find All References by far. However, a possible drawback might be that you could expand the list to infinity by alternating the caller/callee relationship. Figure 6 shows the resulting

image

Figure 6: The View Call Hierarchy window, showing callers/callees of IsFasterThan.

6. Project dialog with search and .NET version selection

Figure 7 shows the improved New Project dialog.

clip_image012

Figure 7: The NewProject dialog. Please note the search field in the right upper corner and the .NET framework dropdown list (center), where now also version 4 of the .NET framework is available.

7. Code Snippets

The code snippets are accessible via the Tools menu, or by pressing the shortcut CTRL + K, CTRL + B

Additional snippets are now available also for HTML, JavaScript and SQL. In sub-categories you can find the different snippets already provided by VS2010. Moreover, you can add your own snippets (as we already know from previous VS versions), as well as remove and import snippets. Figure 8 shows the Code Snippets dialog.

clip_image002[1]

Figure 8: The Code Snippets dialog, showing the newly available languages, as well as subcategories in the Code Snippets Manager.

8. Environment settings: Code Optimized

One more newly available feature is a new default environment setting (remember you had to choose which default settings you wanted to use when starting VS2010 for the first time?). There is one newly available feature which will simply allow you to reduce your viewport to only the code when developing (hence removing the designer). If you have already chosen your first-time-startup environment settings: Don’t worry! The next screenshot explain how you can access the new Web Development (Code Optimized) default environment setting. First, choose Tools –> Import and Export Settings.

image

Figure 9: Import and Export Settings wizard. Choose Reset all settings here. Then you will be prompted whether or not you want to save your current settings. Choose as you wish there. Then proceed.

image

Figure 10: Default environment settings. Note the Web Development (Code Optimized) option, which is new to VS2010. Choose it and VS will immediately switch to those settings, removing e.g. the designer buttons and providing you with a much more lightweight code editor window. Very handy for developers who want to only focus on the code.

9. Conclusion

So I’d say this is about it for this time. Of course there are a lot more features which need to be covered.

The next lessons will deal with creating customized startup pages for VS2010, and introduce the new language features and tools of Visual Studio 2010.

In the meantime, enjoy exploring VS’ new capabilities and features, and hang on till the next time!

Best regards,

Martin

Read Full Post »

Older Posts »