Thursday, 21 August 2014

Viewing the .net Debug Log using DbgView

Every day is a learning day, and today I needed some way for my client to view the debug log for the Debug Version of an Application I created to test a piece of hardware which was acting up.

After a little searching around I came across the Microsoft Sysinternals DebugView application;

http://technet.microsoft.com/en-us/sysinternals/bb896647

Microsoft describe this DebugView as;

… an application that lets you monitor debug output on your local system, or any computer on the network that you can reach via TCP/IP. It is capable of displaying both kernel-mode and Win32 debug output, so you don't need a debugger to catch the debug output your applications or device drivers generate, nor do you need to modify your applications or drivers to use non-standard debug output APIs.

So, in order to view the Debug Log I had already created in my App was as simple as;

  1. Download the DebugView Application from http://download.sysinternals.com/files/DebugView.zip
  2. Extract the contents of the ZIP to a location on your hardrive
  3. Run the DebugView Application as an administrator
  4. Run your Application
  5. Your Debug Messages will appear in the Window;

 

image

If you find that some other applications are also emitting debug information, then you can setup a filter, so that only your application is shown;

  1. Next to the Debug Messages for you application will be a number in square brackets. This is the PID of your application. Take a note of this number.
  2. Press the Filter/Highlight button;

    image

  3. The Filter Highlight dialog will be shown;
  4. In the Include Box, remove the Star and enter your PID;

    image

  5. Press OK, and now you should only see the debug output from your application.


It’s worth noting that each time you start your application, it’s PID will change, so bear that in mind as your Filter will need adjusting to suit of course. You can either remove the filter to find your PID, or use Task Manager.

Very handy.

Friday, 13 June 2014

Freeing up Reserved / Allocated Serial ports

In my line of work, I spend a lot of time interfacing to devices using a Serial (RS232) connection. This often necessitates the use of USB to Serial port converters.

A frustrating issue I often come up against is that, each time a new one of these converters is attached, or indeed an existing to a new USB port, it allocates itself a new port.

This port is then not automatically freed again by Windows, which means that you end up with a bunch of reserved serial ports allocated to converters which are no longer attached or used. Further, you cannot ordinarily see USB devices which have been removed from the system, so manually removing the devices isn’t simple either.

To get around this, you can perform the following steps to allow you to show the removed USB devices, and uninstall them, freeing the ports, and allowing you to reallocate your device com ports;

  1. First, remove any USB to Serial Converters you may have attached, as these will have live allocated COM ports.
  2. Then. launch a Command Prompt as Administrator, by right clicking on the Command Prompt shortcut, and selecting “Run as administrator”;

    image
  3. We now need to allow the Device Manager to let us see removed USB devices. So, type; set devmgr_show_nonpresent_devices=1 and hit Enter… Don’t worry, nothing will be shown in response to this;

    image
  4. Next we need to launch the Device Manager, so type; start devmgmt.msc and hit the Enter key, which will bring up the Device Manager.
  5. Now we want to show all the Hidden USB devices, so click the View menu and select “Show hidden devices”;

    image
  6. You’ll now see that a bunch of extra nodes have been added to the Device tree. The one we’re interested in is the Ports (COM & LPT) section. So expand this node by clicking the small arrow to the left of the label;

    image
  7. You should now see a selection of devices which appear slightly greyed out. Each device will indicate it’s allocated COM port. All we need to do is remove each of these devices, freeing up its COM port. This is achieved by simply selecting the device you want to remove, and either hitting the Delete key on your keyboard or going to the Action menu and selecting Uninstall.
  8. Each time you attempt to uninstall a device you will be asked to confirm the uninstallation. There will also be a checkbox to allow you to “Delete the driver software for this device”. You can leave this un-ticked, as we know we’ll need to use this device in the future.

    image
  9. You should now be able to re-connect your USB to Serial Port Converters, watch each one get reinstalled, where WIndows will automatically assign the lowest COM port available.
  10. You can of course select your own choice of COM port for each device. This is achieved by right clicking on the device who’s COM port you wish to change and selecting Properties;

    image
  11. This will bring up the Device Properties window. From here select the Port Settings Tab, and press the Advanced Button;

    image
  12. This will show the Advanced Settings for the COM port. The COM Port Number can then be selected from the “COM Port Number” dropdown;

    image
  13. Select your COM port, And OK all the open Windows.

