Skip to main content

Posts

Debugging Windows Exceptions with Adplus V7

A tool called Adplus can be used on Windows to get more information on unexpected exceptions, hangs and crashes. If one of these has been reported on a production machine then run Adplus in the background, monitoring that process, and check from dump files afterwards. The dump files should include information on that happened just before the exception, crash or hang. The dump files can be opened in Visual Studio or Windbg for example and ran as a debugging session. There is a new version of Adplus available, Adplus V7 , it's an exe where the old was a vbs. Adplus comes with the "Debugging Tools for Windows", google this to find the latest version. First stop http://www.codeproject.com/Articles/315536/Adplus-Handling-managed-exceptions To get a dump on an exe use the -sc switch with adplus (ensure this is the last switch on the command line) and point it to the full path of the exe. If adplus is working it will launch the exe in a separate window, if not then it...

Immutable Objects

Immutable means "can not change". When an object is referred to as Immutable it means the internals cannot be changed i.e. it's member variables. This is a design choice, where you might wish objects to be passed around as method arguments but you do not want the original object's internal values to change. Remember that in C# when you pass an object of type Reference Type into a method as an argument, you are actually passing it by reference, meaning the method can change the original objects values. To protect objects  from this make them immutable. How: Objects are made immutable by simply making their internal variable readonly.

Dependency Injection IoC

"Dependancy Injection" is a more specific name for and term used "Inversion of Control". It's all about letting client developers of your code add there own implementations. To do this your code needs to be very loosly coupled (i.e. none of the usual newing up of concrete classes, the code must be written using Interfaces for example) and configurable (e.g. the client developer drops their implementation dll into a location and adds content to a XML configuration file to tell your host app what class to load and instantiate from the dll). This is a good intro to "Dependancy Injection"  http://www.martinfowler.com/articles/injection.html These are intros to Microsofts "Dependancy Injection" framework, Unity. https://www106.livemeeting.com/cc/wwe_us/view?cn=guest&id=1032382093&pw=23D44136  with sourcecode at  http://unity.codeplex.com/wikipage?title=Webcast%20demos&referringTitle=Home http://visualstudiomagazine.com/ar...

XML file for Visual Studio HelpViewer 1.0

The following XML file is used in combination with the XSLT file posted in an earlier post. These 2 files transform into HMTL that views correctly in Visual Studio 2010 HelpViewer 1.0. <? xml   version = " 1.0 "   encoding = " iso-8859-1 " ?> <? xml-stylesheet   type="text/xsl" href="../xslt/gravity.xslt" ?> < HelpDocument >   < Meta >     < title > Add </ title >     < metaTitle > Add </ metaTitle >     < metaID > Help3-7F3D2D9D-Add </ metaID >     < metaParent > Help3-7F3D2D9D-Entity </ metaParent >          < metaKeywords >       < metaKeyword >         < keyword > Add </ keyword >       </ metaKeyword >   ...

XSL XSLT file for Visual Studio HelpViewer 1.0

This XSL/XSLT file is based on a Visual Studio Help file found in "C:\ProgramData\Microsoft\HelpLibrary\content\Microsoft\store\Development_Frameworks_21823146_VS_100_en-us_9.msha" I've stripped out the content and replaced with  < xsl:if   gt; etc. The values for this content are taken from XML files which have the corresponding XML element hierachy, e.g

XML to HTML

To convert XML to HTML you need an XSL (XSLT) file and some application to transform the XML to HTML using this XSL file. Usually this work is done by the browser, by including a link to the XSL file in the XML file, when you open the file in a browser it runs the transform on the XML using the XSL file you've pointed to. But I wanted to run this as a seperate step from a batch file so that I can create my .html files on disk but maintain their content using XML. Here's how I've done it: using   System ; using   System . Collections . Generic ; using   System . Linq ; using   System . Text ; using   System . Xml . Xsl ; using   System . IO ; namespace   Tool . XMLToHTML {      class   Program     {          ///   <summary>          ///  "Help\Help3\_HelpSource\gravity.xslt" "Help\Help3\_HelpSource"...

Visual Studio 2010 HelpViewer 1.0 Custom Help Creation

Recently I've been working with our legacy HTML help files, trying to add them the the new Visual Studio 2010 HelpViewer. This is not a simple task. We wanted the styling of our html to be the same as .NET help files We would also like there to be little or no maintenance required to keep them up to date with the latest Visual Studio Help Styles etc. We have a custom development language so the code snippets require their own color coding and the Language should be "Gravity" and not C# or VB. The content itself should be easily maintained. Our own applications logos and copyright should appear instead of Visual Studios. The requirements above proved to be not a simple to implement as you might think. Below I'll mention the snags I came across and describe how I overcame them. 1. Styling: The styling information was not simple to find, there are documents on http://www.helpware.net/mshelp3/intro.htm which explain some of the content of the help files, this is...

TFSbuild custom parameters and Testing

To test your Team Build Project locally with TFSBuild use the Visual Studio 2010 command prompt. here's a sample C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>TFSBuild start /collectio n:http://MYSERVER:8080 /builddefinition:"MYTFS/TestBuild" /droplocation:"\\ SOMECOMPUTER\SOMEDIRECTORY" http://msdn.microsoft.com/en-us/library/ms181742.aspx However firstly I recommend testing the syntax of your project with MsBuild e.g. C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>msbuild C:\SOMEDIR\TeamBui ldTypes\MsBuildSamples\TFSBuild.proj http://msdn.microsoft.com/en-us/library/ms181723(VS.90).aspx In order to tell msbuild to run a particular target within use something like C:\MsBuildSamples>msbuild TfsBuild.proj /t:DesktopRebuild this will run the Target "DesktopRebuild". Passing Parameters/Arguments To use parameters passed in through TFSbuild it's simple, just pass in your argument with the /property switch on the command line o...

