Thursday, 15 November 2012

ASP.NET 4 fails to set cookies for IE10… because it thinks it’s IE-1 ! (But there’s a hotfix)

We were seeing something odd when testers would browse to certain test servers using IE10.  The user would log in, but then a redirect would fail to happen, and the user would get kicked back to the login screen.
I tested it using IE10 on a Windows 8 virtual machine, and also tried it on my Win 7 dev machine with the IE10 preview.  Both failed in the same way.
I looked at the web traffic on the client side using Fiddler.  (What a great program!  But I just noticed, via a message that appears in the upgraded Fiddler, that they have “joined the Telerik family”.  Interesting.  They say they’re going to keep it free… fingers crossed that remains true!)
Anyway I tried hitting the test site with IE10, and then I tried it with Chrome on Windows 8; then I also tried IE 8, running on my Win 7 dev machine.  Here’s what I saw when I looked at the “Raw” view for the 302 redirect event.  The problematic string is shown in red.  It seemed to be stuffing some long encrypted string in front of the redirect URL.
IE10:
HTTP/1.1 302 Found
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Location: /(F(kxQ3Uf_87HS8e2KvJfipg5YpF8JFVG_vsAxGsIUUfvbIUfO2RkMTP7CmV_trwq5MY82TAW0sAcH5QsrNQJq7p_jpw-6_hGf1O99FzJlleWc1))/PassiveTokenServiceHandler.ashx?wtrealm=http://ourclientweb.ourclientst1.local:8882/default.aspx&realmkey=OurClientRealm
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 2.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 14 Nov 2012 09:42:10 GMT
Content-Length: 356

IE8 on Windows 7:
HTTP/1.1 302 Found
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Location: /PassiveTokenServiceHandler.ashx?wtrealm=http://ourclientweb.ourclientst1.local:8882/default.aspx&realmkey=OurClientRealm
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 2.0
X-AspNet-Version: 4.0.30319
Set-Cookie: Form_Login=145038F0A77F3C43361B30B984054913A627A7EA3AB8AA24D54F091AB7FC71ECD069AE685B32A0E1A8943F518B97974EE1D4FE2BAEBD8071A6564B6E34B179EEEE29A85F954CA3A47586782FE4A79A4D; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Wed, 14 Nov 2012 10:46:00 GMT
Content-Length: 240

Chrome on Windows 8 (desktop):



HTTP/1.1 302 Found
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Location: /PassiveTokenServiceHandler.ashx?wtrealm=http://ourclientweb.ourclientst1.local:8882/default.aspx&realmkey=OurClientRealm
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 2.0
X-AspNet-Version: 4.0.30319
Set-Cookie: Form_Login=CE02CF980D5FBE5601C57C420BE71FD03205758EE5FF2736D1DAE201A736C18B02AE52AA6EE02AB5F28670406DF981AEA230A5AABE5BA9B7006F211F5FF43B4B412EF69100F0ECE1FD9AFF05A6A6837A; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Wed, 14 Nov 2012 09:55:10 GMT
Content-Length: 240


Notice any difference, besides the fact that the Location value has the garbage string stuffed into it?  Turns out the “Set-Cookie” isn’t there.  We found this post on Stack Overflow, which looked a lot like our problem; also this post on Stack Overflow and ultimately this MS blog post.

The bottom line is, if your site is using user agent sniffing, then it will think that your IE10 client is IE1!  Notice from this Wikipedia history of Internet Explorer that cookie support didn’t come in until IE2.  That explains why in the Fiddler data above, there’s no “Set-Cookie”.

We installed the hotfix on our test servers, re-booted, and the problem went away.  You can find the hotfix here.

Reminds me somehow of the Y2K bugOpen-mouthed smile

Monday, 12 November 2012

The description for Event ID ( 3 ) in Source ( TFSShellExt ) cannot be found.

So I’ve been on a few projects for my employer Hitachi Consulting UK.  For one of them, the client was maintaining the TFS server.  At some point I finished my work on that project and moved on to other projects.  But for some reason I couldn’t get rid of the reference to the TFS server.  Visual Studio kept trying to connect to it when I would launch Visual Studio 2010, and it was failing to connect because I was no longer authorized to hit that URL, because I’m no longer on the project.  This would lead to errors in the Windows Application log that looked like the one described in this post.

