Posts Tagged ‘.NET Framework’

More details on installing .NET 3.5 in Windows 2000

Wednesday, April 22nd, 2009

I’ve had a comment that my previous post explaining how to install .NET 3.5 in Windows 2000 wasn’t very clear, so I’ll try to clarify it a little…

First of all, let me explain how it works.  .NET is actualy 2 separate things.  There is the .NET runtime, which deals with interpreting the MSIL intermediate code and executing it.  There is also the .NET Framework, which are all the libraries containing the classes that you usually code with in .NET.

In theory, the .NET runtime can be used without the .NET framework (although you’d probably need a couple of DLLs to define things like the basic types).  You could use an entirely different framework which sits on top of the same runtime and is compiled to MSIL.  I’m not aware of any that exist though.

The really interesting bit is that there are actually only 3 versions of the .NET runtime – 1.0, 1.1 and 2.0.  1.0 and 1.1 are used for the corresponding framework versions, but 2.0 is used for running framework 2.0, 3.0 and 3.5.  

In fact, in terms of the framework, 3.0 is 2.0 plus some extra stuff, and 3.5 is 3.0 plus extra stuff.  The trick which I rely on is that you can install 2.0 in Windows 2000 and just add the extra stuff that you need. 

For my purposes, all I needed was support for Linq and Linq to SQL and a few other bits and bobs.  All this is available in .NET Assembly DLL files.  you just need to make sure that the assemblies are available to be loaded by the application you are running.  

You also need to make sure that you have any prerequisites for those assemblies, because a lot of them will access classes in other assemblies.  There are 2 ways of dealing with that.  You can either copy in the entire set of DLLs, or you can keep running your program and looking to see what assembly it can’t find when it throws an exception, copying that DLL in and re-running it until you don’t get any more exceptions.

There are 2 ways of making the assemblies available to your program.  You can either register them in the GAC so that they can be accessed from anywhere (I’ve not tried this and I probably wouldn’t recommend it – if you want to know how to do this, google installing an assembly in the GAC), or you can just copy them into the application folder that your EXE sits in (or bin folder on your ASP.NET website will probably work too).  This does make for a lot of files in that folder, but it works!

You should be able to find the .NET 3.5 assemblies in a folder on a PC that has .NET 3.5 installed under

Program Files\Reference Assemblies\Microsoft\Framework\v3.5 

nb. Make sure that you have Windows 2000 SP4 and .NET framework 2.0 SP1 installed on the Windows 2000 PC!  You might also need to install KB 835732 before .NET 2.0 SP1.

Debugging .NET Framework Source Code

Thursday, May 1st, 2008

I’ve just set up this from Shawn Burke’s blog, and it seems to work.  Should make life easier when I hit something that I can’t work out why it is failing in the .NET framework!

Microsoft .NET Framework 3.5 in Windows 2000 Test 1

Wednesday, March 26th, 2008

I mentioned earlier how to install .NET framework 3.5  in Windows 2000.  I have been testing this on 7 Windows 2000 PCs, and I have successfully managed to get them to do a simple Linq to SQL query with the method that I mentioned.  I can’t speak for WPF or anything, but I am currently only interested in Linq.  I will post more in future when I have the live system in place.

On Reflection Part 2: GetType

Monday, March 24th, 2008
This entry is part of a series, On Reflection»

In order to use reflection in .NET, you need to get an object of class Type.  I will explain how to use the Type object later, but first, you need to be able to get it.

There are 3 ways to get a Type in .NET.

  1. VB.NET has a GetType keyword which takes a class as a parameter.  eg. you can writeDim T as Type = GetType(String)

    This is not really a function, because you are passing in a class, not an actual value, and not even the name of a class!  C# has a similar keyword, which I think is called typeof.

  2. All .NET objects inherit from Object.  Object has a function defined on it called GetType, so all you need to do is eg.Dim p as New Person()
    Dim T as Type = p.GetType()

    Note that if you have an Interface reference you may need to cast it using the CType operator in order to access the GetType function.  You should be able to cast any .NET object to Object.

  3. You can get a Type by name from an Assembly.  I will post details on this in a later post on Assemblies.

Checking if a Debugger is Running in .NET

Monday, March 17th, 2008

