Signing Executable error SignTimeStamp (-2147467259/0x80004005)

October 17, 2011 Leave a comment

Just a quick note on a cryptic error I came across the other day.

I was working on a remote server, trying to determine why our build system was failing trying to sign our executables.

The command being run was:

signtool.exe sign /SHA1 [thumbprint] /t http://timestamp.verisign.com/scripts/timstamp.dll /d [Executable Name] [Executable Path] 

And the error I was receiving was

SignTimeStamp (-2147467259/0x80004005)

As far as I could tell (-2147467259/0x80004005) appeared to be a very generic COM exception and was not very helpful.

The problem actual turned out to be very simple.

While I did know this, I had forgotten that the server in question had no access to the internet. This meant the call to the time server via the -t switch was failing and producing this lovely, and informative error.

The short term workaround for me was to completely remove the -t switch until this group of machines is given internet access. This allows the executable to be signed, and the build and deploy succeed, while we continue to setup this environment. This is however a temporary environment.

Be aware that by not using a time stamp when you sign your executable means the signature is only valid until the certificate expires and thus is most likely not a valid work around in a production system..

With any luck this will stop someone else wasting their time trying to track down the cause of this lovely error message.

Categories: General Tech

Strange errors in generated file DataServiceImplementation.cs in LightSwitch

September 2, 2011 3 comments

Over the past week or so I have been playing with LightSwitch and have been very impressed with what I have found.

That being said, while I know this problem was my fault for being lazy, I have come across my first batch of strange code generation errors. While simple to solve I assume I am probably not the only person to make this mistake so thought I would share my findings.

As part of learning about LightSwitch, I have been going through and following a number of tutorials on the various aspects.

Currently I am looking at using RIA services as a data source and have been following the Creating a Simple LightSwitch RIA Service (using POCO) tutorial from LightSwitch Help Website.

Rather than download the code sample, I was rewriting the code step by step. However once I added my data source to the LightSwitch application and tried to compile I received these errors in DataServiceImplementation.cs within the ServerGenerated project.

Error	1	) expected
Error	2	Invalid expression term ')'
Error	3	; expected
Error	4	; expected
Error	5	A new expression requires (), [], or {} after type
Error	6	; expected

ErrorList

Of course I thought generation errors probably mean I have done something wrong. I looked over the code I had written and it all roughly matched what was provided in the tutorial. I then downloaded the tutorial source and saw that it compiled and worked correctly.

Puzzled I took a closer look at my code and decided to clean it up as I had been lazy and just dumped everything in the same file while I was working. Upon doing so I noticed that when I created the CustomerRecord model class, I accidentaly created it as a nested class of the domain service class.

i.e.

public class DomainService
{
    public class CustomerRecord
    {           
    }
}

instead of


public class DomainService
{
}

public class CustomerRecord
{
}

After refactoring this class into its own file as I should have done in the first place, and updating the data source the solution copiled correctly.

With any luck this will help someone else that makes the same stupid mistake as me.

Categories: .NET Tags:

First Impressions of Microsoft Visual Studio LightSwitch

September 1, 2011 Leave a comment

A couple of weeks ago I attended the Tech Ed Australia 2011 Brisbane Preview breakfast session. As I am not actually attending Tech Ed this year, this was a chance for me to see some short and sweet versions of a few of the sessions being presented.

One of the sessions that took my fancey was the Introduction of Visual Studio LightSwitch by Andrew Coates (@coatsy).

As a result, over the past week or so I have been playing with LightSwitch and have been very impressed with what I have found.

For those of you who have not seen or heard of it yet, LightSwitch is a self-service development tool that enables non developers to build business applications quickly and easily. While it lends itself well to forms over data type systems, with a SilverLight client it is not limited to such applications.

In my eyes it is a replacement tool for building the equivalent of all of the old archaic MS Access and Excel “programs” out there that have been built by non developers out of necessity for something simple right then and there.

It is also very powerful for prototyping and initial requirements gathering for a bespoke system, as real working software can be shown rather than just wire frames and mock ups.

What I see as the added bonus however is that LightSwitch is also a very extensible, customisable and flexible, opening it up to mid and high level developers as well. This along with the built in 3 tier architecture and simple deployment scenarios, I see this filling a lot of holes, and increase speed of delivery in the SME (Small and medium enterprise) market.

This also means that these “necessity” applications can later be taken over by a professional development team without the usual screams of pain…

If you are getting started I would suggest you run through the Lightswitch How Do I? Videos and download the slides from @coatsy’s Tech Ed sessions.

The other resource I have found very helpful is the LightSwitch Help Website and another large list is available from Glenn Wilson’s (@Mykre) blog post here.

