Archive

Posts Tagged ‘c#’

Quick Tip: Iterate through an enum in .NET

April 19th, 2009 3 comments

Here’s a quicky for you. Iterating through an Enum in .NET, replace ‘IconResource‘ with the Enum you want to iterate.

C#

Array enumValues = System.Enum.GetValues(typeof(IconResource));

foreach (IconResource resource in enumValues)
{
	Console.WriteLine("Resource: {0}", resource);
}

VB.NET

Dim enumValues As Array = System.[Enum].GetValues(GetType(IconResource))

For Each resource As IconResource In enumValues
    Console.WriteLine("Resource: {0}", resource)
Next

Useful?

{lang: 'en-GB'}
Share

Give me the Greenlight: Resharper 4.5 Released!!!

April 9th, 2009 No comments

I’m ready to go right now,
I’m ready to go right now.

I see you move, I’m checking your smile
working your back like it’s going out of style
Shake just a little bit faster
shake just a little now girl
Dying to meet you, so lets mess around
I’ve got an obsession of us getting down
Come just a little bit closer
I just need permission so just…

Download Resharper 4.5, the final just got released 🙂

What the hell have I been smoking? Greenlight (feat. Andre 3000) .

{lang: 'en-GB'}
Share

FIX: ‘The Microsoft.Jet.OLEDB.4.0 provider is not registered on the local machine.’ Message for .NET Applications

April 2nd, 2009 4 comments

Came across a post on DeveloperFusion today that resonated the same issue we had at work a few days earlier involving JET (no not the band) accessing an Access database in .NET code on Windows x64.

If you find you get a nasty:

The Microsoft.Jet.OLEDB.4.0 provider is not registered on the local machine.

When you run your .NET Application – and I know this – on your x64 box, its because Microsoft does not support JET on 64bit versions of Windows outside of Windows 2003.

So, what to do? Simple, you need to make sure that the assembly is written targeting ‘x86’ rather than ‘Any CPU’ or ‘x64’ in the Configuration Manager, rebuild the assemblies and you should be good to go 🙂

{lang: 'en-GB'}
Share

Windows 7 Beta SDK and .NET Interop Samples Posted

April 2nd, 2009 No comments

The Windows Tean blog‘s Developers blog has a run down of the .NET Interop Samples for Windows 7. Make sure you install the Windows 7 Beta SDK and grab the samples.

I have yet to play with them 🙁 But the Windows 7 Builds are running awesomely on my Dell M1330.

{lang: 'en-GB'}
Share

Hot Panties: ASP.NET MVC Released!

March 19th, 2009 No comments

Microsoft ASP.NET

JIT for a deployment of UAT for a project we’re working on, Microsoft have released ASP.NET MVC framework as a final RTM only hours ago.

I’ve been working with the framework for the past couple of months and I have to admit its been a burst of fresh air from the standard webforms model.

Download a copy of the RTM and give the samples ago, its bootilicious and hopefully will bring a new cleaner way to write your ASP.NET sites in the future – not that you couldn’t do this before.

The other cool addition is the MVCContrib project which is a complimentary tidbit to help you.

See the ASP.NET MVC site for more information including the ASP.NET MVC Source and dont forget about the free eBook chapter from the upcoming book Professional ASP.NET MVC 1.0.

Ah, memories of Struts without the tears and the pain.

{lang: 'en-GB'}
Share

Deep Dive: How .NET Regular Expressions really work.

March 17th, 2009 No comments

Have you ever wondered how Regular Expressions really work? Most of us (myself included) just take the implementation for granted, but Jeff Moser of Moserware has posted a most excellent, very in-depth overview how Regular Expressions have been implemented in .NET.

A must read for anyone who would like a deeper knowledge about what really happens under the hood and Jeff has done a brilliant job of pulling it into one consistent article.

Whilst on the subject of RegEx’s, I use Expresso for my regex testing.

{lang: 'en-GB'}
Share

Microsoft Releases Singularity 2.0 Research Development Kit (RDK)

November 18th, 2008 No comments

Microsoft has just unleased the initial release of the Singularity 2.0 Research Development Kit (RDK). Singularity is a research operating system started around 2003 by Microsoft Research to write an OS in managed code. The inner-workings of Singularity taken from Wikipedia:

The lowest-level x86 interrupt dispatch code is written in assembly language and C. Once this code has done its job, it invokes the kernel, whose runtime and garbage collector are written in Sing# (an extension of C#) and runs in unsafe mode. The hardware abstraction layer is written in C++ and runs in safe mode. There is also some C code to handle debugging. The computer’s BIOS is invoked during the 16-bit real mode bootstrap stage; once in 32-bit mode, Singularity never invokes the BIOS again, but invokes device drivers written in Sing#, an extended version of Spec#, itself an extension of C#. During installation, Common Intermediate Language (CIL) opcodes are compiled into x86 opcodes using the Bartok compiler.

This new release brings some funky changes:

  • Support for AMD64 64-bit platforms
  • Updates to the Bartok MSIL-to-native compiler and the Sing# compiler
  • A new, more modern and extensible bootloader
  • Several new applications and application documentation
  • Eventing support
  • More extensive ACPI support
  • A unit testing library
  • A ramdisk device
  • An SMB client service
  • Can now check out the most recent version of the Singularity RDK directly from CodePlex source control

Its released under Microsoft’s shared source academic license which in basically means you can do what you like, just don’t make any money out of our hard work.

For convenience there’s even an ISO already baked ready to slap into a Virtual Machine 🙂

