Enabled Hyper-V on my Windows 8 64 bit machine

Written by stevey on August 22nd, 2013
  1. Turned on the Intel’s virtualization feature by going into BIOS setting at boot-up. Not all laptops support this so-called “Second Level Address Translation” technology (SLAT) but most of 64-bit machines do and min. requirement is to have 4GB memory. This link at http://www.techrepublic.com/blog/windows-and-office/get-started-with-windows-8-client-hyper-v-the-right-way/ provided a good reference.
  2. Had to upgrade the Windows 8 x64 to Windows 8 Pro x64 (by downloading from MSDN subscription); then checked the “Hyper-V’ feature on “Windows Feature Turn On/Off” under the Control Panel.
  3. Used command “msinfo32.exe” to check if all Hyper-V features are “Yes”. They are.
  4. Re-started the Windows and opened “Hyper-V Manager”; created first VM named “VM-2008R2″ and stored it in the default location C:\ProgramData\Microsoft\Windows\Hyper-V\
  5. Startup Memory gave it a 4096MB which 8x the default of 512MB and also checked the “Use dynamic memory for this virtual machine” option.
  6. Connection: Not Connected for now. Need to add Network adapter later.
  7. Created a virtual hard disk, “VM-WinSvr2008.vhdx” and leave it default size of 127GB and location at C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\
  8. Will install OS later; Installed Windows Server 2008R2 next day.
 

Manually added Elmah to a deployed Asp.Net website

Written by stevey on June 18th, 2013

Sometimes I found that it was frustrating to not know what exception detail was when an exception was thrown from a production website. At that point, the all-mighty Elmah error logging and exception handling plug-in came to my mind. But all my previous Elmah plug-in was added during web project development and deployed along with the project to hosting server. How to go about plugging in an Elmah when my website is already up there and running? Here were the steps I went through the other day to accomplish exactly that:

  1. Downloaded the elmah sql script file from https://code.google.com/p/elmah/downloads/detail?name=ELMAH-1.2-db-SQLServer.sql&can=2&q= and executed it against the sql database ProdDB on the host. It went through and created the Elmah_Error table and related stored procs inside ProdDB database
  2. Now let’s manually add elmah.dll and configure the web.config to register elmah.
  3. Copied elmah.dll from one of my old projects that had Elmah already working to the target bin folder.
  4. Added to <configuration><configSections> the following:
    <sectionGroup name="elmah"><section name="security" type="Elmah.SecuritySectionHandler, Elmah" />
    <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" /></sectionGroup>
  5. Added to <httpHandlers>:
    <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
  6. Added to <httpModules>:
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
  7. Added <elmah> to <configuration> right after </system.web> and before <system.net>
    <elmah>
    <!--<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Errors" />-->
    <errorLog applicationName="AppName" connectionStringName="connToProdDb" type="Elmah.SqlErrorLog, Elmah" />
    <errorMail subject="Website error via Elmah" to="stevey@yangsoft.com" from="webmaster@yangsoft.com" aysnc="true" />
    
    <security allowRemoteAccess="no" />
    
    </elmah>
  8. Last, but not least, in order to get the alert email sent out automatically to me, I needed to add the SMTP parameters to the mailSettings section in the <system.net>
    <mailSettings>
    <smtp deliveryMethod="Network">
    <network host="mail.domainname.com" userName="webmaster@domainname.com" password="password" port="numberthatworks" />
    
    </smtp>
    
    </mailSettings>

    (there was no <system.net>, so just created one)

  9. Added the following right after </system.net> and before <system.webserver>
    <!--deny annonymous access to error log-->
    <location path="elmah.axd">
    <system.web>
    
    <authorization>
    <allow users="*"/>
    <!--<deny users="?" />-->
    </authorization>
    </system.web>
    
    </location>
  10. Added to <system.webserver><modules>:
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
  11. Added to <system.webserver><handlers>
    <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
  12. Finally, it is completed! Now browsed to the site and manually generated some errors; immediately, I got an email alert; then I browsed to the elmah.axd, and it also rendered all the errors in a tabulated format nice and neat. Of course, more detail info is obtained by clicking on the detail link and you will be surprised how much exception stack trace has been caught.
 