I am still learning this stuff myself but if you have any questions leave me a comment and I will see what I can do.

Categories: .NET, General Tech Tags: ,

Sharp Launcher for DreamCheeky USB Rocket Launcher working on Windows 7 x64

July 12, 2011 2 comments

I have been sitting on this solution for a while and have finally got around to posting about it and sharing the solution with others who might find it handy.

For those of you not really interested in my explanations of the changes I made and just want the software download links are at the bottom of the post.

DreamCheeky rocket launcher

I currently have one of these DreamCheeky USB Rocket Launchers setup on my desk at work. At the time I purchased this device, the best .NET open source project for controlling the DreamCheeky rocket launcher was a project called Sharp Launcher. http://code.google.com/p/sharplauncher/

However, once my work machine was upgraded to Windows 7 64 bit, I had not been able to enjoy the device as the latest version of Sharp Launcher (1.3), does not work under a 64 bit operating system.

After some Googling and finding no solution, only a number of people asking the same questions, I decided to jump in and fix it.

Now I want to point out that I have tried to get in contact with the original developer to supply him with the changes and have got no response. I have also looked at contributing to the code.google project but it is not actually setup as a source repository, just has a zip of the code for download.

My alternative is to post both the binaries and the source here and hopefully someone stumbles across it who knows how to contact this guy.

I take no credit for the original code just the few minor tweaks I have made to make it work in a 64 bit environment. I have also not made any attempt to clean up the code, remove any warnings, test it on more than 1 or 2 systems, or anything else as this was purely an effort to get this existing software to work under 64 bit.

After downloading the source code for version 1.3 from here and converting the solution to VS 2010, I found the straight away the code did not compile.
Error List 1

Error number 3 is the issue so I change the code from

public bool UnregisterHandle()
{
    if (this.handle != null)
    {
        return Win32Usb.UnregisterForUsbEvents(this.handle);
    }
}

to

public bool UnregisterHandle()
{
    return this.handle != null && Win32Usb.UnregisterForUsbEvents(this.handle);
}

This allows us to compile and run the software, however as expected my device is not found.
No USB Launchers Found

By debugging in I found that the call to SetupDiEnumDeviceInterfaces on line 266 of LibHid/HIDDevice.cs was returning false. Now this next bit took me a hell of a long time to work out. Looking back it should have been pretty obvious but I began my search in completely the wrong direction. Long story short, I worked out this was due the type of the Reserved property of the DeviceInterfaceData struct in LibHid/Win32Usb.cs.
This needs to be changed from int

public int Reserved;

to ulong

public ulong Reserved;

This is due to the fact that the returned SP_DEVICE_INTERFACE_DATA Structure returns the reserved property as a ULONG_PTR.
This of course works in a 32 bit environment but the 64 bit data does not fit into a standard 32 bit int.

Once this change was made I continued to debug the process and came across this gem at line 234 in LibHid/HIDDevice.cs.

oDetail.Size = 5;	// hardcoded to 5! Sorry, but this works and trying more future proof versions by setting the size to 
                           the struct sizeof failed miserably. If you manage to sort it, mail me! Thx

To rectify this we need to declare a dll import and define the IsWow64Process

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);

And then change that offending line to

 bool is64BitProcess;
 IsWow64Process(Process.GetCurrentProcess().Handle, out is64BitProcess);
 oDetail.Size = (IntPtr.Size == 8 || (IntPtr.Size == 4 && is64BitProcess)) ? 8 : 5;

I know at least 1 reader of this will say the IsWow64Process method wont exist in earlier version of kernel32 such as under Windows 2000 or XP < SP1 but for what I'm trying to achieve here I am assuming if you are on those older versions you will be using the already released version of Sharp launcher and wont need this Windows 7 x64 version. ūüėÄ

So now we can compile and run the application and this time we will see the device has been detected correctly and we now have control of our cube defense system.
USB Launcher Found

I hope this has provided some insight to a few people and also provided an opportunity to enjoy your USB rocket launcher again.

Now to hook this up to the build failure notifications… Muhahaha…


UPDATE: I have uploaded the source to GitHub

Updated source can be found here: SharpLauncher 1.3.0.1 on GitHub

Binaries can be found here: SharpLauncher 1.3.0.1 Binaries

Helpful Excel function – Remove blank values from a list

July 8, 2011 1 comment

Just a quick note, more to myself than anyone else.

Today I was asked by the BA in my team to look into a particular problem trying to be solved within an Excel workbook.

I know, I know, don’t get me started on companies using overly engineered Excel workbooks to run their business…

Moving right along.

The problem was based on a list of data, if a column value of a row was set, display the key of that row in a list.

i.e.
Table of RSVPs to a list of attendees.
Excel Problem Result

