Using ELMAH's SqlErrorLog to manually insert into Sql Server

by sunil ravulapalli /27. March 2013 00:47 /.net-tools /Comments (0)

This is a class I use to manually log into ELMAH tables

using Elmah;

namespace WesternUnionService
 public class Logger
  public static bool LogError(Exception exception)
	Error error = new Error()
		HostName = System.Environment.MachineName,
		Type = exception.GetType().ToString(),
		Source = exception.Source,
		Message = exception.ToString(),
		StatusCode = 0,
		Time = System.DateTime.UtcNow


	return true;

  public static bool LogInfo(string info)
	Error error = new Error()
		HostName = System.Environment.MachineName,
		Type = "Info",
		Source = ConfigurationManager.AppSettings["applicationName"],
		Message = info.Length <= 500 ? info : info.Substring(0,500),
		StatusCode = 0,
		Time = System.DateTime.UtcNow


	return true;

  private static void Log(Error error)
	  SqlErrorLog sqlErrorLog = new SqlErrorLog((Hashtable)ConfigurationManager.GetSection("elmah/errorLog"));


It can be used like below:

 //do something
catch (Exception ex)


Logger.LogInfo("Peek a boo");

Mocking session variables using Moq

by sunil ravulapalli /22. March 2013 00:20 /.net-tools /Comments (0)

If we want to test a controller method which uses session variables like the following example, we can use the Moq library to Mock up the session variables.

public ActionResult ShowBalance()
  var accountId = Convert.ToInt64(Session[SessionConstants.AccountId]);
  var last4DigitsOfSsn = Session[SessionConstants.Last4DigitsOfSsn].ToString();
  AccountStatus accountStatus = _quickPayService.ValidateAccount(accountId, last4DigitsOfSsn);
  if (accountStatus.IsValid)
    return View(accountStatus);
    return RedirectToAction("ShowError", accountStatus );

Below is an example of how session variables can be mocked

public void ShowBalance_WithNonExistantAccount_GoesToShowError()
  Mock<HttpSessionStateBase> session = new Mock<HttpSessionStateBase>();
  session.SetupGet(s => s["AccountId"]).Returns(99999999);
  session.SetupGet(s => s["Last4DigitsOfSsn"]).Returns("9999");
Mock<HttpContextBase> httpContext = new Mock<HttpContextBase>(); httpContext.SetupGet(c => c.Session).Returns(session.Object);
ControllerContext ctx = new ControllerContext(); ctx.HttpContext = httpContext.Object;
var quickPayServiceMock = new Mock<IQuickPayService>(); quickPayServiceMock.Setup(quickpayservice => quickpayservice.ValidateAccount(99999999, "9999")).Returns(new AccountStatus { IsValid = false }); KioskController controller = new KioskController(quickPayServiceMock.Object); controller.ControllerContext = ctx; //Act RedirectToRouteResult redirectToRouteResult = controller.ShowBalance() as RedirectToRouteResult; //Assert Assert.AreEqual("ShowError", redirectToRouteResult.RouteValues["action"].ToString()); }

Error loading module 'Ninject.Web.Mvc.MvcModule' of type MvcModule Another module (of type MvcModule) with the same name has already been loaded

by sunil ravulapalli /5. March 2013 00:58 /.net-tools /Comments (2)

Error loading module 'Ninject.Web.Mvc.MvcModule' of type MvcModule
Another module (of type MvcModule) with the same name has already been loaded
 1) Ensure that you have not accidentally loaded the same module twice.
 2) If you are using automatic module loading, ensure you have not manually loaded a module
    that may be found by the module loader.

While using NINJECT, If you are getting this error when using 


one possible solution might be is to do it this way, by listing out the dll's individually



I haven't figured out why the modules were loading more than once, but the above work around does achieve the "loose coupling" we seek.



TF271001: An error occurred while attempting to send an e-mail notification

