tag:blogger.com,1999:blog-91759372024-02-22T04:48:52.251-05:00Thanh Hai Tran's Techie Blog v3.0No longer eating and sleeping around computers, but still much senseless babbling.th2tranhttp://www.blogger.com/profile/18129661984008864019noreply@blogger.comBlogger122125tag:blogger.com,1999:blog-9175937.post-3955555150718616732013-09-27T18:46:00.002-04:002020-01-31T22:34:05.849-05:00New journeyI've embarked on a <a href="http://blog.kadople.com/">new journey</a>. For now, this techie blog is considered retired until further notice. Oh, and I also keep a blog in Vietnamese at <a href="https://th2tran.ca/">th2tran.ca</a>.th2tranhttp://www.blogger.com/profile/18129661984008864019noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-21678872328946462522012-02-06T23:09:00.001-05:002012-02-06T23:15:05.423-05:00Farewell @codinghorror<p>Really enjoyed reading <a href="http://twitter.com/codinghorror">@codinghorror</a>’s <a href="http://www.codinghorror.com/blog/2012/02/farewell-stack-exchange.html">last post</a>.  I echo this reader’s comment: </p> <blockquote> <p><em>I think it's pretty cool with all the "startup ra ra ra" bullshit that's popular right now, to see someone high profile say "fuck it, it's not that important"</em></p> </blockquote> <p>Thank you, Jeff! You definitely changed this corner of the world for the better. </p> <p>In death, Steve Jobs probably teaches a much better lesson than he could ever do while alive.</p> th2tranhttp://www.blogger.com/profile/18129661984008864019noreply@blogger.com2tag:blogger.com,1999:blog-9175937.post-2984574038554636452011-06-04T00:29:00.001-04:002011-06-04T00:45:40.705-04:00A simple vow<p>Starting tomorrow, I will continue to greet and speak to my Chinese friends as if nothing has changed. However, in order to show my love and solidarity towards a homeland on which I once felt like an outcast,  I will, from now on, go out of my way to avoid buying “made in china” products. This is but <a href="http://www.smh.com.au/world/vietnam-accuses-china-of-sabotage-20110601-1fgec.html">one</a> in many examples of why:</p> <p><iframe height="349" src="http://www.youtube.com/embed/QdCuDj9_j6A" frameborder="0" width="425" allowfullscreen="allowfullscreen"></iframe></p> <p>This ain’t gonna be easy, as it excludes any future possibility of owning an iPad. But it’s the principle of the thing.</p> th2tranhttp://www.blogger.com/profile/18129661984008864019noreply@blogger.com1tag:blogger.com,1999:blog-9175937.post-77411079672619658592011-06-01T23:33:00.001-04:002011-06-01T23:33:09.189-04:00Workaholic culture (still)<p>From the <a href="http://engineering.twitter.com/2011/05/engineering-behind-twitters-new-search.html">Twitter Engineering blog</a>:</p> <blockquote> <p>While on vacation in Germany, Michael Busch, one of our search engineers, implemented a demo of image and video search. A few weeks later, during Twitter's first <a href="http://engineering.twitter.com/2010/10/hack-week.html">Hack Week</a>, the search team, along with some members of other teams, completed the first demo of our new search experience. Feedback from the company was so positive that the demo became part of our product roadmap.</p> </blockquote> <p>Impressive. But it reminds me of this CNN article I saw the other day, <a href="http://articles.cnn.com/2011-05-23/travel/vacation.in.america_1_vacation-germans-long-holiday?_s=PM:TRAVEL">Why is America the 'no-vacation nation’?</a>,  which starts with this line:</p> <blockquote> <p>Let's be blunt: If you like to take lots of vacation, the United States is not the place to work.</p> </blockquote> <p>I think this all started when I brought my sleeping bag into work one day back in 1999. Depressing.</p> th2tranhttp://www.blogger.com/profile/18129661984008864019noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-11125577881574211422011-04-15T01:18:00.001-04:002011-04-15T01:21:32.936-04:00Them’s fight’n woyds!<p><a href="https://www.expensify.com/">Expensify</a>‘s CEO on “<a href="http://blog.expensify.com/2011/03/25/ceo-friday-why-we-dont-hire-net-programmers/">Why we don’t hire .NET programmers</a>”:</p> <blockquote> <p><em>Programming with .NET is like cooking in a McDonalds kitchen.  It is full of amazing tools that automate absolutely everything.  Just press the right button and follow the beeping lights, and you can churn out flawless 1.6 oz burgers faster than anybody else on the planet. <br />…</em></p> <p><em>So what’s the moral of this whole story?  Two things:</em></p> <ol> <li><em>If you ever want to work in a startup, avoid .NET.  It does you no favors. </em></li> <li><em>If you are a startup looking to hire really excellent people, take notice of .NET on a resume, and ask why it’s there. </em></li> </ol> </blockquote> <blockquote> <p></p> </blockquote> <p>I recently knew of Expensify by reading <a href="http://www.windley.com/archives/2011/03/leave_the_services_clients_to_the_services_and_build_something_really_interesting.shtml">this blog entry</a> by Phil Windley. I can only guess from Mr. Barrett‘s conclusion that Expensify gets alot of resumes from .NET developers. From the employer’s perspective, following the law of averaging, it makes perfect sense. If your software platform is Linux, PHP and Bash, why would you hire a .NET developer? Rather, underlying the above two points is an implicit advice to startup employers—don’t use .NET technologies—which, I daresay, is ill-conceived. But hey, I’m not a CEO of a company. Not yet anyway. ;-)</p> <p>In the end, probably nothing more than simply a publicity stunt.</p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-34585655903247116452011-04-05T18:33:00.001-04:002011-04-06T00:13:53.562-04:00What to do when CryptAcquireContext() fails<p>I’m using CryptoAPI to do encryption and encountering an error on Win2008 Terminal Server which enforces Mandatory Profiles. <em>CryptAcquireContext()</em> fails with a message of either “<em>keyset not found</em>” or “<em>The profile for the user is a temporary profile</em>”.</p> <p>I’ve tried the same test on WinXP using a guest account and got the same thing.</p> <p>So, what gives? </p> <p>Well, this blog post (<a href="http://blogs.msdn.com/b/alejacma/archive/2007/10/23/rsacryptoserviceprovider-fails-when-used-with-mandatory-profiles.aspx">RSACryptoServiceProvider fails when used with mandatory profiles</a>) way back in 2007 by <a href="http://blogs.msdn.com/b/alejacma/">@alejacma</a> explains:</p> <blockquote> <p>CryptAcquireContext will fail with <strong>NTE_TEMPORARY_PROFILE</strong> error when called from a mandatory profile. </p> <p>Mandatory profiles are read-only user profiles. Since changes to the mandatory profile cannot be saved, PKI design doesn't allow this operation, and CryptAcquireContext prevents this scenario by failing.</p> </blockquote> <p>The moral of this story is: RSA sucks, and I am now Rijndael’s new biggest fan.</p> <p>By the way, troubleshooting this problem had given me the chance to learn a few more WinDbg commands:</p> <pre>.sympath srv*http://msdl.microsoft.com/downloads/symbols<br />.sympath+ c:\localsymbols<br />.reload –f<br />bm /a advapi32!CryptAcquireContext*</pre> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-44934479878690468662011-03-17T02:33:00.001-04:002011-03-17T02:56:50.219-04:006 months<p>The following event is happening to me now. There is a certain business Internet service provider in Toronto whose sales guy signed me up on an agreed network speed, whose installation technician, upon arrival at our site, made a judgment that they could never provide service at said speed and aborted the install, who sent us a bill 30 days later for service never rendered, which thus far has taken me 6 months to fight for a refund. I’m stuck with a jaded feeling as I sit here now preparing to fax back a copy of the receipt proving to them that I did indeed return their modem. This internet provider uses a third party to process equipment returns.</p> <p>The following event happened to me a couple of years ago. There is a certain home building materials vendor in Toronto, who uses a third party for their credit provisioning, who miscalculated my returns on their monthly statement, which took 6 months for me to successfully dispute the discrepancies.</p> <p>A couple of conspiracy theories is now bubbling in my head.</p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-26710188895500793382011-03-08T02:01:00.001-05:002011-03-08T02:07:47.481-05:00XmlSerializer and the "Specified" suffix<p>It took me 3 hours to figure out why <em>XmlSerializer</em> wasn’t writing out a particular class property. <a href="http://stackoverflow.com/questions/4261038/xmlserializer-specified-suffix-and-ireflect">This </a>is why:</p> <blockquote> <p>…if a serializable <em>Field/Property</em> has a corresponding field of type <em>Boolean</em> having as a name the <em>Field/Property</em> name with "Specified" suffix, the XmlSerializer conditionally exclude that <em>Field/Property</em> from the serialization process.</p></blockquote> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-53506223614902136712011-02-17T00:50:00.001-05:002011-02-17T01:04:36.866-05:00DateTime Serialization to XML<p>I have an C# serializable object with a DateTime property like this:</p> <pre class="brush: csharp"> public class MyClass {<br /> public DateTime Date1 {get;set;}<br /> }</pre><br /><p>When serialized to XML, it gives me something like this</p><br /><pre class="brush: xml"> <MyClass><br /> <Date1>2010-11-30T00:00:00</Date1><br /> </MyClass></pre><br /><p>I could not get it to give me this, which is in the proper  <em><a href="http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#date">xml date</a></em> format:</p><br /><pre class="brush: xml"> <MyClass><br /> <Date1>2010-11-30</Date1><br /> </MyClass></pre><br /><p>After a couple of wasted days, it turned out that <a href="http://msdn.microsoft.com/en-us/library/ms950721.aspx">the solution</a> is really simple:</p><br /><pre class="brush: csharp"> public class MyClass {<br /> [System.Xml.Serialization.XmlElement("Date1", DataType="date")]<br /> public DateTime Date1 {get;set;}<br /> }</pre> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-27235521794332678642011-02-12T15:34:00.001-05:002011-02-12T15:51:35.533-05:00Does your employer own your side projects?<p>Apparently, according to <a href="http://joelonsoftware.com/">Joel Spolsky</a>, they do:</p> <blockquote> <p>…So before you hire this guy, you agree, "hey listen, I know that inventing happens all the time, and it's impossible to prove whether you invented something while you were sitting in the chair I supplied in the cubicle I supplied or not. I don't just want to buy your 9-5 inventions. I want them all, and I'm going to pay you a nice salary to get them all," and he agrees to that, so now you want to sign something that says that <em>all</em> his inventions belong to the company as long as he is employed by the company.</p> <p>This is where we are by default. This is the <em>standard</em> employment contract for programmers, inventors, and researchers. <br />[Read rest of the discussion at <a href="http://answers.onstartups.com/questions/19422/if-im-working-at-a-company-do-they-have-intellectual-property-rights-to-the-stu/">answers.onstartups.com</a>…]</p> </blockquote> <p>One Interesting corollary: if you spend your day-time working for an employer and night time working on a <a href="https://github.com/">github</a> open source project, and 2 years from now the OS project becomes wildly popular (wink), your open source project is probably not very “open” afterall, unless you’ve had the appropriate work-for-hire clauses stipulated in your employment agreement. I’m reminded of a vaguely similar case in recent history: the infamous <a href="http://en.wikipedia.org/wiki/SCO_v._IBM">SCO v. IBM</a> debacle from a few years back.</p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-43276383914347596752011-01-31T18:01:00.001-05:002011-02-04T14:04:10.620-05:00Convert string to DateTime object<p>Two C# functions that may be useful in accepting date/time strings of various formats:</p> <pre class="brush: csharp"> /// <summary><br /> /// Converts date string value, of various formats into DateTime object. <br /> /// Example formats are DDMMYYYY,DD/MM/YYYY,MM/dd/YYYY,MMDDYYYY,... <br /> /// </summary><br /> /// <param name="dateValue">date string</param><br /> /// <returns>resulting DateTime object</returns><br /> public DateTime ConvertDateStringToDateTime(string dateValue) {<br /> string[] dateFormats = { "MM/yyyy",<br /> "M/d/yyyy", "M/dd/yyyy", "MM/dd/yyyy",<br /> "dd/MM/yyyy", "ddMMyyyy","dd/MM/yyyy","MMddyyyy", <br /> "MM-dd-yyyy" };<br /> try {<br /> return DateTime.ParseExact(dateValue, dateFormats, CultureInfo.CurrentCulture, DateTimeStyles.None);<br /> } catch (FormatException fe) {<br /> throw new DataException(dateValue + ": " + fe.Message);<br /> }<br /> }<br /><br /> /// <summary><br /> /// Converts a time string of various formats into a DateTime object.<br /> /// Example formats are: 7:00,700AM, 7:00AM, 7:00A, 0700AM, 07:00 AM, ... <br /> /// </summary><br /> /// <param name="timeValue">time string</param><br /> /// <returns>resulting DateTime object</returns><br /> public DateTime ConvertTimeStringToDateTime(string timeValue) {<br /> string[] timeFormats = {"HHmm","Hmmtt", <br /> "H:mm", "H:mmtt", "H:mmt", "HHmmtt", "HH:mm tt", "HH:mmtt","HH:mmt", "HHmmtt", "HHMMt"};<br /> // DateTime string cannot be blank, so if it is, assume "00:00"<br /> if (string.IsNullOrEmpty(timeValue)) timeValue = "00:00"; <br /> try {<br /> return DateTime.ParseExact(timeValue.ToUpper(), timeFormats, CultureInfo.CurrentCulture, DateTimeStyles.None);<br /> } catch (FormatException fe) {<br /> throw new DataException(timeValue + ": " + fe.Message);<br /> }<br /> }</pre> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-86977424099450337612011-01-29T16:12:00.001-05:002011-01-31T00:08:19.674-05:00Blog v3.0<p>This old techie blog of mine seemed to be dead silent lately that I feel compelled to resurrect it. </p> <p>Let’s review a bit of history: In my mind, version 1.0 of my blog was on Bloglines (circa 2004). Version 2.0 was when I switch to blogspot and <a href="/2006/08/new-look.html">using the Kubrick theme</a>.  It’s now time once again to resharpen the toolkit, beginning with a fresh new look, hat tip to the fine folks at <a href="http://www.deluxetemplates.net">Deluxe Templates</a> for the <a href="http://www.deluxetemplates.net/2009/06/inove-blogger-template.html">iNove theme</a>.  </p> <p>TODO: I like this theme, but one thing I might change is to make a little more room for the content pane. </p> <p>Also trying to install Alex Gorbatchev’s <a href="http://alexgorbatchev.com/SyntaxHighlighter">SyntaxHighligher</a> scripts. Let’s see if this works:</p> <pre class="brush: csharp"> /**<br /> * Sample code in C# to test SyntaxHighlighter.<br /> */<br /> public Argument ArgueWith(Person person) {<br /> if (person == null) {<br /> throw new ArgumentException("no object to argue with");<br /> }<br /> // prepare argument<br /> Argument arg = new Argument(person);<br /> return arg;<br /> }</pre><br /><br /><p><em>Update 01/30/2011 11:44pm EST: </em>SyntaxHighlighter worked great. I had to use <a href="http://db.tt/onPSA3Y">dropbox.com</a> to host the scripts. I think I spotted a bug, though, on Safari for iOS 4.1: line number is a bit out of whack.  Let’s have a closer look at <a href="http://pastebin.com">PasteBin</a>, as Gavin suggested:</p><br /><script src="http://pastebin.com/embed_js.php?i=FwULfJQC"></script> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com3tag:blogger.com,1999:blog-9175937.post-50079780292449770502010-05-17T15:22:00.001-04:002010-05-17T15:42:16.961-04:00Debugging hybrid VB6/C/C# app crashes with WinDbg<p>I was troubleshooting one of two (2) different app crashes this past week in which the app simply dies without any prior warning.  At first I thought: crappy VB6! But then, after looking in the <em>Event Log</em>, I found out this was not Visual Basic 6.0 Runtime’s fault, but rather it’s the .<em>NET Runtime version 2.0 Fatal Execution Engine</em> that erred fatally. Below is how I went about debugging the crash.</p> <p>First of all, two sets of tools are needed:</p> <ol> <li><a href="http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx">Debugging Tools for Windows</a> (WinDbg) </li> <li>Debugging symbol (.pdb) files. These are useful but not essential.   PDB files are generated automatically in Visual Studio .NET, and can be turned on in VB6 IDE via the project properties under the <strong>Compile</strong> tab. </li> </ol> <p>In using WinDbg to troubleshoot app crashes, I found this blog post <a href="http://blogs.msdn.com/johan/archive/2008/01/31/using-windbg-hunting-exceptions.aspx">Using WinDbg - Hunting Exceptions</a>  by <a href="http://blogs.msdn.com/johan/default.aspx">Johan Straarup</a> to be tremendously helpful.</p> <p>As anyone who’s ever involved in troubleshooting any software bug would know, the hardest part is to reproduce it in a consistent manner, and an app crash is (or should be) the rarest (and most feared by programmers) of bugs. Yet, an app crash is nothing more than an exception that has gone uncaught by the application.</p> <p>In WinDbg, I used the <strong>Attach to a Process</strong> menu option to connect to the running app. Then, I issued the <strong>gn </strong>command (Go [until] Unhandled Exception) command, and let the app run its course.  Eventually, it came a stop with this message:</p> <blockquote> <p>(4a4.1e4): CLR exception - code e0434f4d (!!! second chance !!!) <br />eax=0129ecfc ebx=0017d328 ecx=00000000 edx=00000025 esi=0129ed88 edi=e0434f4d <br />eip=7c812afb esp=0129ecf8 ebp=0129ed4c iopl=0         nv up ei pl nz na po nc <br />cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202 <br />…</p> </blockquote> <p>I then used “<em>!analyze –v”</em> and subsequently “!pe”, which gave me this:</p> <p><code>0:002> !PrintException <br />*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll - <br />PDB symbol for mscorwks.dll not loaded <br />Exception object: 019138a0 <br />Exception type: System.IO.FileLoadException <br />Message: Could not load file or assembly 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) <br />InnerException: <none> <br />StackTrace (generated): <br />    SP       IP       Function <br />    00000000 00000001 MyAssembly1.MyClass1.Finalize() </code></p> <p>So, this crash was the result of a referenced assembly version mismatch in one of the plugin components. That's one easy problem solved. </p> <p>The other crash is a bit more elusive, which, after two weeks, I'm still in the process of trying to reproduce. </p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com3tag:blogger.com,1999:blog-9175937.post-6874991341564211792009-09-24T13:59:00.001-04:002009-09-24T17:53:32.998-04:00FF 3.5.3 crashed again<p>My Firefox 3.5.3 crashed again for the third time today:</p> <blockquote> <p><font size="1">Add-ons: {2B8EFF80-1240-11DB-BF6C-934CD2EFDFE8}:20080728.334,{CF40ACC5-E1BB-4aff-AC72-04C2F616BCA7}:1.5.2.35,toolbar@alexa.com:1.3.0,{2fa4ed95-0317-4c6a-a74c-5f3e3912c1f9}:2.1.062,firebug@software.joehewitt.com:1.4.2,{d37dc5d0-431d-44e5-8c91-49419370caa1}:2.5.35,{e4a8a97b-f2ed-450b-b12d-ee082ba24781}:0.8.20090123.1,{CAFEEFAC-0016-0000-0007-ABCDEFFEDCBA}:6.0.07,{CAFEEFAC-0016-0000-0011-ABCDEFFEDCBA}:6.0.11,{CAFEEFAC-0016-0000-0015-ABCDEFFEDCBA}:6.0.15,LogMeInClient@logmein.com:1.0.0.460,{B7082FAA-CB62-4872-9106-E42DD88EDE45}:3.0,{20a82645-c095-46ed-80e3-08825760534b}:1.1,pencil@evolus.vn:1.0.6,refractor@developer.mozilla.org:1.0b2,twitternotifier@naan.net:1.8.3,web@veoh.com:1.4,{972ce4c6-7e08-4474-a285-3208198ce6fd}:3.5.3 <br />BuildID: 20090824101458 <br />CrashTime: 1253813633 <br />InstallTime: 1252611358 <br />ProductName: Firefox <br />SecondsSinceLastCrash: 70976 <br />StartupTime: 1253811215 <br />Theme: classic/1.0 <br />Throttleable: 1 <br />URL: about:blank <br />Vendor: Mozilla <br />Version: 3.5.3 </font></p> </blockquote> <p>This happened while I was doing Google searches…probably one of the add-ons’ fault (probably the Alexa toolbar).  </p> <p><em><strong>Update 17:40 EDT</strong>: It’s not the Alexa toolbar. Next guess: McAfee SiteAdvisor 3.0</em></p> <p>One of the design goals that one should aim to achieve, when building any plug-in architecture, is <em>isolation</em>, to the extent that  a crash in one of the  plug-ins should not bring down the entire application. </p> <p>Somehow, that is very hard to do, isn’t it? </p> <p>Guilty as charged.</p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com1tag:blogger.com,1999:blog-9175937.post-58335423473226472342009-09-01T16:40:00.001-04:002009-09-01T16:40:57.565-04:00COMException : Creating an instance of the COM component with CLSID {…}<p>I recently changed my <a href="http://nant.sourceforge.net/">NAnt</a> build script, as part of its post-build cleanup step,  to unregister all .NET COM interop components after doing the build. Now my unit tests fails with this error:</p> <blockquote> <p><em><font size="1">System.Runtime.InteropServices.COMException : Creating an instance of the COM component with CLSID {596C3AA2-D5EC-4F86-85E3-7FAF86EC17A3} from the IClassFactory failed due to the following error: 800a005b.</font></em></p> </blockquote> <p>What’s the cause? </p> <p>Here are the facts: My .NET lib X depends on a  COM lib Y (596C3AA2-D5EC-4F86-85E3-7FAF86EC17A3), which depends on COM lib Z, which in turn invokes  .NET COM interop lib N.</p> <p>It turns out that the real culprit was N, which wasn’t registered for some reason, even though I’ve told it to register via the <em>regasm</em> NAnt task.</p> <p>Well, as it turned out, I needed to add the <em>codebase=”true”</em> attribute to the <em>regasm</em> task that registers N, which makes sense in hindsight, because my DLLs are not all in the same directory. Another “doh!” I suppose.</p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com1tag:blogger.com,1999:blog-9175937.post-34668740096198183182009-08-24T18:13:00.001-04:002009-08-24T18:13:45.197-04:00AccessViolationException in OpenFileDialog.ShowDialog()<p>Note to self:  Next time I get this error, when running in a 64-bit OS, make sure to specify x86 for <em>Platform target</em> in the Build options.</p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-75551728690510383992009-08-01T08:58:00.001-04:002009-08-01T09:06:43.327-04:00PageRequestManagerParserErrorException<p>Good <a href="http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx">tips</a> from <a href="http://weblogs.asp.net/leftslipper/default.aspx">Eilon Lipton</a> on this error:</p> <p><code>Microsoft Internet Explorer <br />--------------------------- <br />Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.</code></p> <p>I suppose I fell into trap #5 listed on the article.  I was looking to do parameter passing from the current page to the redirected page. Basically, I had a general “catch all” event handler that catches unhandled exception, and forwards the detail to an error display page.  There doesn’t seem to be any direct way of passing parameters from one  .aspx page to another. So I stuffed this parameter into the <em>HttpContext</em> object.  The problem is: <em>Reponse.Redirect()</em> wipes out all parameters stored in the context. This problem doesn’t happen if I use <em>Server.Transfer()</em>.</p> <p>All of this was happening inside an <em>UpdatePanel</em>,  just as Eilon explained.  Hence, the <em>PageRequestManagerParserErrorException</em>. I looked in my <a href="http://www.errorstack.com/">ErrorStack</a>, saw what the originating error was, fixed it, and the <em>PageRequestManagerParserErrorException </em>was gone. </p> <p>I guess the next step would be to figure out how to display the error properly when invoked from an <em>UpdatePanel</em>, as it is working well everywhere else. </p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-4772436555701677812009-06-29T12:48:00.002-04:002009-06-29T12:51:58.871-04:00Wow!I want a Mac for Christmas:<br /><object width="450" height="370"><param name="movie" value="http://www.liveleak.com/e/adf_1245828170"></param><param name="wmode" value="transparent"></param><embed src="http://www.liveleak.com/e/adf_1245828170" type="application/x-shockwave-flash" wmode="transparent" width="450" height="370"></embed></object><br /><br />Just kidding.Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-6817999410376014522009-06-18T12:16:00.001-04:002009-06-18T12:16:47.830-04:00Flight scheduling system test case: flight number re-use<p>Scenario:</p> <ul> <li>Mom books a flight from airline X, gets assigned flight number 123, arriving at airport YYZ @ 5:45am </li> <li>Mom tells son: “my flight #123 arrives tomorrow @ 5:45am” </li> <li>“Tomorrow” comes. Son goes online and checks flight info, which states that flight 123 is on-time. </li> <li>6:15am: son arrives at YYZ to pick up mom. </li> <li>Son checks the Arrivals Fight Info board, which says flight 123 has landed. Son waits at the Arrivals Area. </li> <li>Three hours later. Mom was “no show”. Son calls mom, who says “oh, did I say ‘today’? I meant ‘tomorrow’. Tomorrow @ 5:45am.” </li> </ul> <p>Why someone would design a flight number assignment algorithm such that any X flight departing XXX for YYZ at time hh:mm, on any day of the week, would get assigned the exact same flight number, is beyond me. Are flight numbers so scarce that they have to reuse the same numbers every day? </p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-60801774212934284852009-06-12T22:56:00.001-04:002009-06-12T23:30:30.047-04:00LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method<p>I’ve been dabbling with the <a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework">ADO.NET Entity Framework</a> in .NET 3.5, was trying to convert this SQL WHERE clause, which uses the LIKE operator, into LINQ syntax:</p> <blockquote> <p><font size="1"><em>String strWhereClause = String.Format(CultureInfo.CurrentCulture, "Type={0} AND Name LIKE '*{0}*'", orgType, orgName); </em></font></p> </blockquote> <p>I read somewhere which suggested to use the <em>SqlMethods</em> helper class. So I tried:</p> <blockquote> <p><em>var objQuery = repository.Organization.Where(vendor => vendor.Type == orgType && SqlMethods.Like(vendor.Name, "”%” + orgName + “%”)); </em></p> </blockquote> <p>The query is targeting an <em>Organization</em> table. <em>repository</em> is an instance of an <em>ObjectContext</em> subclass which has been  auto generated by Visual Studio’s ADO.NET Entity Data Model wizard.  <em>orgType</em> and <em>orgName</em> are passed-in parameters.</p> <p>The above approach resulted in the following runtime error (notice the redundant occurrence of the word ‘method’ in the error message):</p> <blockquote> <p><font size="1"><em>LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method, and this method cannot be translated into a store expression</em></font></p> </blockquote> <p>I then saw <a href="http://stackoverflow.com/questions/835790/how-to-do-sql-like-in-linq">a post</a> on <a href="http://stackoverflow.com">stackoverflow</a> which suggested to use <em>Contains()</em>, <em>StartsWith()</em>, or <em>EndsWith() to mimick the LIKE operator</em>. So I tried:</p> <blockquote> <p><font size="1"><em>var objQuery = repository.Organization.Where(vendor => vendor.Type == orgType && vendor.Name.Contains(orgName)); </em></font></p> </blockquote> <p>This works, but if <em>orgName.Length</em> is zero, then the query returns zero rows.  So finally, a slight mod to the above query achieved the desired effect:</p> <blockquote> <p><font size="1"><em>var objQuery = repository.Organization.Where(vendor => vendor.Type == orgType && (orgName.Length == 0 || vendor.Name.Contains(orgName))); </em></font></p></blockquote> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com28tag:blogger.com,1999:blog-9175937.post-58118264530804890362009-06-12T17:03:00.001-04:002009-06-12T17:06:25.476-04:00“The underlying provider failed on Open.”<p>I’m deploying my ASP.NET app to a brand new server with a fresh install of SQL Server 2008 Express. The db connection step failed with this error:</p> <blockquote> <p><font size="1"><font face="Courier New"><b>Message:</b> The underlying provider failed on Open. <br /><font face="Courier New"><font size="1"><b>StackTrace:</b>  at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) at System.Data.EntityClient.EntityConnection.Open() at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1</font> forMergeOption)</font></font></font></p> </blockquote> <p>I checked the <em>connectionString</em>, which uses Windows authentication, and it looked fine.</p> <p>Somebody <a href="http://www.eggheadcafe.com/conversation.aspx?messageid=34423314&threadid=34336970">suggested</a> to <em>Allow Remote Clients</em> in the <em>Network DTC Access</em> settings. That option is already enabled on my environment.</p> <p>I looked at the Event Viewer, and noticed this entry:</p> <blockquote> <p><font face="Courier New" size="1">Event Type:    Failure Audit <br />Event Source:    MSSQL$MSSQL <br />Event Category:    Logon <br />Event ID:    18456 <br />User:        NT AUTHORITY\NETWORK SERVICE <br />Description: <br />Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]</font> </p> </blockquote> <p>So IIS is trying to access the database under the credential   'NT AUTHORITY\NETWORK SERVICE' .  I looked that the db settings via <em>SQL Server Management Studio</em> and, sure enough, that account is not listed as one of the users allowed to connect. So I added him. And the web app was able to connect successfully. </p> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com59tag:blogger.com,1999:blog-9175937.post-29923610291579329082009-06-09T14:25:00.001-04:002009-06-09T16:38:20.268-04:00Which config file to put the db connectionString for ADO.NET (3.5) Entity Data Model?<p>Normally this goes in the App.config. VS2008 designer wizard automatically creates this file and puts it in the same location as the  assembly in which your database layer resides. But if you’re calling that assembly from an ASP.NET app, you’ll  need to move that <em>connectionString</em> to the Web.config.  Otherwise, you’ll get this error upon  instantiation of the <em>ObjectContext</em>: </p> <blockquote> <p><em>The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.</em></p></blockquote> Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com1tag:blogger.com,1999:blog-9175937.post-40340383557659125222009-05-30T08:53:00.003-04:002009-05-31T06:24:13.818-04:00Google Wave<p>Just watched the <a href="http://wave.google.com/">Google Wave</a> <a href="http://bit.ly/qqpfM">demo</a>, via <a href="http://twitter.com/tylerwhitaker/status/1955949102">@tylerwhitaker</a>. Board game playing via email--I've thought of this before but seeing it implemented with Wave is so much cooler!</p> <br /><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/v_UyVmITiYQ&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/v_UyVmITiYQ&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="304"></embed></object>Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-31503854981372269652009-05-08T16:42:00.000-04:002009-05-08T16:48:48.142-04:00Appropriate levels of abstractionI've learned over the years, through the many facets of my job, to don a different hat depending to whether I'm talking to a programmer, a business person, or an end user.<br /><br />Which is why it always freaks me out when I see my fellow developers showing my CEO how to run regasm to get a particular new product feature to work. Good God!<br /><br />I guess in some sense it's good, because now when something is not working quite right, my CEO would ask "Do I need to rerun regasm?"th2tranhttp://www.blogger.com/profile/18129661984008864019noreply@blogger.com0tag:blogger.com,1999:blog-9175937.post-40274211169794401492009-04-02T16:45:00.004-04:002009-04-04T21:21:49.321-04:00Why does UnhookWindowsHookEx() fail?<p>I’m debugging a Windows hook DLL that’s misbehaving. Actually I’m still not sure whether it’s the hook DLL, or the C# library that calls it, that is the culprit. Here’s the problem symptom. My app DLL installs a mouse hook into a running application. The running app terminates. My app detects that it has terminated and attempts to remove the hook—this fails (1). On subsequent startup of the app in question, I try to re-install the hook onto it, and that fails (2). I’m actually more interested in failure #2 than failure #1, but the latter is probably a consequence of the former. So I needed to track down why #1 happened.</p> <p>Side fact:</p> <blockquote> <p>When you install a thread-specific Windows hook, your hook DLL is actually loaded in 2 places: one instance is loaded in your app's process space, and the other in the target app's.</p> </blockquote> <p>At first, I thought that Windows was failing to do its DLL cleanup duties when the unhook step failed, so I was ready to look into manually forcing the unload and reload of the native DLL—often a bad idea to circumvent the garbage collector, but, hey, what else can you do? </p> <p>Then I spotted the culprit:</p> <blockquote> <p><span style=";font-family:Courier New;font-size:78%;" >DLLEXPORT HHOOK SetHook(HWND hWndTarget, HWND hWndListener) { <br />if(m_hWndListener != NULL) return NULL; // already hooked! <br />// install the hook via SetWindowsHookEx() <br />… <br />… <br />m_hWndListener = hWndListener;<br /></span><span style=";font-family:Courier New;font-size:78%;" > … <br /></span><span style=";font-family:Courier New;font-size:78%;" >}</span></p> <p><span style=";font-family:Courier New;font-size:78%;" >DLLEXPORT BOOL ClearHook(HHOOK hook) { <br />BOOL unhooked = UnhookWindowsHookEx(hook); <br />if (unhooked) { <br /> m_hWndListener = NULL; <br /> // do other cleanup stuff <br />} <br />return unhooked; <br />}</span></p> </blockquote> <p>It turned out: <span style="font-family:Courier New;">m_hWndListener</span> was not being cleared when UnhookWindowsHookEx() failed.</p> <p>Yet again, it goes to show that: just when I thought that the developers at Microsoft are a bunch of idiots who had no clue what they were doing when they invented the Windows API, it turns out that the idiot is me.</p> <p>As to why UnhookWindowsHookEx() failed, my guess is that the hook was already being automatically removed by the OS when the target app terminated.</p>Thanh Hai Tranhttp://www.blogger.com/profile/18371882264327750704noreply@blogger.com1