I hope this helps somebody else as much as it helped me!

Friday, 30 May 2014

XBMC–Some YouTube videos refuse to play

I noticed that a few YouTube videos refused to play. Having searched around, I came upon a thread in the XBMC YouTube plugin code repository;

https://code.google.com/p/youtubexbmc/issues/detail?id=95#c217

martinpe...@gmail.com  linked to an updated YouTubePlayer.py file;

YouTubePlayer.py

Copying this file to your XBMC Addons directory, over the existing file, fixes the problem nicely.

Evidently, some YoutTube videos have a ‘$’ in the JS function name, which confuses the original plugin. This plugin replaces the ‘$’ in the function names with ‘_S_’

Hope this helps somebody!

Thursday, 29 May 2014

Visual Studio 2013 Update 2 – Navigation Bar Dropdowns not working

Seems as though the VS team introduced a bug in Update 2 for Visual Studio 2013, where the Navigation Bar Dropdowns don’t work if you are using VS on a screen which is to the left of your “Main Screen”;

image

When you have VS running on your second (or third) monitor, clicking on the Navigation Drop Downs has no effect;

image

In order to workaround the problem, you either need to set the screen you have VS running in as your main screen, using your graphics properties, or alternatively move VS to your main screen……

Frustrating…

Hopefully this will be cured in a future update..

Friday, 23 May 2014

Wordpress Contact-Form-7 Not Sending–”Spinning Arrows”

I recently had an issue with a new Wordpress install, where the Contact Form wasn’t sending correctly, instead hitting the Submit button would simply show the Spinning arrows animation, with no Mail Sent.

I was also using the Really Simple CAPTCHA plugin, which may have had a bearing on the issue too.

After doing some digging around I found a couple of forum posts which helped;

http://venugopalphp.wordpress.com/2014/01/08/contact-form-7-really-simple-captcha-permission/
http://wordpress.stackexchange.com/questions/13367/how-to-resolve-failed-to-send-your-message-problem-for-contact-form-7

Combining these two gave me a solution which worked;

  1. Set the Permissions of the “wp-content/uploads” directory to 777
  2. Open the “p-content/plugin/really-simple-captcha/really-simple-captcha.php”

    Change;

    /* Image type. 'png', 'gif' or 'jpeg' */
            $this->img_type = 'png';
     
            /* Mode of temporary image files */
            $this->file_mode = 0444;
     
            /* Mode of temporary answer text files */
            $this->answer_file_mode = 0440;

    To;



    /* Image type. 'png', 'gif' or 'jpeg' */
            $this->img_type = 'png';
     
            /* Mode of temporary image files */
            $this->file_mode = 0777;
     
            /* Mode of temporary answer text files */
            $this->answer_file_mode = 0770;

  3. Install the “WP-Mail-SMTP” plugin and configure it to use your website’s email address smtp settings etc
  4. Modify your Contact-Form-7 Contact Form settings;

    From:
    image

    To:
    image

    Where you should replace “info@yourdomain.com” with the email address you have configured in the “WP-Mail-SMTP” plugin.


Adding the Additional Headers, allows you to still reply to the original sender.

Thursday, 22 May 2014

Skype Login Screen not Rendering Properly

Recently I had an issue where my Skype login screen wasn’t rendering properly, showing something like;

33.jpg

After doing some searching around I found the following Skype forum which had a solution;

http://community.skype.com/t5/Windows-desktop-client/Skype-6-10-0-104-BIG-Login-screen-problem/td-p/2064269/page/6

Turns out that this is caused by a registry key setting css to text/plain rather than text/css.

Simply setting “HKEY_LOCAL_Machine > Software > Classes > .css > Content Type” to “text/css” cured the problem.

Thursday, 27 February 2014

WPF PasswordBox control click crashes Application if Fonts aren’t available

I recently had an issue where a kiosk application I was developing would crash on a Windows Embedded 7 system, if the user clicked on a PasswordBox control. Annoyingly, I couldn’t replicate this in my test environment.

The Application would crash, and frustratingly, not actually hit any of my Error Handlers. However, the Windows Application Event Log shined a little more on the issue, returning the following;