by sunil ravulapalli /2. March 2013 00:44 /tfs /Comments (0)

After setting up the Email settings in the "Team Foundation Administration Console", I still did not get any emails. Upon looking into the event logs I found:

TF53010: The following error has occurred in a Team Foundation component or extension:

Date (UTC): 3/1/2013 8:37:30 PM


Application Domain: TfsJobAgent.exe

Assembly: Microsoft.TeamFoundation.Framework.Server, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; v2.0.50727

Service Host: 

Process Details:

  Process Name: TFSJobAgent

  Process Id: 1468

  Thread Id: 2440

  Account name: COMPANY\TFS

Detailed Message: TF271001: An error occurred while attempting to send an e-mail notification to the following address: Further e-mail notification errors that occur within the next five minutes might not be logged. Verify that the e-mail notification settings are correct in the Team Foundation Administration Console.

Exception Message: Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender (type SmtpException)

Exception Stack Trace:    at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse)

   at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)

   at System.Net.Mail.SmtpClient.Send(MailMessage message)

   at Microsoft.TeamFoundation.JobService.Extensions.Core.NotificationJobExtension.SendEmail(TeamFoundationRequestContext requestContext, TeamFoundationNotification notification)


1. TFS was a valid active directory user

2. "From address" was

3. Anonymous sender was enabled in Exchange

Upon requesting the exchange team, they found this entry in their event log:

Log Name:      Application

Source:        MSExchangeTransport

Date:          2/26/2013 4:37:31 PM

Event ID:      1025

Task Category: SmtpReceive

Level:         Error

Keywords:      Classic

User:          N/A



SMTP rejected a (P1) mail from '' with 'Spam Filter' connector and the user authenticated as 'GOPFS\TFS'. The Active Directory lookup for the sender address returned validation errors. Microsoft.Exchange.Data.ProviderError

Event Xml:

<Event xmlns="">


    <Provider Name="MSExchangeTransport" />

    <EventID Qualifiers="49156">1025</EventID>




    <TimeCreated SystemTime="2013-02-26T23:37:31.000000000Z" />




    <Security />




    <Data>Spam Filter</Data>







The last thing we tried was to enable a mail box to the "TFS" user in exchange and the emails started flowing!

Convert large hex to decimal

by sunil ravulapalli /28. February 2013 20:07 /other /Comments (0)

C# does have a big enough data type to hold big decimal numbers.

So, coding will not help.

After googling a lot I found a website to do it for me:

Luckily, I didn't need this in a program. I just had to verify some numbers. When you pull up the certificate properties in the "certificate repository", it shows up in hex. But in my "Signed Xml", the serial number showed up as decimal. So, i just needed a tool to convert between the two.

TFS build not picking up correct configurations

by sunil ravulapalli /20. February 2013 23:34 /tfs /Comments (0)

I encountered a bizarre problem where TFS was picking up the wrong configuration settings. For example, if I wanted to do a production build using, it was picking up settings from

After a lot of investigation, I found the answer in the Solution(.sln file). Essentially I think the solution was telling TFS to pick Qa settings when TFS asks for Prod. 

