Skip to main content

Posts

Showing posts from 2007

MMC Snapin creation

MMC Snapin Creation There are 2 main versions of MMC available on Windows, MMC 2.0 (Windows 2000 and XP) and MMC 3.0 (Windows Server 2003). I'll mainly explain how to develop a Snap-in with MMC 3.0. You can upgrade MMC 2.0 to MMC 3.0 using this install supplied by Microsoft MMC 2.0 snapin: Download the Platform SDK, Windows® Server 2003 R2 Platform SDK Web Install, from http://www.microsoft.com/downloads/details.aspx?FamilyID=0baf2b35-c656-4969-ace8-e4c0c0716adb&DisplayLang=en Build an example from the Platform SDK install: C:\Program Files\Microsoft Platform SDK\Samples\SysMgmt\MMC\mmc2.0\simple>nmake MMC 3.0 snapin: How to Develop and MMC 3.0 Snap-in (msdn) How to create a Snap-in using MMC 3.0 (msdn) MMC Snap-ins for MMC 3.0 can be developed with the Windows SDK , for information on the snapin classes see msdn Management Console There is also an opensource .NET library at http://sourceforge.net/projects/mmclibrary The MMC 3.0 application installation is at http://www.m...

Handling SoapExceptions

SoapExceptions are thrown from WebServices when a problem occurs. The SoapException will occur whenever any type of Exception occurs in the WebServices code e.g. if an IOException occurs it will bubble up to the caller as a SoapException, unlike other Exceptions the origninal Exception is not easily extracted, for instance by using the InnerException property. Because of this you must handle the SoapException in the sender and the caller. Yuo must stuf your Originals details into a new instance of a SoapException and then throw it. The original Exception's details are contained in the Details property of the SoapException but you still have to do some work to extract it. Also remember that WebServices return XML, the SoapException is also returned as XML, so our extraction code will need to know how to identify the inner exception and how to extract it from the correct XML Element. One thing you may wish to do with the SoapException is extract the original Exceptions details. Here...

DynamicMethod, IL Code, CreateDelegate

In a previous post, dotNET - Under the Hood, IL Assembly , I briefly described how to write some IL Code to an Assembly, but what if at a later occasion you'll want to invoke these methods from the dll. This could be achieved by loading the assembly in an AppDomain and then invoking the methods within ???? Or you could use what are known as DynamicMethod s to invoke the methods. DynamicMethod is a class that also resides in the System.Reflection.Emit namespace. Why would you want to use DynamicMethod? it's useful when you want to load methods into memory or write methods in memory and invoke later. We can write IL code in memory in the exact same was as we wrote IL code earlier using the MethodBuilder. In my experience DynamicMethod is a bit tricky to get right especially when you try to invoke your Dynamic method. The problem I found was with the constructor parameters, what do they mean; There are 6 constructor overloads in all; half of these are associated with an class in...

Enumerator(s)

You've all used the foreach loop in .NET to get the values in a container. The foreach actually uses that objects Enumerator. In order to allow the use of the foreach on an object the class must implement the IEnumerable.GetEnumerator method which also means you have to implement the IEnumerable interface. Within the GetEnumerator override you need to return an instance of IEnumerator, so you need to create a class that implements the IEnumerator interface. see the code. This is useful if you class contains a member variable which is an or even a container. Let's say it's an array. When an instance of your class is create the array is also instantiated. But you don't want the array to be visible but you do want clients to be able to use a foreach on your class instance, this can be achieved by implementing the IEnumerable interface and overriding the GetEnumerator method. using System; using System.Collections.Generic; using System.Text; using System.Collections; namesp...

Security in Assemblies

Code Security is all about allowing and preventing code from running. The . NET Security Model works by the assemblies each having their own Evidence embedded in the Assembly by the Assembly writer. When the CLR loads the assembly it then reads and applies this Evidence to a Security model and this in turn returns Permissions , depending on what Permissions are returned will determine is the assembly is permitted to execute or not. So it's Evidence in (on the assembly) -> Code Groups -> Permissions. Code Access Security (CAS) is the the mechanism used by .NET to manage all of this. It's function is to process assemblies and determine the runtime permissions they should have, e.g. should they code within a certain assembly be allowed to run or not. All assemblies have Evidence. As the CLR is loading the assembly it looks at this Evidence and processes it using the current machines .NET Code Group. Depending on where the assembly is being loaded from, the Evidence it has,...

dotNET - Under the Hood, IL Assembly, MSIL, ILGenerator, MethodBuilder