I tried to clear the cache (by deleting the cache folder) as described in the aforementioned post, and also here.  But every time I tried to delete it the cache folder kept coming back.  It seems to have something to do with TFS Power Tools.

In the end what solved it for me was deleting the Cache folder, running Task Manager, killing the two processes “TfsComProviderSvr.exe”, then re-booting.  Then the Application Log messages stopped appearing when I would launch Visual Studio.  Now I can launch VS without those errors occurring.

Cheers

Dave

Wednesday, 19 September 2012

The remote procedure call failed (0x800706be)–Windows Azure SDK installation broke SQL Server Config Manager?!?


So I’ve been working on a project which is a large production web application built in ASP.NET MVC.  This is an enterprise level app which means it’s big, it’s complex, and it’s got a lot (i.e. thousands) of unit tests.
When you run all unit tests in solution in Visual Studio, and you’ve got, say, 6000 tests, the memory usage goes way up for devenv.exe, QTAgent32.exe (if you’re using 32 bit version of that; same goes for the 64 bit version, I’ve noticed); and, if you’re doing integration tests and your tests are hitting the database, then, the memory usage goes way up for SQL Server.  And, it doesn’t seem to let go of that memory (for any of those applications) when the tests are done.  (I’ve also noticed this type of behavior when I run certain database build scripts).
Well, I sometimes use the SQL Server Configuration Manager to, primarily, restart SQL Server, for example when I’ve just run a load of unit tests in Visual Studio.  (Yes you can also re-start the service from the normal Windows “Services” list, but I like to do it this way by launching a shortcut from my desktop).   Typically when I do that, it looks like this:
SQLConfigMgr
BTW the version of SQL I’m using is a developer version of SQL 2008 R2.
So anyway I’m going on my merry way, doing my daily work on that application.  Meanwhile, for a project on the side, I’m doing some experimentation with Windows Azure / SQL Azure.  So I downloaded the SDK to my dev machine (the host machine, not a VM), from here.  (I installed the WindowsAzureSDK-x64.exe).
A day or two later, I wanted to do my usual thing of restarting SQL from the config manager and instead of the list of services on the right, I saw something more like the screenshot shown in this stack overflow post.
remote-call-failed
So of course I started googling.  Most of the advice out there regarding this problem is basically rubbish (with all due respect).  Or at least, it didn’t solve my problem.
At that point, wondering what had changed, I realized that it might (obviously) have something to do with the fact that I had installed the Windows Azure SDK.
I found a clue here, did some pondering, and talked it over with colleagues.  So, the SDK, it turns out, installs SQL 2012 Express; one of my Hitachi colleagues suggested maybe the 2012 install had broken something.  I uninstalled everything to do with SQL 2012 Express, re-booted my machine, and lo and behold, the “remote procedure call failed” error went away and the list of services came back.
However, I was still unable to start the SQL Server agent.  It gave me a message saying it started but then stopped.  I thought, well, maybe I never WAS able to start the SQL Server agent.  But I thought, maybe I’d try to uninstall the rest of the Windows Azure stuff.  Maybe that’s still somehow blocking the agent.
Well, I tried to uninstall the Windows Azure tools, and it just gets to the end of the progress bar, then hangs. 
AzureUninstallFailes
Then when you kill the process, then try to uninstall it again, you get an error saying “please wait while anothe program finishes uninstalling” or something to that effect.  I re-booted and that went away, but then when I tried this whole thing again, it turns out that waiting did eventually let me uninstall something else.
In the end I found, it let me uninstall all the other Windows Azure stuff, but the tools, seemingly, can’t be uninstalled.  It just hangs at the end.
I’m going to contact Microsoft and point them to this blog post… I’ll try another day to get this stuff all working together!  Smile
Until next time… –Dave

UPDATE:  Microsoft says they can't reproduce this.  And that SQL 2012 didn't get installed when they installed the Azure SDK in their lab.  So maybe I installed SQL 2012 with some other download.  More as this story develops.

