Windows 8 Hyper-V errors with "could not be started because the hypervisor is not running"

Just recently setup a new machine with Windows 8 and decided to install Hyper-V so that I could run windows XP for some of my legacy applications that will not run under Windows 8 64 bit. After installing Hyper-V components I attempted to setup a new virtual machine and start the install process when I was faced with the following error: "could not be started because the hypervisor is not running"

It turned out that I needed to run the following command

bcdedit /set hypervisorlaunchtype auto

After running the above command and restarting my machine it now works. Hope this helps save someone else hours they cannot back due to this issue.

Calling WCF Service using LINQPad

First, if you are a .NET developer and you are not using LINQPad yet go and check it out at www.linqpad.net. They offer a free version that is the same as the paid version but without intellisense and the pricing to upgrade to the full version is well worth the productivity gain you get.

Ok, with that out of the way let me get to the issue I came across and how I solved it.

Issue:

Created an assembly project in order to create a proxy to a web services using .NET Service Reference which I would then use in LINQPad to do some testing against my web service. Created a new linqpad script and added my reference to the assembly and wrote a method to call my web service. Upon executing I received an InvalidOperationException:

Could not find default endpoint element that references contract 'WCFAcctMgmtWebServiceReference.AccountManagementWebservicesSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

That is odd I can see that my assembly includes a file Proxy.exe.config that has the necessary service reference information

1
2
3
4
5
6
7
8
9
10
11
12
13
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="AccountManagementWebservicesSoap" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://ws.domain.com/acctmgmt/v4/service.asmx"
            binding="basicHttpBinding" bindingConfiguration="AccountManagementWebservicesSoap"
            contract="WCFAcctMgmtWebServiceReference.AccountManagementWebservicesSoap"
            name="AccountManagementWebservicesSoap" />
    </client>
</system.serviceModel>

So why was it not working?

Answer:

Well it turns out that LINQPad needs to have this configuration information included in a file it uses since it is the application executing the proxy. At first glance one might assume they would place it in the the file included with LINQPad called LINQPad.exe.config but that would result in the same issue.

Instead you need to create a file in the same directory that LINQPad is installed in and name it linqpad.config

Adding the following to my new file resolved the issue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="AccountManagementWebservicesSoap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://ws.domain.com/acctmgmt/v4/service.asmx"
                binding="basicHttpBinding" bindingConfiguration="AccountManagementWebservicesSoap"
                contract="WCFAcctMgmtWebServiceReference.AccountManagementWebservicesSoap"
                name="AccountManagementWebservicesSoap" />
        </client>
    </system.serviceModel>
</configuration>

 Hopefully this article will save someone the time I spent figuring this out.

Running FSCK on an LVM (Logical Volume Manager) using Linux Rescue Disk

I am not a linux expert and so when I have problems from time to time I usually have to go searching for the answer. It usually takes me looking at several articles to get my answer and when I am finished I always try and put together a article that has everything I need to know in once spot. Please feel free to correct or suggest a better alternative if you come across this article and would like to provide feedback.

Yesterday I had a server crash and when I logged into the console it was showing a kernal panic!!

I rebooted and the same thing happened over on every reboot. This machine had some problems in the past with the disk going into read only mode so I assumed the issue was related to something wrong with the disk. So I grabbed a CentOS disk and booted up with it and booted into resuce mode and skipped the step that would mount the disks.

Once in I attempted to run fsck /dev/sda1 but I got an error back indicating it did not recognize the volume as EXT2. Searching around I found the following solution if you are using a LVM.

 Perform all of the following commands in the following order. I provided a link for each command if you are interested in knowing more about what each of the commands do.

Scan all disks for partiitions: 