What is this error, “Uncaught SyntaxError: Unexpected token o”?

Written by stevey on June 5th, 2013

It seemed that from time to time, we ran into this error “Uncaught SyntaxError: Unexpected token o“. Without more specific info, sometimes this can be very frustrating.

As matter of fact, this error was simply a result of sloppy coding in creating a JSON string that was not parsed correctly. Tracked down to the piece of code where error was thrown – it occurred where JSON.Parse was called. If the string s passed into the JSON.Parse(s)  is not properly formatted JSON string, the above error is thrown. In the sample code snipe below, r is a json string returned from a AJAX call from C# code; if I called JSON.parse(r), I would get the “Uncaught SyntaxError: Unexpected token o” error; and if r is not properly formatted, I also got the same error. Correct way to parse the returned json string is to call JSON.parse(r.d), instead of JSON.parse(r). I also tried to call JSON.parse(r.responseText), as it worked with the the xhr returned in the error function, but I got a different error, “Uncaught SyntaxError: Unexpected token u“, very interesting. Only r.d worked! Who came up with such super terse object name?!!

 

function fetchEmployer(code) {

        var account = null;
        var url = "<%=AjaxPath%>/GetEmployer";
        var json = JSON.stringify({EmployerCode: code});

        $.ajax({
            type: "POST",
            url: url,
            data: json,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (r) {
                account= JSON.parse(r.d); //the error will be thrown if you just parse r instead of r.d
                //alert(r.d);

            },
            error: function (xhr, ajaxOptions, thrownError) {
                   if (xhr != null) {

                    var err = JSON.parse(xhr.responseText); //you can throw a code-behinde Exception and it will automatically                                                 //render to a valid JSON string when we rerieve the responseText
                    alert("ErrorMessage: " + err.Message + " StackTrace: " + err.StackTrace);

                }
            }
        });

        return account;

    }
 

Error while running PM>install-package MSBuildTasks

Written by stevey on March 14th, 2013

Got this error today while trying to install MSBuildTasks for a DNN Module development project and used NuGet:
install-Package : Method invocation failed because [NuGetConsole.Host.PowerShell.Implementation.PSTypeWrapper]
doesn’t contain a method named ‘AddFromFile’.”

I copied this error message to Google and found no match. After some digging, with portion of error words, found some tips linking to the fact that NuGet might need a face-lift. So I went back to VS2010 project, uninstalled the NuGet and re-installed it. Then run PM>install-package MSBuildTasks again, it went through with not error.

Hopefully this tip will be picked up next time someone would run into the same error message I got here.

Cheers!

 

DotNetNuke Portal Setup

Written by stevey on March 12th, 2013

Steps to get DNN installed on VM and run:

  1. Downloaded DNN Install version from here http://dotnetnuke.codeplex.com/releases/view/81081. Did New Install, not “Install and Source Codes” for now.
  2. Created database DNN on VM Local machine SqlExpress and gave it full access to “Network Service” and my Windows Account
  3. Opened web.config from c:\Development\Dotnetnuke folder (where the dnn installation zip files were extracted to)
    and changed the connectionstring from:<add name=”SiteSqlServer” connectionString=”Server=(local);Database=DotNetNuke;uid=;pwd=;” providerName=”System.Data.SqlClient” />

    to:

    <add name=”SiteSqlServer” connectionString=”Data Source=LocalMachineName\SQLEXPRESS;Initial Catalog=DNN;Integrated Security=True”
    providerName=”System.Data.SqlClient” />

  4. Then went to IIS7/Default websites and added a new virtual directory, DNN and pointed to physical folder at c:\Development\DotNetNuke; Right clicked on the DNN VD and converted it to Application.
  5. Once converted to Application, I could set it to use the application pool that is specific to this app.
  6. So, went back to Application Pools and created one, “DNN” and changed Framework version to 4.0 and leave the Managed Pipeline Mode to
    default, “Integrated” and under the Process Model set the Identity to use Network Service instead of the default “ApplicationPoolIdentity”. The
    reason was that I could assign full folder access permission to the “Network Service” user account, but “ApplicationPoolIdentity” is not a
    actual Windows account.
  7. Set the Application pool to this newly created “DNN” ap.
  8. Browsed the site from IIS and just followed the onscreen instruction to go through the installation process. The database tables and objects
    are all created during this process. No need to run any sql installation script from Sql server side.
 