UPDATE:  Tried this again on 2012-10-18.  Still same exact behavior.  Downloaded the SDK; it broke the configuration manager.

Wednesday, 1 August 2012

Parsing MSTEST results (.trx files) programmatically (in C#)

 

Hello, it’s been quite awhile since I’ve posted anything; I’ve been quite busy.  I just felt like sharing this.  This is an extension of other people’s ideas, but I’ve taken it slightly further and thought it might be useful to somebody.

I came across a situation where I needed to programmatically examine a .trx file for specific strings.  The .trx file was large (31MB) because it contained the output of around 5000 unit tests.  Around 800 of those tests were failed tests, and they were failing for a specific reason (which is not important now).  The point is, I wanted to programmatically examine the error messages that were being output, and do something (which is also not important now), based on certain strings that might be found in the error message of each failed test.

Searching led me to this post in Rasheed’s blog, which was a great starting point for what I wanted to do.  As described in that post, first I had to:

Use XSD.EXE (see MSDN here) to generate classes based on the schema of VSTST.XSD. 

(XSD.EXE can be found in the Windows SDK).

(If you’re running Visual Studio 2010, then VSTST.XSD can be found in the Xml\Schemas directory on your local drive; in my case that was):

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas

So I copied VSTST.XSD to a working directory on my C:\ drive, let’s call it C:\Projects\VSTST-CLASSES.

Then I executed this command:

C:\Projects\VSTST-CLASSES>"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\xsd.exe" vstst.xsd /c

That generated a file called VSTST.CS.  In Visual Studio, in a new console application, I chose “Add Existing Item” and added that .CS file to the project to give me access to the generated classes.

Then (as described in the user comments in Rasheed’s blog ), I had to go into VSTST.CS, which now contains a load of classes that can be used to deserialize your test data, and comment out the “Items” properties of the GenericTestType and CodedWebTestElementType, to get the test results data to deserialize without error.

The end result of all this can be seen in the following C# code (which is a variation of Rasheed’s, but, I don’t care about outputting it to Excel; I’m just trying to find certain strings in the error message, probably so I can output that text to a separate output file, which will probably be a text file in any case).  Modify as desired to find the string you want in the error message of your failed test.  This code deserializes your test results and lets you loop through them and do something  based on the contents of the error message on failed unit tests.

using System.IO;

using System.Xml;

using System.Xml.Serialization;

 

namespace Utility

{

 

    class Program

    {

        static void Main(string[] args)

        {

            var fileInfo = new FileInfo(@"C:\thePathToMyGiganticTrxFile\DBarrows@R9D0YGF 2012-07-16 20_08_01.trx");

 

            var fileStreamReader = new StreamReader(fileInfo.FullName);

 

            var xmlSer = new XmlSerializer(typeof(TestRunType));

            var testRunType = (TestRunType)xmlSer.Deserialize(fileStreamReader);

 

            foreach (var itob1 in testRunType.Items)

            {

                var resultsType = itob1 as ResultsType;

                if (resultsType == null) continue;

 

                foreach (var itob2 in resultsType.Items)

                {

                    var unitTestResultType = itob2 as UnitTestResultType;

 

                    if (unitTestResultType == null) continue;

 

                    // these are not used, but they could be to identify the output:

 

                    // var id = unitTestResultType.testId;

                    // var testName = unitTestResultType.testName;

 

                    var outcome = unitTestResultType.outcome;

 

                    if (outcome != "Failed") continue;

 

                    var items = unitTestResultType.Items;

 

                    if (items == null || items.Length <= 0) continue;

 

                    // now we know we have a failed test; look for the desired string(s) in the error message

                    var outputType = (OutputType) unitTestResultType.Items[0];

                    var errorInfo = outputType.ErrorInfo;

                    var message = errorInfo.Message;

                    var text = ((XmlNode[]) message)[0].InnerText;

 

                    if (text.ToLower().Contains("some_pertinent_string"))

                    {

                        // do something special if the error message contains some particular string,

                        // e.g. parse the error message further and output as desired

                    }

                }

            }

        }

    }

}