Fix for Office 2013 Publisher PIA

So, Office 2013 is out, and out of the box there is an unpleasant surprise: our code driving Publisher via the interop assembly no longer compiles. After much digging, turns out Microsoft managed to screw up the registry entry for the Publisher PIA. Here's the fix, step by step: Fire up regedit (usual caveats apply, don't blame me if your computer blows up) Run a search for "0002123C-0000-0000-C000-000000000046" (without quotes) The first hit should be HKEY_CLASSES_ROOT\Typelib\{0002123C-0000-0000-C000-000000000046} Expand the key, observe two subkeys, "2.1" and "2.2" -- you've found the problem! ...

HttpContext.Current.Profile is null in iis7 (Vista, Windows 7, 2008 Server)

Took an ASP.NET app to an IIS7 and suddenly lost access to Profile. After much trial, error, and Googling, found that the following attribute must be present on the <modules> element inside the <system.webserver> element: <modules runAllManagedModulesForAllRequests="true"> Hope I saved you some time.

Cure long startup delay of vs2008 debugger

Lately, starting up a debugging session in Visual Studio 2008 has started to take a really long time (as in sometimes minutes!). I was contemplating uninstalling and reinstalling but the prospect didn't excite me. Finally, I did some digging around the Interwebs and found my answer: apparently, large number of breakpoints can significantly impair debugger startup time. No, I don't know what "large" means, but Debug -> Delete All Breakpoints cured my problem and now the debugger starts up instantly. So, posting this here in case someone else runs into this problem.

Add client-side onchange handler to ASP.NET CheckBox control

The ASP.NET CheckBox control offers a convenient abstraction on top of the standard HTML input type="checkbox" control, by marrying a checkbox with a label. Ordinarily, the ASP.NET checkbox works just fine, but if you wanted to have a client-side javascript function triggered when the checkbox is toggled, there is no built-in mechanism to do that. The usual things to try when one wants to add client-side functionality to ASP.NET controls won't work because the CheckBox control wraps the checkbox input control and the label inside of a span. So, if one were to just add an "onchange" or "onclick" handler either...

C# number format expression for large numbers

This expression will format large number with a thousands separator: .ToString("#,#")


Don Box posted an excellent summary of the REST vs SOAP decision tree.

I got Dugg!

In a first for this blog, my rant on arrogant web designers got dugg. The interesting thing to me is that at the time of this writing, there is only one commenter that agreed with me and four who didn't get my point at all and ranted back about IE's poor standards support. Oh well, I just hope they are a vocal minoroty. :)

Are you an arrogant web designer?

