June 19, 2014

Exceptions exist for a reason – use them!

C# and all CLR-compliant languages support a fantastic facility to ensuring code quality. That facility is the Exception. Sadly, it is an often under-utilized facility. How many times have you seen code that checks for an object’s validity? If, like … Continue reading 

Webinar Recording: Merging Refactored Code – ReSharper Meets SemanticMerge

The recording of our June 17th webinar, Merging Refactored Code – ReSharper Meets SemanticMerge, is now available on JetBrains YouTube Channel.

In this webinar, Matt Ellis (JetBrains) hosts Pablo Santos (SemanticMerge) who runs through a number of refactoring examples, from the seemingly trivial (yet essential) to complex structure modification scenarios, and demonstrates how to refactor with ReSharper and later get it merged with Semantic.

Pablo talks about the challenges of merging complex refactorings and demonstrates how SemanticMerge simplifies it, parsing the code into a syntax tree then reasoning about it as code rather than text (or text with heuristics), and merges accordingly.

The slides used in the webinar are available on Slideshare.

About the Presenter:

Pablo SantosPablo Santos is the founder at Codice Software, the company behind Plastic SCM and SemanticMerge. Codice started in 2005 and since then Pablo played different roles ranging from core engineering to marketing, business development, advertising and sales operations. Nowadays he plays a dual role as lead of software engineering and product manager for both Semantic and Plastic.

Profiling ASP.NET vNext using dotMemory and dotTrace

With ASP.NET vNext (working title), Microsoft is making some bold moves towards opening up development and deployment options for building applications. For starters, we no longer have to install the full .NET framework on our servers: ASP.NET vNext lets us deploy our own version of .NET on an app-by-app basis. Next, the project model is being migrated to being just a project.json file describing dependencies and some optional configuration, much like we write apps in NodeJS.

ASP.NET vNext is still in an early preview, but it never hurts to explore and test-drive what’s going to be the next generation of .NET. And when writing code for it, we may want to inspect performance and memory of our applications to verify we don’t have any issues there. And what better tools than dotMemory and dotTrace to do that?

Setting the correct CLR type

Before we start profiling, it is important to know that profiling currently only works when the Desktop CLR is active. The new Core CLR does not (yet?) expose the same profiler hooks.

Checking if the correct CLR is active can be done from the command line using the kvm list command.

Output of the kvm list command

Make sure that the active CLR (marked with an *) shows the svr50 runtime. If it’s svrc50 that means we’re on the Core CLR and have to switch to the Desktop CLR using the kvm set <pick the correct version from the above list> command.

Attaching to an already running ASP.NET vNext process

After starting dotMemory or dotTrace, hit Attach To Process on the toolbar. This will give us a list of all running processes on our local computer. Both profilers can also attach to processes running on remote machines. From this list, find the klr.exe process. When running multiple ASP.NET vNext applications on our machine, it will be a bit tricky to find the correct one.

Attach profiler

We can provide additional options and even make use of the profiler API in our ASP.NET vNext applications. Hitting Run will attach the profiler which will behave identical to profiling “classic” .NET applications. For example in dotMemory, we can see the memory usage (unmanaged and managed heaps) in real-time:

dotMemory memory usage of project K ASP.NET vNext

In dotTrace we can see the subsystems used by our code and drill down to the function or thread level.

Profiling ASP.NET vNext in dotTrace

Starting an ASP.NET vNext process with profiling enabled

When attaching to an already running process, some options will be unavailable. For example, dotMemory will be unable to collect memory traffic for an already running application. It will be impossible to pick a more detailed profiling mode for dotTrace, such as Tracing or Line-by-Line profiling. For these options to be available, we have to launch the process with profiling enabled from the start.

Running ASP.NET vNext applications is done using the k run or k web commands. These are aliases for the active runtime which is located under %USERPROFILE%\.kre\packages\<seleced runtime>\. From dotMemory and dotTrace, we can use the Profile | Standalone Application menu and enter the startup details for our ASP,NET vNext application.

Profiler configuration