Application: FrontEnd.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Unrecoverable system error.
Stack:
   at System.Environment.FailFast(System.String)
   at MS.Internal.Invariant.FailFast(System.String, System.String)
   at MS.Internal.Invariant.Assert(Boolean)
   at System.Windows.Media.FontFamily.get_FirstFontFamily()
   at System.Windows.Media.FontFamily.get_LineSpacing()………

After doing some digging around, I found that I wasn’t the only person that this had happened to;

http://stackoverflow.com/questions/8821648/why-does-a-passwordbox-control-crash-my-wpf-application

and…

http://social.msdn.microsoft.com/Forums/vstudio/ar-SA/fc2c9a54-8f66-4f1a-82be-cb40ada5fba5/systemwindowsmediafontfamily-crash-net-35-sp1-systemexecutionengineexception?forum=wpf

Where the final post by Brendave suggested installing the following fonts on the machine;

  • Arial (TrueType)
  • Courier New (TrueType)
  • Times New Roman (TrueType)
  • Marlette

I couldn’t actually find Marlette on my system, so didn’t copy this one, and I also assumed that if it was working ok on my system anyway, then chances were this Font being missing wasn’t the issue.

After installing these fonts, magically the issue was solved.

’

Tuesday, 21 January 2014

Chrome v32.0.1700.76 - Dropdown Scrollbars not functioning – January 2014

I’ve noticed that, since the recent silent Chrome update to v32.0.1700.76, the Dropdown Scrollbars have stopped working. Turns out this is a widespread problem, but downloading the latest Chrome Beta V33 solves this issue.

This can be found here;

http://www.google.co.uk/intl/en/chrome/browser/beta.html

Thursday, 21 November 2013

Cannot browse for Files in SSMS 2008 R2–Cannot access the specified path or file on the server

Recently, while dealing with a client, I can across an issue where I couldn’t restore a database.

Whenever I pressed the “Add” button, I was shown a warning box, similair to;

image

After which, pressing Ok, would leave me with an empty Browse Dialog.

image

It seems as though, if your user does not have the "sysadmin" role, then they will not have sufficient access to the filesystem on the machine in order to open the file browser.

Setting aside the security concerns for one moment....

In order to grant this role;

  1. Log in to SSMS using Windows Authentication
  2. Navigate to Security->Logins
  3. Either double Click, or Right Click and select Properties on the user you're interested in .
  4. In the "Select a page" box, select "Server Roles"
  5. Make sure that the "sysadmin" role is selected
  6. Press Ok to save the change and close the dialog
  7. Exit SSMS
  8. Reopen SSMS and login as the User you wanted, and you should now have sufficient Privileges to browse.

Wednesday, 9 October 2013

Redirecting .co.uk to .com with ASP.net MVC IIS7 URL ReWrite 2.0

I recently started work on a new website, where I’ve purchased the .co.uk and .info domain names. However, I wanted to redirect people automatically to the main .com domain.
As my host supports the IIS7 URL ReWrite 2.0 moduke, adding the following section to the primary web.config file solved this for me;
   1: <rewrite>

   2:       <rules>

   3:         <rule name="RedirectToWWW1" stopProcessing="true">

   4:           <match url=".*" ignoreCase="true" />

   5:           <conditions logicalGrouping="MatchAny">

   6:             <add input="{HTTP_HOST}" pattern="^mydomain.co.uk$" />

   7:             <add input="{HTTP_HOST}" pattern="^mydomain.info$" />

   8:             <add input="{HTTP_HOST}" pattern="^www.mydomain.co.uk$" />

   9:             <add input="{HTTP_HOST}" pattern="^www.mydomain.info$" />

  10:           </conditions>

  11:           <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />

  12:         </rule>

  13:       </rules>

  14:     </rewrite>

Tuesday, 1 October 2013

svchost.exe consumes 100% CPU on Windows XP, caused by Windows Updates

I reinstalled Windows XP on a clients PC recently, and came up against an issue where I couldn’t update Windows using Windows Update. I then noticed that the PC had slowed down to a crawl. Opening up Task Manager, Processes and Sorting by CPU, I found that svchost.exe was consuming 100% CPU.

I tried killing the process, and retrying the updates, but svchost.exe was back to 100% as soon as I did.

Having searched around multiple forums for a long time, I finally found a solution which sorted the problem;

Firstly, download Internet Explorer 8 for Windows XP - http://www.microsoft.com/en-gb/download/internet-explorer-8-details.aspx