If you are the person responsible for BlogLines, you are. Before I get into my rant, let me classify site designs into three buckets: Arrogant: common among Mac and Linux people. They discount windows and Internet Explorer on religious grounds, code up page layouts to look good in their favorite browser (FireFox, Safari) and assume that because their browser of choice is known to be fairly standards compliant, their work is therefore standards compliant. There are two fallacies with this approach: first, just because browser X renders something one way, it does not necessarily mean that that is the right way (either due...

CompositeDataBoundControl explained

The .Net framework version 2.0 includes some new base classes that make creating custom ASP.Net controls much easier. Among them is the CompositeDataBoundControl class intended to aid in the development of custom databound controls that are made up of other Controls. Under most circumstances, all the control author has to do is override the CreateChildControls method. The exact method signature is: protected abstract int CreateChildControls ( IEnumerable dataSource, bool dataBinding) Note the int return value -- this should be the number of data items in the data source that your control acted on when processing the data source. This should become clear in a minute. The...

Custom HTTP error pages tip

Just a small reminder: if you are creating a customized page for a specific HTTP error, be sure to include code in the page to set the response error code appropriately. For reference, see this and this. For example, if you are using ASP.Net and are creating a custom 404 page, add this line to your Page_Load method: Response.StatusCode = 404;

How to write a unit test

Jason Diamond comments on Brad Wilson's post about unit tests' SetUp and TearDown methods. In the process, he lists some excellent general guidelines on how to structure your unit tests and fixtures. Definitely worth a read. Jason concludes: These days, I write a lot more fixtures. Each fixture has a unique SetUp method and the test cases usually contain nothing more than a single method call and one or two assertions. To figure out what the entire test case does, all I have to do is look at the SetUp method which, itself, is usually just a few lines of code....

Refactoring under VS 2005 (Whidbey) and ASP.Net

Surely I am not alone out there developing ASP.Net applications under VS 2005 who would like to be able to use the new refactoring features. If you, like me, find the performance abysmal, please vote for this bug!

ICallbackEventHandler changes again

I reported on the change from Beta2 of Visual Studio 2005 to the July CTP in a previous post. According to latest information from Microsoft, the interface will undergo another change for RTM. Here it is from the horse's mouth: Callbacks enable ASP.NET controls to request data from the server using client script instead of posting back the page. For example, the TreeView control uses callbacks to populate child nodes when the parent node is expanded; this avoids the need to render the complete data hierarchy to the client on the initial page request. Controls will typically retrieve data from a...

ICallbackEventHandler changes in July CTP

Prior to the July CTP of VS 2005, the ICallbackEventHandler had just one method with the following signature: string RaiseCallbackEvent (string eventArgument) The eventArgument was the string that came from the client and the return string went back to the client. In July CTP, the ASP.Net team split up the processing into two calls that now make up the ICallbackEventHandler: void PrepareCallbackEvent (string eventArgument)string RenderCallbackResult () The idea remains the same, you process the incoming data in PrepareCallbackEvent and put together the return payload in RenderCallbackResult.

ASP.Net 2.0 urlMappings (Web.config)

Following up to my previous post, the urlMappings section in Web.config allows one to configure rudimentary url rewriting. For example, putting this into your section: <urlMappings>  <add url="~/PageThatDoesNotExist.aspx" mappedUrl="~/RealPage.aspx" /><urlMappings> will result in RealPage.aspx being rendered while the browser still thinks it reached PageThatDoesNotExist.aspx. One thing to note is that the URL must be application root relative. This was actually of interest to me since I wanted to do something similar but with a permanent redirect. It looks like in order to be able to do that, they had to bake urlMappings support pretty deep into the framework (way deeper than an...

Things to check out in ASP.Net 2.0

Looking through the machine.config.comments found in \Windows\Microsoft.Net\Framework\{ver}\Config yields some curious things that I havent seen broadly discussed yet. This is a reminder to myself to dig a bit further. anonymousIdentificationurlMappingshttpCookiessessionPageState

WinDiff, WinMerge, and other usual suspects

If you are looking for a place to download WinDiff or just a list of diff/merge solutions for windows, take a look at Brad's post and comments...

More free ASP.Net controls

In the department of link propagation. found these via Mike Gunderloy: Morrison Schwartz products.

Example – An ASP.NET handler that returns a dynamically generated image

This is a verbatim excerpt from a Microsoft employee post on changes in ASP.NET 2.0 from Beta 1 to Beta 2:   <%@ webhandler="" language="C#" class="ImageHandler" %=""> using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Web; using System.Web.Caching; public class ImageHandler : IHttpHandler { public void ProcessRequest (HttpContext context) { // Get the image ID from querystring, and use it to generate a cache key. String imageID = context.Request.QueryString["PhotoID"]; String cacheKey = context.Request.CurrentExecutionFilePath + ":" + imageID; Byte[] imageBytes; // Check if the cache contains the image. Object cachedImageBytes = context.Cache.Get(cacheKey); if (cachedImageBytes != null) { imageBytes = (Byte[])cachedImageBytes; } else { // Get image from business layer, and...

Even more on ASP.NET 2.0 Membership Provider API design and Exceptions

Robert and I have been having some back and forth on the quality of the API design of the Membership Providers in ASP.NET 2.0. The discussion is starting to evolve along two lines: whether or not to throw exceptions from method calls and whether the API should use interfaces or abstract classes to define contracts. I am not touching the latter since I believe there are no right answers, just tradeoffs. I have, however, been advocating a change in the API that would either move away from a boolean return value convention or rename method calls to make it clear...

More on MembershipProvider API design

I blogged recently about what I saw as flaws in the design of the ASP.NET MembershipProvider API. Robert McLaws responded in comments: Mike, your argument is incorrect. Microsoft development guidelines clearly state that exceptions are expensive and should be avoided whenever possible. The Provider Model was not designed to make the decision for you on whether or not something is exception-worthy, that is why this specific function returns a boolean. If the exception is going to be thrown, it should happen either inside your custom Provider (which is again not recommended because they are expensive) or from your method call. I stand...

Fun with Iterators

Wesner digs into iterators in his new blog post. Its fascinating stuff and a lot to chew on. Its not clear to me though, in what way is his iterator-based chess game example better than code like the bit below? public class Game{   public static void Main()   {       bool gameOver = false;       while (! gameOver)       {          gameOver = DoWhiteMove();          if (! gameOver) gameOver = DoBlackMove();        }     }} (sorry about lack of proper formatting).

Visual Studio 2005 Express does not include Source Control integration.

Mike Gunderloy pointed to the Visual Studio 2005 Product Line Overview page and commented that he doesn't understand why the Express line does not include source control support. This was one of the things that jumped out at me as well. The Express line of products is intended for a hobbyist programmer and one could do no greater service than introduce a beginner to the concept of source control. Fine, don't include VSS, but at least throw in the option to support SCC integration! IMO, SCC is the concept every beginning developer should be forced to learn. Thay may be too extreme...

How to reverse engineer and debug MSI files

An insightful blog entry by Aaron Stebner.

ASP.NET 2.0 MembershipProvider issues

I blogged on this topic before, but just ran into a blog post by Paul van Brenk with a different set of issues.

Walkthrough: Localizing Web Forms Pages

It took me a bit of MSDN spelunking to find it, so here's a direct link: Walkthrough: Localizing Web Forms Pages

VS.Net 2005 May CTP, Membership PasswordRecovery

There is a bug in the May CTP bits of Whidbey that prevents the PasswordRecovery control from properly doing its magic. Specifically, it can't send an email because the SmtpMail class that this control relies on has some broken logic when it comes to reading the name/address of the SMTP server from the config file. The symptom is a COM error relating that the “SendUsing” configuration value is not defined. To fix this problem, make sure you set the value of the SMTP server in your code. (something like SmtpMail.SmtpServer = “localhost”;) Then, things will work like a charm. Of...

VS.Net 2005 May CTP, adding assembly reference to Web project

I couldn't find a way to add an external project reference to my Whidbey web project, so I googled for answers. Instead, I found that Matt Hawley, among others was having the same problem. Well, Matt hasn't looked hard enough! :-) The answer is right there in the Readme: 13.19. The Add Reference button in property pages dialog boxes does not work  Steps to reproduce: Start Visual Studio 2005. Create a new Web site.Right-click the Web project in Solution Explorer and click Property Pages on the shortcut menu.Click Add Reference.Nothing happens.   To resolve this issue   To add a reference to a managed assembly: Create a /Bin...

I hope Whidbey MembershipProvider API changes before release

I started looking closer at the upcoming provider model in ASP.NET 2.0 and found some troubling patterns in current incarnation of the API (as of the May 2004 CTP). One example is MembershipProvider.ChangePassword method with the following signature: public abstract bool ChangePassword( string name,  string oldPassword,  string newPassword); Can anyone spot a problem? I'll give you a hint, look at the return type. Now, without looking at the docs, can you tell me without a shadow of a doubt what that boolean value indicates? I didn't think so. In this case, the API follows the old C convention of returning a boolean value to...

Wesner on the evolution of code editors, part 2

Wesner responded to my previous comment and pointed to an article describing SCID, Source Code As Database concept. I've also taken a look at the old Lutz Roeder presentation (MS PowerPoint) where he is toying with similar ideas. In the end, I think we are agreeing more than we are disagreeing. That is to say, that having the IDE become intimately aware of the code that is being created within it is a great thing. However, and this is a biggie for me and I think is the point where Wesner and I part ways: I want the IDE to use...

Wesner on the evolution of code editors

Wesner Moise wrote a post predicting that code editing capabilities in VS.NET 2005 will be behind the competition by the time it ships. I agree with the premise but disagree with the analysis. Wesner asserts that the advent of macro-less, easily parsable languages like C#, VS.NET, and Java opens the door for IDE's to work with parse trees. He correctly points out the benefits of this that will come through IDE intelligence about code (rather than just text). But then he goes off the deep end predicting that developers will work with a graphical representation of this parse tree directly. I just don't see...

.NET String.Replace() performance uncovered

In a previous entry I ran into some unexpected results with the performance of String.Replace() in .Net Framework 1.1. Upon further digging, it turns out that Replace is only fast when the input string does not contain the string (or character) that is intended for replacement. When the string does contain it, the performance of CleanString class drops, and, as expected, the character array exhibits better perf. So here's an updated bit of code that behaves no worse than original when there is nothing to replace and better than original when there is cleaning to do: ...

Unexpected string performance in .Net 1.1

A project I started recently centered around improving performance of some existing code. My first inclination was to scan the code for obvious low hanging fruit and one of the first methods I hit upon was this: 1: public static string CleanString(string Text) 2: { 3: // cleans a string for fuzzy matching 4: // trims white space, and removes numbers 5: 6: Text = Text.Trim(); 7: Text = Text.Replace("0",""); 8: Text = Text.Replace("1",""); 9: Text =...

Missing VSS menus in VS.NET 2003

I opened up VS.NET 2003 today and realized that the Source Control menus were nowhere in sight. So if that happens to you, quick tip: register the SSSCC.dll and everything will be OK again. First, locate SSSCC.dll on your machine, typically located in the win32 folder of your Visual SourceSafe installation. Then open a command prompt in that folder and run the following command “regsvr32 ssscc.dll”. Restart VS.NET and all should be well. Good luck!

Filter out WinCE documentation from MSDN

There is a great tip and discussion on Saurabh's blog on the subject on filtering out WinCE documentation from the MSDN search results. But why stop there, WinCE is not the only less used (useful?) topic set in MSDN that has a lot of overlap with other API. How about a way to filter out FoxPro docs?

Googe (Toolbar) does evil, customer blames Microsoft

The customer in this case is me. You can catch all the gory technical details in my previous post. The gist of the issue is that the popup blocker that is part of the Google Toolbar has a nasty way of silently defeating certain Internet Explorer functionality that may have absolutely nothing to do with popping up an annoying ad. The worst part about it is that Google Toolbar is otherwise a fine piece of software that does give you both visual and sound cues when it catches and stops popups. This started two days ago when I discovered that part of...

JavaScript OnUnload event broken in IE6

[Update: This blog post sets up the problem, though it appears I was pointing the finger the wrong way. It turns out the problem was caused by Google Toolbar. See my followup post for more details.] The JavaScript / JScript onunload event is notoriously unreliable from browser to browser. Reading though various USENET posts leads me to believe that the behaviour is slightly different between Mozilla derivatives, Opera, and IE. That sucks but is nothing new. What is, however, annoying is that behaviour differs on the same browser. A few months ago I coded up some functionality that persisted state back to...

DevDays 2004: attendee demographics.

One more comment on DevDays: is it just me or are developers getting older? Looking around, it appeared to me like the average age of attendees was pushing high thirties. Made me feel decidedly young. Is it that there is no fresh blood in Valley? Was this event marketed only to the “senior” people? Should I remove the quotes? Or have all the younger devs defected to the OSS side? On the other hand, there was much comfort (yes, I am being sarcastic) in there being only 2.35 women in the audience. It looks like on that front things haven't changed at all....

DevDays 2004 San Francisco

Today I attended the Microsoft DevDays 2004 event in San Francisco. Overall, I'd give it a 6.5 out of 10. Better than a six but not quite a seven (how is that for redundant?). I stayed with the Web Security track, so my impression is based on those sessions. I missed the larger chunk of the opening keynote, but the last 20 minutes or so that I did catch did not impress. Perhaps it was because I am already familiar with Reporting Services and Whitehorse, or maybe it was because the presenters did not exude confidence or excitement, or perhaps it...

Suggestions for VS.NET IntelliSense

Anson Horton asked how people are using IntelliSense in VS.NET. He mentions at least two modes: typing and browsing. There is another mode that I would love to see and that is prototyping. In the example than Anson gave, when the user starts typing after the “dot” and is typing a method or property that does not exist, I would like to see IntelliSense give up instead of forcing an existing closest match onto the user. Instead, I would like to see a progression that goes something like this: someVar.|   <- at this point IntelliSense dropdown appears someVar.Undef|   <- at this point IntelliSense should...

C# Frequently Asked Questions

Another worthwhile Microsoft blog: C# Frequently Asked Questions.

Windows Media PLayer 9 Error Codes

Via Sean Alexander, “Troubleshooting Windows Media Player 9 Series Error Codes”. Awesome!

How to apply TDD to web development?

Craig Andera writes about his entry into the world of TDD. This is something I'd like to try but I primarily develop Web apps. Does anyone have any advice for applying TDD to the world of ASP.NET? [Update: TSS posts an article on the subject:]