Build with .NET 4.0 in Team Foundation Server

In order to force your Team Build to use the .NET assemblies and tools you'll need to make the following change. Change the value in the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\tfsbuildservice.exe.config From add key="MSBuildPath" value="" to add key="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319" TFS service must be restarted afterwards "Visual Studio Team Foundation Build" http://blogs.infosupport.com/blogs/martijnb/archive/2010/05/04/building-visual-studio-2010-solutions-using-team-build-2008.aspx

Dependency Injection

Loose coupling i.e. making your code modules less tightly bound to each other. Dependency Injection helps this process, allowing clients of your code to get the application using their own code without them having to know very much at all as to how the application works internally. The article linked in the title of this post has a very brief outline of some how it can work but basically I'm interested in using Interfaces and registering my own classes with the host application with the minimum possible code work. There are lots of third party frameworks which provide implementations. The method is usually the same, create and instance of the third party class and then call a method on it which tells the framework to run a particular concrete class that you have provided when a particular interface or type is used, it's a form of mapping allowing client classes to be used at runtime. http://www.martinfowler.com/articles/injection.html

ISerializable - Serializing objects

Serializing is a mechanism to create a text/binary version of your objects state, this can be saved or sent somewhere and then deserialized back into the instance again. i.e. The member variables of your Type get written somewhere with their values of the instance of your Type. e.g. Here's the class who's instance I want to recreate somewhere else or at a later time. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SimpleClass { public class Class1 { public int _myMemberVar; /// /// required for serialization /// public Class1() { _myMemberVar = 0; } public Class1(int value) { _myMemberVar = value; } } } Here's a class which Serializes the instance of the class above with the XMLSerializer. The version below writes the XML version of the instance to the Console, you could replace the using (Stream str = Consol...

Testing COM components

Here's some code you can use to try to load your Type through COM. You can use the GetPEKind method to get the platform that the assembly was compiled for. (Recently ran into a problem where I couldn't be sure the assembly I'd registered was registered correctly, my query was particular to win64, there are some changes in the registry entries for 64bit windows when running 32 bit applications.) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; namespace ComTest { class MyGetTypeFromCLSIDSample { public static void Main() { try { Guid myGuid1 = new Guid("3A21CE6B-8571-4955-9780-BAE1EE3215C0");//my Types GUID, regasm was ran on this assembly. // Get the type associated with the CLSID // and specify whether to throw an exception if an error occurs // while loading the type. //if this shows The typ...

Visual Studio build configuration with x64 "Any CPU"

In Visual Studio you may have noticed, and ignored, the pulldowns in your toolbar which usually contain "Release" "Any Cpu". The "Any CPU" part in particular is of interest especially if you plan on running your apps on Windows 64. These configurations are contained in each project and solution i.e. if you open the projects in a text editor you'll see sections in the XML which contain the settings. These settings are also accessible through the Visual Studio UI via the pulldowns mentioned earlier. The significance of the "Any CPU" is it's telling the compiler to compile the code into assemblies into code which can run on either 32 or 64 bit machines. If your assemblies are used by an application written in 64bit (and of course the app runs on a 64bit machine) then your assemblies will be used in the 64bit context, the same stands for 32bit (of course 32bit apps can also run on 32 or 43 bit machines). 64bit machines have an additional regi...

Roles in ASP.NET

Roles are part of the Authorization in ASPNET i.e. a mechanism to tell if the user has or has not access to resources. Roles are a mechanism to group users into sets of permissions. Roles can reuse already existing groups from windows. Roles can also be linked into a SQL database. Roles are configured on the aspnet websites web.config. http://msdn.microsoft.com/en-us/library/ff647401.aspx

XMLSerializer and .NET CLR (sgen.exe)

You might have spotted on your .NET projects in Visual Studio a radiobutton to turn on/off serialization "Generate serialization assembly" in your project's property's Build tab , so what's that all about? Serialization is a mechanism for recreating .NET objects from text. There's another post in this blog on the topic. So why is this option on your project? in brief it's there as a performance improvement for .NET CLR. .NET serializes the assemblies when loading, if you tick the "Generate serialization assembly" listbox your creating a second assembly to accompany the original, the second assembly , with extension .xmlserialize.dll , will be loaded by the CLR at load load if it exists, this improves performance at load time because now the CLR does not have to serialize the original assembly at load time instead if can just load the already existing second assembly. The second assembly is generated with Visual Studio with a tool called sgen.exe...

Interop Assemblies

What the hell are these Interop Assemblies, Primary Interop Assemblies (PIAs)? You'll see these assemblies from time to time pulled in as references in you projects, but I never really cared why they were called Interop and what it meant, I'll explain. Interop is short for interoperability meaning how to get .NET to talk to COM. Primary Interop Assembly (PIA): A PIA is an interop assembly that is signed by the originator to mark it as the one and only assembly to use to get the Type information. It's used to avoid conflicting Types. The assembly is signed in a particular way using the tlbimp.exe and then used by the client to resolve Types. http://msdn.microsoft.com/en-us/library/aa302338.aspx What have they got to do with COM? So implementations and Types available through COM is not accessible itself through .NET itself in the usual manner i.e. you cannot new up objects etc because you do not know the Type names. To get over this the COM Types are wrapped into an Interop ...