Once that has downloaded, install the hotfix KB2870699 for IE8 - http://www.microsoft.com/en-us/download/details.aspx?id=40119

Hey presto, problem solved. You can now use Windows update and install the 300+ updates that are required!

Saturday, 27 July 2013

Entity Framework Code First Seeding with Related Data

A quick tip I stumbled upon while working on an MVC application using Entity Framework Code First.

In order to Seed Related Data when using Entity Framework Code First, it’s important to give items temporary ID’s before calling the seed method. Otherwise, when the database is seeded you will end up with Conflicted Inserts

Wednesday, 26 June 2013

Knockout (or any javascript) Intellisense not working if move script file locations

I found while playing around with Knockout.js, that my Visual Studio Intellisense wasn’t working. This turned out to be because I had formatted my Scripts folder, and moved standard Javascript libraries into another folder.

This meant that Visual Studio couldn’t find my _references.js file.

At first I added the following to the @Scripts Section in my .vbhtml file;

   1: @Code 
   2:  
   3:        If (False) Then
   4:  
   5:            @<script src="/Scripts/lib/knockout-2.2.1.debug.js" type="text/javascript"></script>
   6:                
   7:        End If
   8:              
   9: End Code
Where the If (False) code forces the compiler to ignore the file when publishing.


But this would end up being silly if I had lots of files. So, I had a quick look around and found a couple of useful answers on Stack Overflow;


http://stackoverflow.com/a/12016530/1305169 and
http://stackoverflow.com/a/12628049/1305169


Where, basically, you need to add a reference to your new _references.js file to the Intellisense list options in Visual Studio;



  • In Visual Studio, go to Tools > Options > Text Editor > Javascript > Intellisense > References
  • In the “Add a reference to current group”, type in the relative path to your _references.js file (for me this was “~/Scripts/lib/_references.js”

Hey presto, you should now have working intellisense!

Wednesday, 19 June 2013

Slow WPF DataGrid when Grouping Styles Added

I found while working a project recently, that when I added the styling for Grouping, even if I wasn’t actually using it, that the load time for my data was massively affected.

Evidently, the reason or this slow down is due to the fact that, unbeknown to me, when grouping is enabled in WPF, then Virtualisation is disabled by default.

Virtualisation allows WPF to not physically render items which don’t appear directly in the UI, thus it doesn’t need to perform all the complicated UI math related to showing UI elements. This vastly improves performance, in my case, when dealing with Data Sources which have rows exceeding a few hundred.

Thankfully, WPF and .Net 4.5 has enabled a way for Virtualisation to be re-enabled when grouping. Simply adding the following to the Datagrid re-enabled Virtualisation.

   1: VirtualizingStackPanel.IsVirtualizing="True”

Friday, 7 June 2013

Installing IE10 offline

Today I came up against a problem where an application I was working on required IE10 to be installed. This all well and good, however this pc didn’t have access to an internet connection.

As such, I needed to download the IE10 install package, and copy it across to the machine.

However, when I came to install IE10, it simply told me that it needed to download “An Update” before it could be installed.

After a little searching around I found the following forum which lists the updates IE10 requires prior to being installed;

http://www.askvg.com/direct-download-link-full-standalone-offline-installers-of-microsoft-internet-explorer-10-ie10/

Basically, you need to download the following files, some of which require you to validate your copy of windows;

  1. KB2729094 - http://www.microsoft.com/en-gb/download/details.aspx?id=30521 (Requires Validation)
  2. KB2731771 - http://www.microsoft.com/en-gb/download/details.aspx?id=34863 (Requires Validation)
  3. KB2533623 - http://www.microsoft.com/en-gb/download/details.aspx?id=26767 (Requires Validation)
  4. KB2670838 - http://www.microsoft.com/en-us/download/details.aspx?id=36805
  5. KB2786081 - http://www.microsoft.com/en-gb/download/details.aspx?id=36326 (Requires Validation)

Download and install all of the above, there’s no need to restart between each update, but you must restart afterwards.

Once you’ve completed that, download the IE10 install package from;

http://www.microsoft.com/en-us/download/internet-explorer-10-details.aspx

Your install should then work smoothly!

Note: there are two different versions for x86 and x64 platforms.

SGEN: Mixed mode assembly is built against version 'v2.0.50727'…

I found while building an VB application in Visual Studio 2012, in release mode for the first time, that I was confronted with cryptic build error;
SGEN: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
After trawling through some Google results, I found the following post by Microsoft;

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

And also a couple of forums;

http://stackoverflow.com/questions/3749368/team-build-sgen-mixed-mode-assembly
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

Which suggests adding (or creating if it it doesn’t exist already) the following XML to the sgen.exe.config file;
<?xml version ="1.0"?>

<configuration>

    <startup useLegacyV2RuntimeActivationPolicy="true">

                <supportedRuntime version="v4.0" />

    </startup>   

</configuration>
For .Net 4.0 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools  (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools (for x64 systems)
For .Net 4.5 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x64 systems)
Edit - 03-06-14:

For .Net 4.5.1 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x64 systems)
Once I’d added the xml, the application built just fine.

