Using NuGet with Ninject MVC3
May 2011
If you have not used NuGet yet I strongly recommend you have a look. It’s a Visual Studio extension that simply takes the hassle out of having to download, install, reference etc. libraries and third party tools. It will automatically update everything for you in your project. Have a look here http://www.nuget.org.
Now I’m a fan [...]
Error finding ‘log4net’ library
Feb 2011
When using log4net in a .NET 4 project, when you compile the project you can get an error saying that it cannot find ‘log4net’ or ILog.
The solution seems to be that the framework for the project is set to ‘.NET Framework 4 Client Profile’, while what it needs is ‘.NET Framework 4′. You can change [...]
Multiple startup projects in Visual Studio 2010
Feb 2011
If you want to debug more than one of the projects in your solution in Visual Studio 2010, you can set multiple startup projects. Obviously this does not apply to projects such as class libraries, which will be loaded as per your single startup project, but if you have if you have multiple independent projects, [...]
Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format.
Feb 2011
When running a web application on Windows 64-bit you may receive the following the error message:
'Could not load file or assembly xxxxxx or one of its dependencies. An attempt was made to load a program with an incorrect format.'
The reason for this is the Appliction Pool in IIS is not allowing 32-bit application to run.
You can [...]
Formatting text directly in XAML
Aug 2010
You can format text strings directly in the XAML code of a WPF application.
For example, you can use standard .NET formatting such as currency and date:
<TextBlock Text="{Binding Amount, StringFormat={}{0:C}}"/>
<TextBlock Text="{Binding Date, StringFormat={}{0:dd/MM/yyyy}}"/>
The empty {} after the StringFormat= escapes the text before the formatting string.
You can add text in front of the formatting string too, e.g.
StringFormat=Amount: [...]
Unit testing internal methods
Aug 2010
When unit testing applications you write tests for the exposed public methods. Philosophically this is correct as you need to test the functionality exposed by your class to the consuming application, and any private or internal functions that use functionality that also needs testing should be discrete from this class. This functionality should be [...]
Android numeric input
Jul 2010
To restrict the input for an EditText to a numeric value, you can add the following to the layout file:
<EditText
...
android:singleLine="true"
android:inputType="numberDecimal"
...
>
Then use, for example, Double.parseDouble(…) to retrieve the value in code.
Incidentally, the documentation recommends avoiding floats and using double instead.
main.out.xml: Error parsing XML: no element found
Apr 2010
When you build and run your Android application in Eclipse you can get the following error message:
...res\layout\main.out.xml:1: error: Error parsing XML: no element found
This occurs when you try and run the application from the main.xml layout file. The application cannot run from here and needs to be run from the java file.
The answer is to [...]
Error registering WCF host in Windows Vista (HTTP could not register URL http://+:80)
Mar 2010
This is an error encountered by one of my team when trying to run up a WCF host on a Windows Vista machine. The actual exception is an
AddressAccessDeniedException
with the error message
HTTP could not register URL http://+:80/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details)
The Microsoft site (http://go.microsoft.com/fwlink/?LinkId=70353) does have [...]
C# Image from a byte array (and back again)
Mar 2010
Quick code sample for transforming a .NET System.Drawing.Image into a byte array:
public byte[] imageToByteArray(Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
and conversely, turning a byte array into an image:
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}