Here’s what we have to specify:

  • Application: the ASP.NET vNext runtime to use. This will depend on which runtimes we have installed on or system but will look like %USERPROFILE%\.kre\packages\<seleced runtime>\bin\K.cmd.
  • Arguments: the arguments we would typically pass to the k command. If we start our application with k web, then web would be the argument to specify here.
  • Working directory is the path where our application and its project.json file are located.

Using this approach, we can now set all additional profiler options. dotMemory allows collecting memory traffic while dotTrace will let us perform Line-by-Line profiling and specify the measure used. Run will launch the application and lets us capture a snapshot we can investigate later.

Give it a try! Even with a new CLR in town we still have to care about memory and performance of our applications. Here are some resources to get started with dotMemory and dotTrace:

May 27, 2014

ASP.NET MVC, Bootstrap, and Internet Explorer Compatibility View

Works on My Machine…or Does It?

It's always frustrating when you're working on a project, and everything looks good when you're running it from Visual Studio, and then you deploy to your web server, and suddenly something's not rendering correctly. In this post, I'll give you some tips for troubleshooting these problems when the target browser is Internet Explorer.

The Project

I'm working on a project that uses ASP.NET MVC 5 and leverages the out-of-the box support for the Bootstrap UI framework.

Having completed the initial phase of development, and wanting to provide a copy of the app for the client to test on their own network, I arranged to have all the necessary stuff set up (DB, web server, etc.), and dutifully published the bits to the web server location. So far, so good.

The Problem

When I went to run the application, I discovered a strange UI issue, where the div on the page that contains the page title (in the default template, it's the one that uses the "jumbotron" class, was riding up underneath the navigation bar, and the navigation bar was taller than normal, which resulted in the text inside the div being partially cut off:

CompatView7

This isn't the first time I've seen the issue, as I'd run into it when testing on local IIS instead of the default of IIS Express. So when I saw it again, I decided to open up the Internet Explorer F12 developer tools (I'm running IE 11 on Windows 8.1, Update 1), and see what I could find. I used the Select Element button in the DOM Explorer tab to examine the div that was riding up, and discovered in the Console that the browser was using document mode 7 (rendering as if running IE7), as shown below (click for larger image):F12Console

Since I wasn't sure what was causing this, I flipped over to the Emulation tab to investigate. Helpfully, the Document Mode selector indicated that the document mode was defaulting to 7 "Via intranet compatibility settings," the text of which includes a link to MSDN documentation on the Emulator tab:

F12Emulation

Those docs included this helpful bit of info:

New in Windows 8.1 Update, when the Document mode has been changed from the default, you'll be shown a reason why. Here's a quick list of the reasons with explanations:

Brilliant! That last item is exactly what I'm seeing, and so I brought up the Compatibility View settings (click on the sprocket icon in the IE toolbar, and it's the option near the bottom. That brings up the following dialog, which shows the checkbox in question:

CompatibilityViewSettings

If you're wondering why it renders properly in IIS Express, but not in IIS, that's because it's hitting the "localhost" URL, so Internet Explorer does not treat it as an intranet site. By contrast, when I was viewing the site in IIS, I was doing so by the server name, so the Compatibility View defaults for intranet sites kicked in.

Back to the F12 developer tools, the document mode selector also included a link (the "i" icon) to this helpful article on modern.ie that explains the document modes and how developers and administrators can override the default behavior.

The Solution

Now, if I want to test and make sure that this is truly the issue, I can just uncheck the checkbox, and close the Compatibility View dialog, and voila! The site now renders as expected:

CompatView_Off

But that's not a practical solution for end-users. If I had the ability to set group policy for my users, I could use GP to tell IE not to render this site in compatibility view, but most developers don't have that as an option.

Another option is to use the x-ua-compatible META tag to specify the desired mode, like so:

<meta http-equiv="x-ua-compatible" content="IE=9">