There are others that deviate from Singularity that tackle the use of a managed operating system slightly differently and I wrote about them a while ago.

{lang: 'en-GB'}
Share

Mono 2.0 Released today!

October 6th, 2008 No comments

Mono has made it to version 2.0 today and brings so much goodness to the table. Some very cool new features and functionality to Mono and promises of speed improvements – which I dont doubt having tried a few things.

From the release notes:

Microsoft Compatible APIs

  • ADO.NET 2.0 API for accessing databases.
  • ASP.NET 2.0 API for developing Web-based applications.
  • Windows.Forms 2.0 API to create desktop applications.
  • System.XML 2.0: An API to manipulate XML documents.
  • System.Core: Provides support for the Language Integrated Query (LINQ).
  • System.Xml.Linq: Provides a LINQ provider for XML.
  • System.Drawing 2.0 API: A portable graphics rendering API.

Mono APIs

  • Gtk# 2.12: A binding to the Gtk+ 2.12 and GNOME libraries for creating desktop applications on Linux, Windows and MacOS X.
  • Mono.Cecil: A library to manipulate ECMA CLI files (the native format used for executables and libraries).
  • Mono.Cairo: A binding to the Cairo Graphics library to produce 2D graphics and render them into a variety of forms (images, windows, postscript and PDF).
  • Mono’s SQLite support: a library to create and consume databases created with SQLite.
  • Mono.Posix: a library to access Linux and Unix specific functionality from your managed application. With both a low-level interface as well as higher level interfaces.

Third Party APIs bundled with Mono

  • Extensive support for databases: PostgresSQL, DB2, Oracle, Sybase, SQL server, SQLite and Firebird.
  • C5 Generics Library: we are bundling the C5 generics collection class library as part of Mono.

Compilers

These compilers are part of the Mono 2.0 release:

  • C# 3.0 compiler implementation, with full support for LINQ.
  • Visual Basic 8 compiler.
  • IL assembler and disassembler and the development toolchain required to create libraries and applications.

Tools

Mono includes profiling tools, the standard development kit tools that are part of the .NET framework

  • Debugger: this is the first release when we support a debugger for managed code.
  • Gendarme: is an extensible rule-based tool to find problems in .NET applications and libraries. Gendarme inspects programs and libraries that contain code in ECMA CIL format (Mono and .NET) and looks for common problems with the code, problems that compiler do not typically check or have not historically checked.
  • Mono Linker: a linker that allows developers to reduce the size of their executables and libraries by removing features from libraries using an XML definition of the desired public API.
  • Mono Tuner: a tool to apply arbitrary user-defined transformations to assemblies. Mono uses this library to produce the Silverlight core libraries from the main system libraries.
  • Mono Documentation Tools: the Mono Documentation framework has been upgraded to support documenting generics and extension methods. The tools can be used to produce online and offline documentation for any any APIs, and are used by the project to document our own APIs.

There are so many goodies in this release if C# 3.0 with LINQ loving doesnt entice you already and the fact that Mono now provides a complete WinForms 2.0 implementation for OS X & Linux.

Whats cooler is the WebBrowser control powered by Gecko that ships with Mono, this would be an ideal drop in replacement for the MSHTML control.

Implementations of Table Layout and Flow Layout Panels and Big Arrays.

Go ahead and download a copy and give it a whirl. My how Mono has come over the years.

{lang: 'en-GB'}
Share

The Slick New DeveloperFusion.com is ‘soft-launched’

September 29th, 2008 1 comment

DeveloperFusion.com

DeveloperFusion has just soft-launched its slick new look and feel, go take a looksy and drool. From the humble beginnings, to the golden years and the times of change we have finally come to the slick new Web 2.0 era – maybe a tad late but damn it was worth the wait!

James is now full time at DF working away at making DF the greatest community driven site around.

{lang: 'en-GB'}
Share

NAnt: Signing Satelite Assemblies Fix

September 4th, 2008 No comments

I’ve been using NAnt to build our source trees at work (via TeamCity ) and came across a somewhat annoying issue when it comes to signing satellite assemblies.

Problem Background

For several of the projects we use the CSLA framework by Rockford Lhotka, the framework doesn’t ship a redistributable binary blob. When it gets built it generates the following:

total 644K
   0 .
   0 ..
   0 /ca-ES
   0 /da
   0 /de
   0 /es
   0 /es-ES
   0 /fr
   0 /hr
   0 /it
   0 /nl
   0 /no
   0 /pt
   0 /pt-br
   0 /ro
   0 /ru
   0 /sr
   0 /sv
   0 /zh-CHS
 16K Csla.XmlSerializers.dll
156K Csla.dll
4.0K Csla.dll.config
468K Csla.pdb

Inside each of those folders we have the resources for the locale (a Csla.Resources.dll satelite assembly). The NAnt Script uses the KeyFile attribute in the CSC task passing in the CslaKey.snk file to sign the main assembly but it appears the NAnt engine (as of NAnt 0.85) does not pass this key to the Assembly Linker (AL.exe) utility to sign the satelite assembly.

Preliminary Solution

So the easiest way to get around this is to specify in the AssemblyInfo.cs file itself the key file to utilise when signing the assembly. This way the compiler will delegate the key to the child utilties it uses enforcing the key signing process.

[assembly: AssemblyCopyright("Copyright © 2007 Rockford Lhotka")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyKeyFile(@"..\CslaKey.snk")]

// Mark the assembly as CLS compliant
[assembly: System.CLSCompliant(true)]

Hopefully this will be addressed in a future release of NAnt.

{lang: 'en-GB'}
Share