The other alternative was to disable the option to Generate Serialization Assemblies in the offending project;

  • Project Settings for the offending Project
  • Compile Tab
  • Advance Compile Options Button
  • Set “Generate Serialization Assemblies” from “Auto” to “Off”

However, I recommend that you go with the XML option as suggested by Microsoft.

Thursday, 6 June 2013

WPF Binding Integer Validation with Null Values

I found a small hole in an application I am developing where a null value in a textbox bound to an integer value wouldn’t get validated.

It was slightly more complicated than that however. The xaml was as follows;

<TextBox Text="{Binding MyTextBoxText, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay}"/>

Where my Validation was set for when the control lost focus.

When I added a new record, the value of the binding was set to null, this enforced by validation correctly. Same when I edited the text and left the control. However, if I edited the control when it had a value, say changing the value from a 2 to nothing, then the validation wouldn’t occur.

This was because the binding didn’t have a value for a null entry. Adding a TargetNullValue parameter to the binding and thus changing the binding to the following fixed the issue nicely;



<TextBox Text="{Binding TaskOrder, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, TargetNullValue=''}"/>

More information on the TargetNullValue Property can be found here;

http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue.aspx

Tuesday, 4 June 2013

Adding EF POCO Classes to TFS Source Control

I have various projects which included Entity Framework POCO (Plain Old CLR Object) Classes. By default, these are not automatically included in TFS Source Control.

To add these classes in VS2012;

  1. Open the Team Explorer Window using View>Team Explorer
  2. You will see a list of shortcuts... My Work, Pending Changes and so on;
  3. Under "Pending Changes" is a link to "Source Control Explorer"
  4. Click this link, to open the Source Control Explorer Window
  5. Navigate through your solution to the Project containing your edmx file
  6. Above the "Source Location" will be a toolbar
  7. The fourth icon from the left is "Add Items To Folder"
  8. Clicking this icon will bring up the "Add to Source Control" Dialog, showing all the files in this project which aren't currently under Source Control.
  9. Select all the files you wish to now include under Source Control
  10. Press Next, then Finish

Now Check In your Solution again, and your POCO's should now be included.

Visual Studio – Solutions not configured for Integrated Source Control

I recently ran into an issue where, when I opened up one of my Solutions which were under TFS Source Control, I was presented with a message box which showed;

The solution you have opened is under source control but not currently configured for integrated source control in Visual Studio. Would you like to bind this solution to source control now?

Turns out that this is Visual Studio’s way of telling me that parts or all of my solution isn’t bound correctly to the source control provider.

To rectify this issue I needed to;

  1. Open the Project directly using Visual Studio, rather than with the Source Control Explorer
  2. Goto File ->Source Control –>Advanced –> Change Source Control

This will open up the “Change Source Control” dialog, which shows which items in your solution are bound and which aren’t.

From here you simply need to select which Items need to rebound and hit the “Bind” button.

Visual Studio will then checkout the unbound items, and you then need to check them back in, and your done.

Tuesday, 21 May 2013

XBMCbuntu Frodo 12.2 no Sound over SPDIF after upgrade

I recently upgraded to XBMC Frodo 12.2 and lost my sound over SPDIF. The option for SPDIF wasn’t available in the options.

After some searching around, I found the following forum post;

http://forum.xbmc.org/showthread.php?tid=161251

Which suggested;

1. Set speaker config to 2.0 or 2.1 in XBMC.
2. Set speaker config to 2.0 in osx audio-midi-setup
3. Activate AC3 and DTS options in XBMC
4. Disable LPCM otption in XBMC

Done