Since the project I'm working on targets IE8, I could use IE=8 as the value. But it turns out that as long as the tag is present and has a valid value, the page won't default to compatibility view. I ended up setting the value to IE=11 (you could also use IE=Edge to always target the latest version, but that didn't work for my needs since I needed to target IE8), which clears up the rendering issues without limiting newer versions of the browser to the feature set supported by IE8. IE8 users won't get fancy CSS animations and such, but once the organization is able to migrate to a newer browser version, no change will be needed to the meta tag for them to take advantage of such features.

Note that you can also specify the compatibility mode using a custom HTTP header, which comes in handy if you want to enforce a specific mode at the server or site level, without having to modify all of the pages and/or layouts in a given site.

More on the Problem

After doing some more spelunking, it turns out that at least part of the problem I was running into with the rendering was coming from the fact that I started the project with an Empty ASP.NET project template, and added the features I wanted, including Bootstrap, etc. As a result, my project didn't have the Site.css that is included in the default MVC 5 template, and one of the style rules it adds is a padding-top value of 50 pixels. That rule pushes the body content below the navigation bar, so it doesn't ride up under, as I was seeing. I still haven't figured out quite why the navigation bar gets taller under an IE7 document mode, but I've got things working well for the target browser, so I probably won't spend more time troubleshooting something that's no longer an issue, even though there's a part of me that wants to figure it out.

Conclusion

When things go wrong in rendering your site, it can be very frustrating, particularly when a site that was working in IIS Express suddenly stops working when you test it in full IIS.

Fortunately, the IE Developer Tools keep getting better with every generation, and for this issue in particular, the Emulation tab turned out to be a lifesaver, giving me the info I needed to locate and correct the problem, along with links to documentation to better understand the underlying settings. So the next time you run into an issue, just hit F12, and see what you can find!

Did you find this post useful? How about using the Share button above to pass it along to friends and colleagues? And I welcome your comments and experiences in the comments section below.

May 22, 2014

Cisco AnyConnect and Hyper-V - Connect to a VPN from Inside a VM Session

Clients and VMs and VPNs, Oh My!

As regular readers of this blog may be aware, I recently hung up my technical evangelist hat, and made the jump back into full-time consulting.

Consistent with best practices, I decided that when working with a new client, the best course of action would be to set up a new virtual machine to keep all of the development environment, tools, and files isolated from anything on my host machine, which helps minimize the risk that installing the latest bleeding-edge tools (which are good to have to stay ahead of the learning curve) don't endanger the work I'm doing for the client.

With my current client, I need to be able to access files, servers, and tools on their remote network, which they enable via the Cisco AnyConnect VPN client software. So far, so good. I had no trouble at all installing and connecting with this software from my laptop over my FiOS connection. Just like being at the office.

The Tricky Part

Unfortunately, the VPN connection does not pass through to the virtual machine I set up, using client Hyper-V on Windows 8.1 (update 1). Which is interesting, because while I was onsite recently, when I connected to the LAN directly via cable, that connection would pass through to the VM. But since I'm not a networking geek, I'll leave that to others to explain.

So, the next step was to try installing the VPN client software in the VM itself. But it was not to be. The client software installs fine, but I found that when I tried to connect, I'd get the following error message:

AnyConnect_NoRemote

OK, so now what? Well, truth be told, since I didn't have time to troubleshoot this immediately, I set the problem aside for a while, which can be a good way to let your brain work on the problem while you're doing other things.

Or sometimes, you get lucky...this was one of those times.

Basic or Enhanced?

By good fortune, this morning, I ran across a brief blog post by Osama Mourad (No, not the same person who runs one of the CMAP Special Interest Groups), which suggested that connecting the VPN was possible "if connected to the VM using Hyper-V Manager." A bit cryptic, but it gave me hope that it was at least possible.

Here's where luck comes in. I was trying to see if there was a different way to connect to the VM from Hyper-V Manager, when I noticed that if I did not have the VM session window full-screen, there is an icon at the end of the toolbar that looks like this:

BasicSession

That button switches the VM session from Enhanced Session Mode (the default in newer versions of Hyper-V), which uses a Remote Desktop Connection to interact with the VM, to Basic Session Mode, which provides simple screen, keyboard, and mouse redirection.

And beautifully, it turns out that in Basic Session Mode, connecting the VPN works just fine. And once connected, you can switch back to Enhanced Session Mode, and the VPN will remain connected.

Conclusion

Using a virtual machine is a good practice for keeping your client environment isolated from your day-to-day experiments or bleeding edge tools, etc. And it also has the advantage of making the environment portable. You can store the VM files on a portable drive, or copy them from one machine to another if you need to migrate systems.

But along with the convenience comes the occasional head-scratcher or stumbling block. I hope that this post will help anyone else who runs into this particular issue resolve their problem.

You can learn more about Enhanced Session Mode from this TechNet article. My thanks to Osama for the clue that helped me track down the solution.

January 05, 2013

Speaking at SQL Saturday #184 (North Haven CT) 03/02/2013

I am presenting at SQL Saturday #184 event in North Haven CT on March 2nd 2013. The presentation topic is about PowerShell and SQL Server – ‘Get-PowerShell | Get-SQLServer’.

Primarily aimed at SQL Server DBAs & developers – it’ll introduce PowerShell and show how it is applied with SQL Server and related tasks. More details are here at the SQL Saturday #184 session site.

January 01, 2013

Microsoft MVP Award for 2013: SharePoint Server

MVP-Rect1

My thanks to Microsoft for the Most Valuable Professional (MVP) Award for 2013 - 6th time in a row since 2008!  The award is based on SharePoint Server and working with the CTDOTNET/CTSPUG developer groups and also actively presenting and participating in numerous events – details are the MVP Profile site.

More about plans that are in the works for this year is coming shortly - some exciting stuff for the community!

April 28, 2011

Siemens Smart Grid Innovation Contest

1The Smart Grid Innovation Contest is an open international competition to find new, sustainable Smart Grid business models and technologies for the near future.

Siemens believes in the future of the Smart Grid for a more sustainable world – a vision of intelligent, flexibly controllable power generation, distribution, and consumption. The breakthrough of Smart Grid applications, though, strongly depends on attractive business models that combine technologies and economic benefits.
The Smart Grid Innovation Contest consists of two phases: during the first phase, ideas are generated and developed in a collaborative community. In the second phase, universities are invited to submit research proposals to further elaborate and develop ideas.

Idea contest (for everyone) from April 13 to May 31 2011
 
Call for proposals (for universities) from October 4 to November 30, 2011. Siemens will award €15,000 and a workshop trip to Berlin together with Siemens Smart Grid experts to the five best ideas and the most valuable contributions. In a joint effort with several universities, more than €1,000,000 will be invested to translate the participants’ ideas into innovation. The contest addresses your creativity and your local expertise in making energy systems smarter and more environmentally friendly.

Watch an idea grow, through suggestions, comments and ranking, into mature and realistic innovation!

Full competition details and rules at:
http://www.siemens.com/smartgridcontest

September 22, 2010

Build a Quadrocopter using .NET Micro Framework and win a VS2010 + MSDN Subscription

For those of you are interested or working on a Quadrocopter controlled by the .NET Micro Framework, there is a contest where the winner of a flying Quadrocopter will get a free VS2010 license including 1 year MSDN subscription.

Check my blog at http://netmicroframework.blogspot.com/

September 28, 2008

IndiaStockQuotes Version 1.2.1

It has been a long time since I actually worked on the IndiaStockQuotes component. Just had sometime over the weekend and fixed some bugs in the component and got out a new release. Also upgraded the component from .NET 2.0 to 3.5. I dont yet use any 3.5 specific features, so you should be able to recompile the source agains 2.0 and still get it to run.

Check it out at India Stock Quotes

September 26, 2008

Moving a project from VS 2005 to VS 2008

When you open a VS 2005 project in VS 2008, Visual Studio offers to migrate the project to the new format. Usually there should be no problem with this and all your project files, solution files, Test cases etc should move seamlessly to the 2008 format.
Targettedframeworksetting
But if you do build your project you will notice that your output assemblies actually target .NET Framework 2.0 and not 3.5. This is basically because the migration retains the targeted framework to make sure you application does not fail. The method to change this setting after migration is not easy to find.

For VB projects, this setting is actually hidden inside, My Project -> Compile -> Advanced Compiler Options dialog. Obviously, this is not very easy to find. (See Image)

In C# projects this setting is a lot easier to find in Project Properties -> Application Tab itself. I am not sure why the VB team actually made this setting so difficult to find.