{AB15DD03-6329-4468-96F9-DE694B31617C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Debug|Any CPU.Build.0 = Debug|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Prod|Any CPU.ActiveCfg = Qa|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Prod|Any CPU.Build.0 = Qa|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Qa|Any CPU.ActiveCfg = Qa|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Qa|Any CPU.Build.0 = Qa|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Release|Any CPU.ActiveCfg = Release|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Release|Any CPU.Build.0 = Release|Any CPU


I still don't know what I keep doing for this to happen. But it happens multiple times for different projects and each time I have to go and fix this by manually going and editing it like below. 



{AB15DD03-6329-4468-96F9-DE694B31617C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Debug|Any CPU.Build.0 = Debug|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Prod|Any CPU.ActiveCfg = Prod|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Prod|Any CPU.Build.0 = Prod|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Qa|Any CPU.ActiveCfg = Qa|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Qa|Any CPU.Build.0 = Qa|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Release|Any CPU.ActiveCfg = Release|Any CPU

{AB15DD03-6329-4468-96F9-DE694B31617C}.Release|Any CPU.Build.0 = Release|Any CPU


How do I even google this? :)

Intranet and Internet site look different in IE 10

by sunil ravulapalli /20. February 2013 21:18 /other /Comments (0)

Recently, when I opened a local site intranet site in IE10, it looked broken. When I cross checked the same on my production sever it looked fine. I checked to make sure all my code was same, it was.

So, what gives?

I hit F12 and saw 3 things which seemed off.

1. Browser mode: IE10 Compat View

2. Document Mode: IE7 Standards

3. What was my DOCTYPE commented?

So I started googled "ie10 doctype getting commented out" and I found my answer here:

The following post also says, "Are you on the same domain? If so, IE automagically forces one into intranet-friendly compatibility mode. "

To summarize, if you put this in your web.config, it generates a META tag in the HEAD telling IE to use latest rendering mode instead of going to older modes no matter what.

    <clear />
    <add name="X-UA-Compatible" value="IE=edge" />

Force Windows Phone 7.8 Update

by sunil ravulapalli /13. February 2013 01:17 /other /Comments (0)

Like many people I was desperate to update my Noikia Lumia 7.5 to 7.8. I kept reading all gadget websites everyday to see if ATT would send out the update. Some sites suggested using an update software by an enthusiast but it came with several warnings, so I decided not to go that route. I my quest for other information, I bumped into this forum which talked about some weird Zune bug to force an update. This seemed much safer to me as it was still Zune which was doing your update. So I tried it. I am glad to report that it works great!

1. Disable Wifi and Cellular Data

2. Connect to PC, open zune, settings, then phone, then update. It won’t find any, but you NEED to do this.

3. Change the tab (navigate away from Update). Now click on Update again, but disconnect your internet connection after 2 seconds. BAM an Update is available after waiting a few seconds!

4. Hook up internet and proceed!

Additional notes:

1. I had a tough time doing STEP 3. You had to be really quick to disconnect the internet after you hit UPDATE. I dragged Zune to my lower right corner, so that my mouse has lesser distance to travel. I guess if there is a Keyboard shortcut to disconnect the internet, it would be advisable.

2. I also had to do this whole thing twice. I think first update just preps it and second actually does the 7.8 update.

HTML Canvas Rotate Image

by sunil ravulapalli /22. January 2013 04:08 /javascript /Comments (0)

The following is a function to rotate an image using javascript on html canvas:

    function rotateImage(img, x, y, width, height, deg) {

        //Convert degrees to radian 
        var rad = deg * Math.PI / 180;

        //Set the origin to the center of the image
        ctx.translate(x + width, y + height);

        //Rotate the canvas around the origin

        //draw the image    
        ctx.drawImage(img, width * (-1), height * (-1), width, height);

        //reset the canvas  
        ctx.rotate(rad * (-1));
        ctx.translate((x + width) * (-1), (y + height) * (-1));

It can be used a follows:

    var ctx = canvas.getContext("2d");

    var img = new Image();
    img.src = "fish.png";

    rotateImage(img, 50, 50, 100, 100, 45);

Cannot install Web Farm Framework 2.2

by sunil ravulapalli /22. January 2013 00:46 /other /Comments (0)

I had an amazingly difficult time installing Web Farm Framework 2.2 until I found this answer on IIS forums, just re-posting hoping someone else will find it useful.



1. Install web deploy 1.1 Can be found in the "Installing Version 1.1 of Web Deploy " section of the following link: 

2. Install Web Platform 3 (DO NOT INSTALL 4!) 

3. Install WFF 2.0 (x64) (x86) 

4. Install WFF 2.2