ASP.NET Web service call error, “Unable to generate a temporary class (result=1)”

Written by stevey on February 19th, 2013

Got this obscure error while calling a web service method that requires a Xml serializer:

Unable to generate a temporary class (result=1).\r\nerror CS2001: Source file ‘C:\\Windows\\TEMP\\qdrb02m1.0.cs’ could not be found\r\nerror CS2008: No inputs specified\r\n”}  System.Exception {System.InvalidOperationException} “

 

Web searches on key phrase “Unable to generate a temporary class (result=1)” returned some useful results but none could directly resolve my issue. But general direction was pointing to the proper permission of the ASP.Net surrogate identity that most likely does not have sufficient right to the local I/O where XML serialization takes place.

To prove this, I fired up a console application and called the same web service method; as anticipated, the Console app did not throw error at all. So that’s true – it is to do with the Windows account that IIS uses to run the ASP.Net process.

By default, IIS7 uses “ApplicationPoolIdentity” as the Identity for the Application pool automatically created when a new website is added to the IIS/Sites. But what’s underneath this mysterious “ApplicationPoolIdentity” – you could not even find it in Windows by looking up user accounts? Below are several things I tried and let’s see how they fared:

  1. I tried to give “Full Control” permission to ASP.NET Machine Account on c:\windows\Temp folder. Not work.
  2. Changed the app pool identity to “Network Service” (via IIS7/Site/Advanced Settings) and gave the “Network Service” full control permission to c:\windows\temp (via Windows Explorer). It worked! Then I reduced permission to only “Read, List Folder Contents”, and it still worked.
  3. Changed the app pool identity to “Local System”, of course that worked too.

 

So, at the end, to get rid of error “Unable to generate a temporary class (result=1)..”,  I ended up using the “Network Service” as the Application Pool identity (leave the security mode as Integrated) and granted the “Network Service” account permission “Read, List folder contents” on “C:\Windows\Temp” folder.

P.S.: after I deployed the web app to my staging web server, the error returned. The staging server is running IIS6 and the app pool identity by default was already tied to “Network Service” account. So I went directly to the c:\windows\temp folder and as I anticipated, the account did not have “read, list folder contents” permission. So I granted the permission to “Network Service” account and then it all worked!

 

Good read on SSIS

Written by stevey on February 6th, 2013

Liked this article series on MS SSIS from sqlservercentral.com:
This is an introductory one and quickly helped to understand what is SSIS and it is a replacement of DTS, not upgrade; and what’s BIDS (Business Intelligence Development Studio) and how it is integrated into Visual Studio IDE for development SSIS in C#, etc.
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/72492/

 

Downgraded Windows 8 to Windows 7, be careful

Written by stevey on December 27th, 2012