IL (Intermediate Language) is also referred to as MSIL (Microsoft Intermediate Language) or even ILAsm which is the same thing. IL is the code which your source code (C#, VB.NET etc) is compiled into. When you EXE or DLL is run these IL code is converted to a machine language particular to the present machine i.e. if the current machine being used to run the application is a Windows 2000 machine the IL will be converted into Windows instructions before running on the x86 processor (processor architecture used for Windows machines). When you're developing with .NET languages with a Development tool such as Visual Studio 2005 the compiler you use will generate the correct/valid IL for you, but what if you want to create your own IL for some reason! One reason could be that you've developed your own Language and would like it to run on .NET, in this case you'll need to write out some sort of Assembly, be it EXE or DLL, with IL code. To do this you can use some Classes availa...

Design Patterns - Visitor Pattern

The Visitor Pattern is a solution for a problem where you have many Objects, each Object is similar but you wish to extract information (such as a print statement) on each Object in a different way. E.g. You have a collection of Objects, each of your objects has different member variables and you want some way to call print this info. One way to do it would be to cycle through each object and Call some common method on each such as Print(), this ties the Object tightly to the printing or whatever you are doing, we want to loosly couple the printing or whatever to the object itself, to unbind the Printing from the actual Object we introduce 2 interfaces. The Visitor and the Visitable. The Visitor interface has a Visit(object) method (this is what would print the details). The Visitable interface has an Accept method, this takes the Visiting object as a parameter. The Object we want to print implements the Visitable interface, this has a callback to the implementor of the Visitor Interfa...

Installer (MSI) - Windows Installer general information

Aaron Stebner's Blog Common problems I've found while playing around with the creation of Windows installers is that if you break the uninstaller functionality it's very difficult to uninstall at all. There are a couple of ways to attempt to repair, this 1. Force overwrite of the installer with a known good installer and then uninstall. msiexec.exe /fvecmus 2. Repair the installer with a known good installer (Control Panel->Add/Remove Programs, locate you Applications installer and select "Click here for support Information", then select Repair from the resultant dialog, now point to a new location of a good installer) Then Remove. 3. Use a tool name MsiZip.exe, it's available with the MS Windows SDK , it cleans up the registry (the SDK installation takes quite a while). 4. A Windows Installer Cleanup Utility . The windows installer keeps a list in the OS of files installed by the installer, if you cannot uninstall because windows thinks one of these files ...

BootStrapper BootStrapping

Bootstrapping is the creation of a wrapper installer around already existing installars or files. It's useful if you have multiple installation files that you'll like the user to install in on step. The Bootstrapper itself is a .exe installer file, it also may have .SED file which contains details of the contents of the .exe. There are a few applications out there to generate a bootstrapper, the most simple I've seen is the an app called IEXpress . IExpress Is actually installed on windows (System32/iexpress.exe). This creates an installer, you tell it what files you wish it to include in the installation. I've only played with this so far and it appears to me that the isntaller can only install upto 2 setup.exes. You can include as many files as you like, but the files cannot have the same name, because of this you will probably need to rename your setup.exes to something else because you cannot have 2 files with the same name. After you've included all the files...

dotNET Custom Attributes

Attributes those snippets of code you see in .NET classes in square brackets at the top of Class or Method, one of the most common examples is [WebMethod] to indicate that the current method is a WebMethod . The Attribute is in fact a class that inherits from System.Attribute . The Attribute is read in at Runtime, Reflection takes care of this. Attributes are useful for flagging types, conditions when and when not to use certain methods like the WebMethod.

WiX - Windows Installer XML

Latest Release ('Rosario' November CTP msdn) now has Visual Studio Integration. WiX Tutorial (tramontana). WiX documentation (sourceforge). WiX and Visual Studio (msdn forum). WiX integration in Visual Studio using Votive (Votive blog). WiX integration (msdn). WiX Forum. Building setup packages for Visual Studio project templates and starter kits ( Aaron Stebner's WebBlog) WiX Tallow tool WiX is a methodology to write installers. WiX has a compiler/linker (candle/light) which may give the installer writer some validation before deployment. The contents of the end installer (.msi) are edited using an XML file. I haven't found WiX to be advantageous over the ordinary Visual Studio Setup Project. Visual Studios SDK has a project template (from Votive) for creating WiX installers. This project template gives you the skeletol wix file to start and the build commands are built into the project, all you've to do is create new GUIDs ,these guids are only for the installer,...

Visual Studio Extensibility

http://feeds.delicious.com/rss/learnerplates/extensibility Extending the Visual Studio IDE means adding custom functionality to the IDE, this could be custom TextEditors, Add Ins to the Tools menu, Writing to the Output Console, basically anything that will require you to add or write to any component in the Visual Studio IDE. Extending the Visual Studio IDE is not for the faint hearted. It is implemented with a Visual Studio Extensibility SDK downloadable from link 1 below. It's implemented using COM interfaces (not very nice). There are 5 points of contact for Extensibility issues 1. MSDN Visual Studio SDK homepage. 2. MSDN documentation. 3. MSDN Extensibility Forum . 4. Dr. Ex's Weblog . 5. MZ-Tools. There are also webcasts available from msdn . I recommend watching some of the webcasts especially the Managed Package Framework as the explain briefly how some of the Class Attributes work with RegPkg.exe and how important the GUIDs are. GUIDs The GUIDs are static and each con...