Scan all disks for volume groups and build /etc/lvmtab and /etc/lvmtab.d/* which are the database for all other lvm commands:

Change attributes of a logical volume

Scan all disks for logical volumes

Then I was able to run fsck as follows

fsck -f /dev/VolGroup00/LogVol00

Which of course reported TONS of errors and fixed them up. I do not claim to be an expert but this worked for me. Hopefully this information will help someone else out in the future.

Getting LINQPad to read your applications App.Config settings

I have been using LINQPad for a while now and I love it. This utility allows me to write and execute immediately code that I am working out before I put it into my project. However on occassion I need to reference assemblies from my project that are getting settings from the applications App.Config such as SQL connection strings etc...

Each time I would run into this I would search and not come up with how to get my app.config settings to be honored by LINQPad and today I finally found how to do it so I thought I would write up something really quick to show others how to accomplish this.

1) Find the path that LINQPad uses for its configuration file by excuting this: AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.Dump()

This returned for me the following: C:\Program Files\LINQPad4\LINQPad.config

I was suprised this returned LINQPad.config instead of LINQPad.exe.config which is what you would typically expect since most .NET applications name the file the same as the executable.

2) Take your App.config and copy it to the location above naming the config file whatever yours returned. In my case it was LINQPad.config

3) Close LINQPad or the TAB that you have opened to execute your assembly and reopen to get LINQPad to read the configuration file.

Now execute your code and you should see that LINQPad is now pulling in your settings as needed.

 

Creating custom EventLog source in windows azure

If you have tried to execute the following code on windows azure then no doubt you have run into a security violation. In fact if you try and run the same example on your local machine you will also get the same error as creating an custom event source on windows requires that it be performed by an Administrator.
 
1
2
3
4
if(!EventLog.SourceExists("MyCustomSource"))
{
    EventLog.CreateEventSource("MyCustomSource", "Application");
}
In order to create a custom event source in windows azure do the following:
 
1) Create a cmd script using notepad with the following content
 
EventCreate /L Application /T Information /ID 900 /SO "MyCustomSource" /D "Custom source for logging my custom events" 
 

Here are the options for EventCreate.exe /?
 EVENTCREATE [/S system [/U username [/P [password]]]] /ID eventid
            [/L logname] [/SO srcname] /T type /D description

Description:
    This command line tool enables an administrator to create
    a custom event ID and message in a specified event log.

Parameter List:
    /S    system           Specifies the remote system to connect to.

    /U    [domain\]user    Specifies the user context under which
                           the command should execute.

    /P    [password]       Specifies the password for the given
                           user context. Prompts for input if omitted.

    /L    logname          Specifies the event log to create
                           an event in.

    /T    type             Specifies the type of event to create.
                           Valid types: SUCCESS, ERROR, WARNING, INFORMATION.

    /SO   source           Specifies the source to use for the
                           event (if not specified, source will default
                           to 'eventcreate'). A valid source can be any
                           string and should represent the application
                           or component that is generating the event.

    /ID   id               Specifies the event ID for the event. A
                           valid custom message ID is in the range
                           of 1 - 1000.

    /D    description      Specifies the description text for the new event.

    /?                     Displays this help message.


2) In your windows azure web role  create a folder called Startup and place the CMD file created above in it
 
3) Right click on the cmd file in solution explorer and select properties and set the "Copy to output directory" to "Copy if newer"
 
 
4) Open the ServiceDefinition.csdef file and add the startup section as shown below. 
 
 
Finished. Now wasnt that simple ;-)
 
Ok, so now you no longer need code that checks if it exists as that will throw a security exception. Now you just write to the EventLog as usual but now using your new custom source.
 
1
EventLog.WriteEntry("MyCustomSource", "This is my event log message")
 
I also want to give credit to Walter Mayers for pointing out the cmd script approach to creating the custom event source

Installing OpenWebmail on BlueOnyx server

I have been in the process of evaluating the BlueOnyx distribution that replaces the older BlueQuartz web hosting control panel. However one of the short comings is that BlueOnyx does not currently incorporate a webmail interface.

So today I decided to work out what it would take to bring over Openwebmail to the BlueQuartz platform so that as I migrate users to the new platform they will have the same webmail interface that they have been used to. I will also be later installing RoundCube as a second webmail option but for now I want to maintain as much as possible backwards compatibility.

Here is the installation steps:

1) Grab the latest install of openwebmail from: http://openwebmail.acatysmoof.com/

2) Download file to /var/www

3) Extract contents

  • tar -xvzf openwebmail-2.53.tar.gz
  • This will extract files to 2 different directories
    • /var/www/cgi-bin/openwebmail
    • /var/www/data/openwebmail

4) Change permissions on created folders

  • chown root:mail /var/www/cgi-bin/openwebmail
  • chown root:mail /var/www/data/openwebmail

5) Install Text::Iconv perl module required

  • yum install perl-Text-Iconv

6) Add apache config file to set /webmail alias for openwebmail

  • Create file /etc/http/config.d/httpd_openwebmail.conf
  • Place in file the contents of this file: http_openwebmail.conf

 

7) Edit the openwebmail configuration file so that it reflects proper defaults

  • nano -w /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
  • Edit these entries to look as follows.
    • ow_cgidir                         /var/www/cgi-bin/openwebmail
    • ow_cgiurl                         /openwebmail
    • ow_htmldir                        /var/www/data/openwebmail
    • ow_htmlurl                        /data/openwebmail
  • Here is a complete example file that is from my system that reflects not only the above changes but other changes I make from the default to support our current user preferences.
  • openwebmail.conf
    • Note if you enable spell check like my above example configuration make sure you install the aspell library
    • yum install aspell
  • You should open /var/www/cgi-bin/openwebmail/etc/openwebmail.conf.help if you want to understand all the possible settings that can be made

8) Edit dbm.conf

  • nano -w /var/www/cgi-bin/openwebmail/etc/defaults/dbm.conf
  • Change dbm_ext     .db      to      dbm_ext     .pag

9) Restart httpd

  • /etc/init.d/httpd restart

10) Initialize openwebmail by running /var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

11) Finished - Open your browser and go to one of your websites located on the server and append /webmail to the url and if all is well you will have running webmail on your BlueOnyx machine.

PlayOn Plugin - TECH.ED 2011

Well I really enjoyed creating the MIX 2011 PlayOn plugin that I decided to do the same for TECH.ED 2011. I am going to do a bit more research and see if in the next release I can provide a folder for each year as they have published all of the archives for TECH.ED and MIX back to 2008.

When you access the TECH.ED 2011 channel you will see it grouped by All Sessions - Provides a entire list of all sessions, By Category - groups each of the sessions based on the category it falls under, By Speaker - groups each of the videos by the speaker

TECHED2011.plugin (33.50 kb)

To install download the file and then open your playon software and go to the Plugins tab. At the bottom of that screen click Install and browse out to the file.

**** UPDATE ****

Just updated the download with a new version that supports checking for updates and cached the RSS feed so that subsequent access to the sessions is very quick. 

PlayOn Plugin - MIX 2011

I have been using PlayOn software to view online content via my XBOX for about 6 months now and while it is really cool I dont find myself using it as much as I thought I would. However one thing I have enjoyed is using it to view last years MIX 2010 content that someone provided a plugin script for. However as of MIX 2011 they reformatted the website and now the previous plugin does not work.

So this prompted me to take a look at the PlayOn API and see if I could either fix the script or create a new one. In the process of things I decided to write my own. If you are using PlayOn premium feel free to download and install my plugin to view the MIX 2011 sessions. 

It is truly a joy to sit in front of my TV instead of my computer and watch these sessions. When you access the MIX 2011 channel you will see it grouped by All Sessions - Provides a entire list of all sessions, By Category - groups each of the sessions based on the category it falls under, By Speaker - groups each of the videos by the speaker

MIX2011.plugin (30.50 kb)

To install download the file and then open your playon software and go to the Plugins tab. At the bottom of that screen click Install and browse out to the file.

**** UPDATE ****

Just updated the download with a new version that supports checking for updates and cached the RSS feed so that subsequent access to the sessions is very quick.

Fix error: Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance.

For anyone using Visual Studio and trying to add a SQL Database File and getting the error: "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance." you might want to give the following steps a try.

 

Make sure you have enabled user instances. Open SQL Server Management Studio and connect to .\SQLEXPRESS

Run the following query

exec sp_configure 'user instances enabled', 1
go
reconfigure

Now restart SQL

Now you must delete the files that SQLExpress creates when adding instances if they already exist.

Go to your Local Settings folder.

Windows 7: C:\Users\YOUR_USERNAME\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS

Windows XP: C:\Documents and Settings\YOUR_USERNAME\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS

Delete all files in the above folder

Hopefully if the above worked you will now be able to create databases inside VS with no issue.

ASP.NET CustomValidator that validates multiple controls using both Server Side and Client Side scripting

ASP.NET has some nice validation controls built in that can help make validating forms much easier. Listed below are a few of the available controls.

RequiredFieldValidator – Ensures that the user does not skip a field that has some requirement for being selected or filled out.

CompareValidator - Compares a user's entry against a constant value, against the value of another control (using a comparison operator such as less than, equal, or greater than), or for a specific data type.

RangeValidator - Checks that a user's entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, and dates.

RegularExpressionValidator - Checks that the entry matches a pattern defined by a regular expression. This type of validation enables you to check for predictable sequences of characters, such as those in e-mail addresses, telephone numbers, postal codes, and so on.

All the above controls have you specify the ControlToValidate which can be any one of these types: DropDownList, FileUpload, ListBox, RadioButtonList, TextBox, HtmlInputFile, HtmlInputPassword, HtmlInputText, HtmlSelect and HtmlTextArea

But what if you want to perform validation against a control type not listed or on multiple controls? Have no fear as the  CustomValidator control allows you to write your own server side and client side validation logic and get as complex as you want.

All of the previously mentioned controls require you to specify the control you want to validate via the poperty ControlTValidate, however with CustomValidator you can leave it blank which then leaves you to specify logic server side and client side to perform any validation you like.

So let’s take this to the real world. Recently I was faced a scenario that could not be handled by the standard set of validation controls.

Example) A series of 5 independent checkbox controls and at least one of them was required to be checked. Plus if Other is selected then you must fill in the textbox.

image

So the behavior should be that you must select at least one checkbox and if none selected then you will get an error “You must select at least one checkbox” and if the Other checkbox is selected then they must also supply text in the texbox field.

Here is a snippet from the ASPX source showing the controls and the CustomValidator

Code Snippet
  1. Please select the skill's you have:
  2. <br />
  3. <asp:CheckBox ID="checkBoxCSharp" runat="server" Text="C#" />
  4. <br />
  5. <asp:CheckBox ID="checkBoxASPNET" runat="server" Text="ASP.NET" />
  6. <br />
  7. <asp:CheckBox ID="checkBoxJavascript" runat="server" Text="Javascript" />
  8. <br />
  9. <asp:CheckBox ID="checkBoxHtml" runat="server" Text="Html" />
  10. <br />
  11. <asp:CheckBox ID="checkBoxOther" runat="server" Text="Other" />
  12. &nbsp;
  13. <asp:TextBox ID="textBoxOther" runat="server" />
  14. <br />
  15. <br />
  16. <asp:Button ID="buttonSubmit" runat="server" Text="Submit" />
  17. <asp:CustomValidator
  18.     ID="CustomValidatorSkillsYouHave"
  19.     runat="server"
  20.     ErrorMessage="You must select at least one skill"
  21.     ForeColor="Red"
  22.     OnServerValidate="CustomValidatorSkillsYouHave_ServerValidate" />

Notice that we do not have specified ControlToValidate. As well we have defined a OnServerValidate method that will get called when the page is posted back to the server.

Here is the server side method

Code Snippet
  1. protected void CustomValidatorSkillsYouHave_ServerValidate(
  2.     object source, ServerValidateEventArgs args)
  3. {
  4.     if (!this.checkBoxASPNET.Checked &&
  5.         !this.checkBoxCSharp.Checked &&
  6.         !this.checkBoxHtml.Checked &&
  7.         !this.checkBoxJavascript.Checked &&
  8.         !this.checkBoxOther.Checked)
  9.     {
  10.         args.IsValid = false;
  11.     }
  12.     else if (this.checkBoxOther.Checked &&
  13.         string.IsNullOrEmpty(this.textBoxOther.Text.Trim()))
  14.     {
  15.         ((CustomValidator)source)
  16.             .ErrorMessage = @"You must supply a text
  17.                               description when selecting other";
  18.         args.IsValid = false;
  19.     }
  20. }

In this method we check to see if at least one checkbox was checked and if not set the args.IsValid = false which will cause the validator to fail. If the first test is passed we check to see if the Other checkbox is checked and if so ensure that the texbox was filled out. If not then we set args.IsValid = false but we also change the error message to provide a better description of the failure.

However the above only happens when posted back to the server. We also want to provide some client side validation in order to prevent a post back to the server if the same type of validation fails on the client side.

To do this we specify the ClientValidationFunction property on the CustomValidator to point to our JavaScript function to perform the client side validation. In this case I created a JavaScript function called IsSkillsYouHaveValid as shown below.

Code Snippet
  1. <script type="text/javascript">
  2.     function IsSkillsYouHaveValid(source, args) {
  3.         var checkBoxCSharp = document.getElementById('checkBoxCSharp');
  4.         var checkBoxASPNET = document.getElementById('checkBoxASPNET');
  5.         var checkBoxJavascript = document.getElementById('checkBoxJavascript');
  6.         var checkBoxHtml = document.getElementById('checkBoxHtml');
  7.         var checkBoxOther = document.getElementById('checkBoxOther');
  8.         var textBoxOther = document.getElementById('textBoxOther');
  9.  
  10.         if (!checkBoxASPNET.checked &&
  11.         !checkBoxCSharp.checked &&
  12.         !checkBoxHtml.checked &&
  13.         !checkBoxJavascript.checked &&
  14.         !checkBoxOther.checked) {
  15.             args.IsValid = false;
  16.         }
  17.         else if (checkBoxOther.checked &&
  18.         textBoxOther.value == "") {
  19.             source.innerText = 'You must supply a text ' +
  20.                             'description when selecting other';
  21.             args.IsValid = false;
  22.         }
  23.  
  24.     }
  25. </script>

So with this extra bit of client side code we will now perform client side validation that if failed will prevent the page from being posted back to the server, thus avoiding an unnecessary round-trip.

BUT we are not done yet. I am picky and one of the things I don’t like about the following solution so far is that when you correct the validation failure by for instance selecting at least one checkbox or by filling out the textbox if you have selected Other is that the error message still appears until you click the submit button. I want the user to immediately know once they have correct the issue that they have satisfied the validation.

To do this we need to add one more method. This method will be responsible revalidating to see if the validation passes if any change happens to one of the controls we are validating.

Code Snippet
  1. function ValidateSkillsYouHave() {
  2.     var customValidator = document.getElementById('CustomValidatorSkillsYouHave');
  3.     var checkBoxCSharp = document.getElementById('checkBoxCSharp');
  4.     var checkBoxASPNET = document.getElementById('checkBoxASPNET');
  5.     var checkBoxJavascript = document.getElementById('checkBoxJavascript');
  6.     var checkBoxHtml = document.getElementById('checkBoxHtml');
  7.     var checkBoxOther = document.getElementById('checkBoxOther');
  8.     var textBoxOther = document.getElementById('textBoxOther');
  9.  
  10.     if (!checkBoxASPNET.checked &&
  11.     !checkBoxCSharp.checked &&
  12.     !checkBoxHtml.checked &&
  13.     !checkBoxJavascript.checked &&
  14.     !checkBoxOther.checked &&
  15.     !checkBoxOther.checked) {
  16.         customValidator.isvalid = false;
  17.         customValidator.style.visibility = "visible";
  18.     }
  19.     else if (checkBoxOther.checked &&
  20.     textBoxOther.value == "") {
  21.         customValidator.innerText = 'You must supply a text ' +
  22.                         'description when selecting other';
  23.         customValidator.isvalid = false;
  24.         customValidator.style.visibility = "visible";
  25.     }
  26.     else {
  27.         customValidator.isvalid = true;
  28.         customValidator.style.visibility = "hidden";
  29.     }
  30. }

Now when we submit the form and the validation fails and the user goes and selects at least one checkbox then the validation will be re-evaluated and immediately update the display to remove the validation error when it passes.

I know this was a bit of extra work but when you have a big form and you have implemented RequiredFieldValidators etc.. in which the error message goes away when you fill in the field but your custom validators do not it starts to stand out and the extra little bit of work provides a better end user experience.

Now much of the Javascript code written about could have been done much easier using JQuery and no guarantee the javascript written is cross browse safe. I used IE8 in all my testing and would personally recommend implementing a Javascript library like JQuery that abstracts the browser differences out. However I wanted to keep it simple without adding the need to explain the JQuery syntax.

Click on the download link to download a copy of the full source for this article Download Source

 

kick it on DotNetKicks.com