Upon first glance I though this would be very simple, and in any query language it would be.

However when I actually sat down to look at the problem, I realised I could get the list very easily, but displaying it without blank values was a problem.

i.e.
With a simple =IF(B2=”Yes”,A2,””) formula I could produce
Excel Problem First Attempt

Removing those blanks however was a little more interesting.

Due to my before mentioned “dislike” for overly engineered Excel workbooks, I told myself I would not revert to doing it in a VBA Macro, I would solve this with a formula.

Eventually I stumbled across this helpful little function at http://www.cpearson.com/excel/noblanks.aspx

=IFERROR(INDEX(BlanksRange,SMALL((IF(LEN(BlanksRange),ROW(INDIRECT("1:"&ROWS(BlanksRange))))),ROW(A1)),1),"")

While not easy to read, when copied into a range of cells the same size as the original list (including blanks), this formula will populate said range with the non blank values sequentially.

So I took my first function to create the temporary list of attendees (including blanks).
Excel Problem Temporary List

And then use the above formula to select the values from this list without the blanks.
Excel Problem All

Now this is a simple contrived example but I have tested this with 1000 rows of data with up to 30 character strings as the keys and it still is almost instant performance.

One thing to note: If you don’t actually follow the above link. This is an array function, therefore when entering or subsequently editing it you must commit your change with CTRL + Shift + Enter not just Enter.

Categories: General Tech Tags: ,

CA2000 on default MVC GetAccountController method

I came across a tricky issue the other day after creating a new MVC3 project and associated unit test project.

After turning on Code Analysis, I was presented with

CA2000 : Microsoft.Reliability : In method ‘AccountControllerTest.GetAccountController()’, object ‘<>g__initLocalb’ is not disposed along all exception paths. Call System.IDisposable.Dispose on object ‘<>g__initLocalb’ before all references to it are out of scope.

To fix this Dispose issue, change the GetAccountController method to the below.

        private static AccountController GetAccountController()
        {
            AccountController controller = null;

            try
            {
                var requestContext = new RequestContext(new MockHttpContext(), new RouteData());

                controller = new AccountController();
                controller.FormsService = new MockFormsAuthenticationService();
                controller.MembershipService = new MockMembershipService();
                controller.Url = new UrlHelper(requestContext);

                controller.ControllerContext = new ControllerContext
                {
                    Controller = controller,
                    RequestContext = requestContext
                };
            }
            finally
            {
                if (controller != null) controller.Dispose();
            }

            return controller;
        }

Note that when constructing the AccountController, I have removed the object constructor.

While this took me a while to figure out, but using an object constructor on the Disposable object, actualy brings back the original error even though we are constructing within the try finally block.

Categories: .NET

SA0001: An exception occurred while parsing the file – Caused by an optional string argument

I was presented with this StyleCop error by a member of my team the other day.

SA0001: An exception occurred while parsing the file: System.ArgumentNullException, element
Parameter name: Must not be null
   at Microsoft.StyleCop.Param.RequireNotNull(Object parameter, String parameterName, ParamErrorTextHandler errorTextHandler)
   at Microsoft.StyleCop.Param.RequireNotNull(Object parameter, String parameterName)
   at Microsoft.StyleCop.StyleCopAddIn.AddViolation(ICodeElement element, Int32 line, String ruleName, Object[] values)
   at Microsoft.StyleCop.StyleCopAddIn.AddViolation(ICodeElement element, Int32 line, Enum ruleName, Object[] values)
   at Microsoft.StyleCop.CSharp.ReadabilityRules.CheckEmptyString(Node`1 stringNode)
   at Microsoft.StyleCop.CSharp.ReadabilityRules.IterateTokenList(CsDocument document, Settings settings)
   at Microsoft.StyleCop.CSharp.ReadabilityRules.AnalyzeDocument(CodeDocument document)
   at Microsoft.StyleCop.StyleCopThread.RunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable`1 analyzers)
   at Microsoft.StyleCop.StyleCopThread.TestAndRunAnalyzers(CodeDocument document, SourceParser parser, IEnumerable`1 analyzers, Int32 passNumber)
   at Microsoft.StyleCop.StyleCopThread.ParseAndAnalyzeDocument(SourceCode sourceCode, DocumentAnalysisStatus documentStatus)
   at Microsoft.StyleCop.StyleCopThread.DoWork(Object sender, DoWorkEventArgs e).

It took some time to track down, but the below link helped point me in the right direction.

http://stylecop.codeplex.com/workitem/6755

The problem was an optional string argument in a method.

There is a bug in StyleCop which has now apparently been fixed in version 4.4.1

Looks like we have an upgrade to do…

Categories: .NET