Recently I purchased a Lenovo ThinkPad T430 loaded with Windows 8 64 bit. A few days later I tried to downgrade Win8 to Win7 in order to be consistent with my company’s standard which is currently Windows 7; I thought it would be easy – just pop in the Windows 7 CD and let it delete the old partition and create a new NTFS partition, then install the Windows 7 32-bit. Well, yes, it did delete the partition where Win8 was installed. But I was unable to reformat it to NTFS that is required to install Windows 7. Windows 8 is only installed on GPT (Guid Paritition Table) format; at that point, I was basically in a limbo – I could not go back to Windows 8 because the GPT partition was deleted and was unable to install Windows 7 because it requires NTFS. Eventually, I got someone from Lenovo Community Forums to point me to using a DOS utility called DISKPART. With that, I have successfully overcome the biggest hurdle – re-partition my disk to NTFS format. Here I recorded the steps I just went through ( I also posted these to Lenovo Community Forums), hoping it will be useful to someone who might want to do the same:

  1. Powered up T430 and let the Diagnostic tool run “Preparing Automatic Repair”
  2. On screen showing “Diagnose your PC” then “Attempt to repair your PC”
  3. Automatic Repair failed, then two options button showed “Shutdown” and “Advanced options”; selected the “Advanced options” button
  4. Selected “Troubleshoot”, then “Advanced Options”
  5. Clicked on “Command Prompt” on Advanced Options screen
  6. Now we are in command prompt: c:\>; typed “diskpart /?” to list a possible commands
  7. Followed the instruction on http://www.computerhope.com/diskpart.htm to get the proper command switch
  8. At C:\> typed “diskpart” to enter DISKPART command mode; then type ? to list all the switches, such as GPT, Help, etc
  9. Diskpart>format fs=NTFS Label=”86DB-AC90″
  10. Did not format; message returned
    There is no volume selected.
    Please select a volume and try again
  11. As matter of fact, the problem was that I had not selected a disk; after reading this post at http://www.jwgoerlich.us/blogengine/post/2009/11/05/Use- Diskpart-to-Create-and-Format-Partitions.aspx, I did a “list disk” command at DISKPART>, and that got me a list of disk online.
  12. Then I did a select disk command: DISKPART>select Disk 0; it returned message “Disk 0 is now the selected disk”
  13. I ran “clean” command again; this time, message returned, “DiskPart succeeded in cleaning the disk”
  14. Diskpart>format fs=NTFS quick; still got the “There is no volume selected”
  15. Tried DISKPART>convert mbr
    DiskPart successfully converted the selected disk to MBR format
  16. DISKPART>create partition primary
    output: DiskPart succeeded in creating the specific partition
  17. DISKPART>select part 1
    output: Partition 1 is now the selected partition
  18. DISKPART>format fs=NTFS label=YangT430 quick
  19. Put in Windows 7 32-bit CD and installation now just sailed through.
 

Asp.Net Form Postback error:Error – Operation is not valid due to the current state of the object

Written by stevey on December 12th, 2012

Sometimes when there are a large number of input fields on a Asp.Net form, and doing postback, I would get this error:
“Error – Operation is not valid due to the current state of the object”

As it turned out there is a restriction on how many fields can be posted back to server and the large grid that contains a large number of textbox fields probably was the culprit. Google search returned some postings that all point to the configure setting

<appSettings>
<add key=”aspnet:MaxHttpCollectionKeys” value=”2000″ />
</appSettings>

 

After I stuck this line into the appSettings, the problem went away.

 

Smtp Permission error at Winhost

Written by stevey on December 7th, 2012

When I was developing my ASP.Net app on local machine,  I had no problem sending email by calling directly the SMTP relay server assigned by my hosting company Winhost, with port set to 587 of course. But when I deployed the app to the winhost server, the email tool threw this exception :

Request for the permission of type ‘System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.

I did suspect some some security permission to Smtp related assembly and have done some search toward that direction. First I got a lead from some post via Google search and one suggested added this entry into the <system.web> section; but that did not work, so I am not going to give reference to this post.

<securityPolicy>
<trustLevel name=”Full” policyFile=”internal”/>
</securityPolicy>

Today, I went into Windost support site and did another search on their forum, and they pointed me to using this instead:

<system.web>

<trust level=”Full” />

</system.web>

Yes, that was all it needed!