.net

Host the CLR in C++

Calvin Hsia’s blog post provides a pretty neat example of hosting the CLR in C++, which then calls a VB.NET object that emits a new type into the runtime, then invokes its Main method — which includes dynamically generated code passed in as a parameter from C++.
Obviously, this is not the recommended method to show a message box. :-)

But it does give an interesting example of different ways to interop between managed and unmanaged code.

Thanks for the cool example Calvin!

c#
.net

Comments (0)

Permalink

MSDN Wiki!

I don’t know how long this has been available, but MSDN has a wiki!

I read about it first in Shawn Steele’s Blog. What is very cool is there are a number of Microsoft developers that are adding comments.

Here are some helpful entries I’ve found:

  • David M. Kean’s post: breaking changes to System.Uri.
  • Adam Nathan’s post: details of the Type Library Exporter.
  • Craig Skibo’s post: Visual Studio Automation object oversight.
  • Ken Cox’s post: details on encrypting connection strings in your web.config file.

There was a very minor positioning issue when using FireFox, the header for each content submission was aligned incorrectly.

Overall a very good resource that I’m going to be checking out more often.

visual studio
c#
.net

Comments (0)

Permalink

The NotImplementedException

The NotImplementedException is a very simple, but useful class. It’s intent is to indicate, obviously, that a method is not implemented yet. This is very simple to search for while editing code and also something you can’t miss at runtime.

Okay, let’s give it a try. Open up any C# project, move inside any method, and type a call to a method that you are sure does not exist. For example:

TestNotImplementedException();

Select the above text, right click and choose “Generate Method Stub”. If you were surprised as I was that instead of generating:

throw new NotImplementedException();

Visual Studio generated:

throw new Exception("The method or operation is not implemented.");

Read Anson Horton’s blog post that describes why the decision was made, and how by editing a snippet file you can change the default behavior.

c#
.net

Comments (0)

Permalink

A tool all .NET developers should have - Reflector for .NET

Lutz Roeder’s Reflector for .NET is a tool that I think every .NET developer should have in their toolbox.

It’s a great class browser. It has an analyzer feature to show you what each type depends upon, and what other types it’s used by.

It also contains a dissasembler, which is very helpful when you are trying to debug tough problems.

Reflector also support an Add-In model. There are a bunch of Add-In’s available - everything from code metrics, to code coverage to dependency graphs.

tools
.net

Comments (0)

Permalink

WeakReferences

A WeakReference allows you to hold a reference to an object while allowing the garbage collector to reclaim it.

What ??

Sounds strange at first, but it can be very useful. For example, you could have a rather large object created to present data to a user. You might keep a WeakReference around after you set the “strong reference” to the object to null when the user cancel’s out of the screen.

If the user were to open that screen up again, you could check the Target property of the WeakReference to see if the large object has been garbage collected yet. If the Target property is not null, you can create a new “strong reference” by setting a normal reference type variable to the WeakReference.Target property.

Since there is now a “strong reference” to the object, it will not be reclaimed by the garbage collector.

Here’s a great WeakReference blog post by Brad Abrams, which includes comments from a developer on the Microsoft CLR team.

This article Using Weak References provides details on the difference between a long and short weak reference.

c#
.net

Comments (1)

Permalink

ReaderWriterLock Synchronization Class

The ReaderWriterLock class is a great alternative to other sychronization methods when you have situations where you have infrequent short duration writes, and a high frequency of reads.

This class is designed to allow concurrent access for multiple readers threads, or write access for a single thread.

The msdn help article provides a good example to demonstrate how it can be used.

c#
.net

Comments (0)

Permalink