System.Diagnostics.Debugger.IsAttached will return True if a debugger is running.  Note that this is completely different to compiling in Debug mode, and you can’t use this function to test for that.  Conditional compilation is more suited (coming soon).

The Enum Class

Sunday, March 16th, 2008

A lot of people don’t realise that there is actually an Enum class in .NET that you can use to perform a few nice tricks. In order to access the shared methods in it in VB.NET, you need to enclose it in square brackets. The following functions I find particularly useful: -

  • [Enum].GetName
  • [Enum].GetNames
  • [Enum].GetValues

These are all useful ways that you can access the values and corresponding strings that are in Enums. In case you aren’t familiar with it, you’ll usually need to use GetType to pass in the type of the enum eg. [Enum].GetName(GetType(System.DayOfWeek),1) will return “Monday”.

Multiple Visual Studio Versions on a Single PC

Sunday, March 16th, 2008

Sometimes it is useful to be able to have multiple Visual Studio installations on a single PC.  I’ve heard some worries about whether this will cause any problems.  Personally, I have had Visual Studio 6, Visual Studio .NET and Visual Studio 2003 on one PC.  I have also had Visual Studio 6, Visual Studio 2003 and Visual Studio 2005 on another, and Visual Studio 2005 and Visual Studio 2008 on a third.  None of these seemed to cause any apparent problems.

From the point of view of the frameworks, there is very little chance of causing problems…

From 1.0 to 1.1 there were some minor behaviour changes.
From 1.1-2.0-3.0-3.5  I’ve never noticed anything that breaks old code.

Each version includes previous versions.  There are also service packs for 1.1, 2.0 and 3.0 (all SP1s at time of writing). These are included in the 3.5 installer.  2.0 SP1 does include some new classes which are required for some 3.5 features and new compiler features for the 2008 compilers (such as some Linq stuff) to work, but I am pretty certain it won’t break anything.

The .NET Stack Part 1: How The Stack Works

Thursday, March 13th, 2008
This entry is part of a series, The .NET Stack»

A stack frame is the way that .NET keeps track of what sub/function/method/whatever you want to call it you are in, which one called that, which one called that one etc. all the way up to the main function that runs the whole program. It also keeps track of where it is up to within each function.

For example, if you have the following code (in VB.NET as usual): -

1  Module Module1
2
3      Sub Sub3()
4
5     End Sub
6
7     Sub Sub2()
8         Sub3()
9     End Sub
10
11     Sub Sub1()
12         Sub2()
13     End Sub
14
15     Sub Main()
16         Sub1()
17     End Sub
18
19 End Module

If we were to stop at Line 4, the stack frame would look something like this…

Sub3:4
Sub2:8
Sub1:12
Main:16

Of course it is a bit more complicated than this, but that is the gist of it. The same idea applies for most other languages.

Entries in this series:
  1. The .NET Stack Part 1: How The Stack Works
  2. The .NET Stack Part 2: The StackTrace Class
Powered by Hackadelic Sliding Notes 1.6.5

Microsoft .NET Framework 3.5 in Windows 2000

Wednesday, March 12th, 2008

Microsoft don’t support using .NET 3.5 in Windows 2000, which is particularly annoying, especially if, like me, you have a client who has 8 out of 12 PCs still using Windows 2000.

So, I decided to have a go and see if I could find any way of doing it. This is completely unsupported, and if it breaks anything, don’t blame me, but it is actually fairly straightforward and it seems to work fine to me (although I doubt it works with things like WPF, but if anyone tries it, please leave a comment to say how it goes)…

  1. Make sure you have Windows 2000 SP4 installed
  2. You may need to install KB 835732 before step 3
  3. Install .NET Framework 2.0 Service Pack 1

Now, there are 2 ways of continuing. Either you can copy over all the .NET 3.5 assemblies (you’ll have them on a .NET 3.5 PC in the Program Files\Reference Assemblies\Microsoft\Framework\v3.5 folder). You can either dump them in the application folder or probably register them in the GAC (not tried it, but it should work).

Alternatively, try running your application. You will probably get a load of AssemblyReferenceFailedExceptions. Copy in the required DLL from the above folder into your application folder for each one.

It should all work now!