jump to navigation

NLog and Windows Event Log Bug? November 6, 2009

Posted by kevinbe71 in .NET, Development, Windows Development.
add a comment

I’ve been experimenting with a logging library for .NET called NLog.  My past experience has been with Log4Net but I’ve not been all that happy with Log4Net so I was looking for a better alternative.  NLog seems to be that alternative… but I ran into one glitch when I switched from file and console logging to Windows event logging.  I just wasn’t getting anything logged.  The first problem was that I didn’t have an event log source defined, so I used WiX to create an event source (pretty easy to do since I’ve already used WiX for this purpose in the past).  After that I was a bit puzzled- it still wasn’t working and the nlog internal logs weren’t showing anything either.

It was time to dig into the source code… and what I found out seems to be a bug in NLog.  I had a target configured this way:

<target
  name="eventlog"
  xsi:type="EventLog"
  layout="${longdate}|${level}|${message}"
  log="Application"
  source="My Source" />

I didn’t have machineName defined.  After all, the documentation stated that machineName defaults to the local machine anyway, so why set it to anything?  Well… because if you don’t then a boolean member var called _operational stays “false” and it needs to be set to “true” for the event log entry to get written!  So, the workaround for this is actually pretty easy:

<target
  name="eventlog"
  xsi:type="EventLog"
  layout="${longdate}|${level}|${message}"
  log="Application"
  source="My Source"
  machineName="." />

Anyway, I thought someone else may find this useful if they’re also an NLog newbie…

ASP.NET detected invalid characters in the URL (HTTP Error 400.0 – Bad Request) April 8, 2009

Posted by kevinbe71 in ASP.NET, Development, MVC, Web Development.
add a comment

I ran into this error when writing a web app using ASP.NET MVC and using a comma in one of the input params used in the URL.  IIS 7 reported the error in the following way:

In “Error Summary” it had “HTTP Error 400.0 – Bad Request” and “ASP.NET detected invalid characters in the URL.”

In “Detailed Error Information” the Request URL was something like this and hovering over the link showed the same URL:
http://localhost/BaseUrl/Some_Path%2c_And_More/View

In the browser’s address box the URL was displayed as:
http://localhost/BaseUrl/Some_Path%252c_And_More/View

The comma was being double-encoded (%2c –> %252c) !  I didn’t spot the difference at first until I used the W3 Schools reference on URL encoding (http://www.w3schools.com/TAGS/ref_urlencode.asp) and noticed the encoding of %.

So, in the end the solution was to remove the bit of code that was doing the extra URL encoding.  Pretty simple really…

Uninstalling VS 2008 Beta “Microsoft Windows Vista Client Headers and Libraries (6001.16533.121)” January 4, 2009

Posted by kevinbe71 in Development, Windows Development.
add a comment

I recently upgraded one of my old desktop systems that had a VS 2008 Beta installed on it.  When attempting to install the gold version of VS 2008 it complained about the pre-release “Microsoft Windows Vista Client Headers and Libraries” still being present on the system.  This made some sense because the VS 2008 Beta uninstall had failed to uninstall some libraries.  I followed the work around documented on this page:

http://blogs.msdn.com/varungupta/archive/2007/11/27/i-uninstalled-visual-studio-2008-beta2-but-still-cannot-install-vs-2008-final-release.aspx

However, this process complained about a dependency on “vstscore_vs”.  The only page that had information on this was a Japanese page:

http://www.niuc.net/post/82/

(well, it looks like Japanese to me… I’m not really sure, but whatever it is I can’t read it!)

That same page mentioned “procore_vs” that is mentioned in the earlier article.  So, I put 2 and 2 together and figured that it was safe to use the “procore_vs” workaround for the “vstscore_vs” message.  It worked!

So, if you’re seeing a message about “vstscore_vs” then use the following step to remove the dependency:

Delete the following Registry key and try uninstall again.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\ProductReference\ReferencedProducts7D7D27646D242F5BC900906C330746E

The following warning note on the original page had made me nervous, but with the Japanese page showing this same step and mentioning both vstscore_vs and procore_vs I figured that it wasn’t that bad…

Note: This workaround is for a specific case and don’t delete registry key in any other case.”

However… the usual disclaimer should be included: use at your own risk!  Also, could someone who understands Japanese perhaps confirm my hunches?

Using ASP.NET MVC From Visual Web Developer Express 2008 April 19, 2008

Posted by kevinbe71 in ASP.NET, Development, MVC, Web Development.
Tags:
2 comments

Recently I’ve been curious about Microsoft’s ASP.NET MVC framework that is currently at “Preview 2″ stage (although there may be more recent CTPs floating around). I’ve read a bit about it and felt it was time to actually dig in and start writing a web site that uses the technology. I don’t own a copy of VS 2008 so I figured I’d download VWD Express 2008 and play around with it. Well, the problem is that ASP.NET MVC doesn’t specifically support it. Fortunately, I found a blog posting by Jason Whitehorn that got me started. However, I couldn’t get it working immediately. I ran into two issues that I’ll explain below. I figure that this may be helpful to others.

Jason Whitehorn’s blog posting here:

http://jason.whitehorn.ws/CommentView.aspx?guid=…

Jason provides all the pieces of the puzzle but his page is missing a few minor points that a newbie may run into:

  1. Downloading the zipped template to the Visual Studio 2008\Templates\ProjectTemplates\Visual Web Developer folder doesn’t appear to work at first if you download the C# template. The reason for this is that VWD defaults to VB as a language. All you need to do is select C# from the drop-down list and the template will appear. Another mistake a newbie might make is to unzip this file. Don’t- it won’t be found if it isn’t zipped.
  2. You should change the VirtualPath property of your web site from “/<your_web_site_name>” to just “/”. Otherwise you’ll need to build routes that include your web site name as the first part of the URL- not preferable. If you don’t do this you may end up with the error shown below.

The RouteData must contain an item named ‘controller’ with a non-empty string value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The RouteData must contain an item named ‘controller’ with a non-empty string value.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The RouteData must contain an item named 'controller' with a non-empty string value.]
System.Web.Mvc.RouteData.GetRequiredString(String keyName) +201
System.Web.Mvc.MvcHandler.ProcessRequest(IHttpContext httpContext) +139
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +55
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.
ProcessRequest(HttpContext httpContext) +28
System.Web.CallHandlerExecutionStep.System.Web.
HttpApplication.IExecutionStep.Execute() +358
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Anyway, I hope this will be helpful to someone else who encounters this error. Jason’s blog post isn’t accepting comments so I couldn’t post this “answer” there.