Subscribe: mattonsoftware.com
http://mattonsoftware.com/rss.aspx
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
adplus  application  assembly  attribute  configuration  method  methods  net  public  recycling events  state  system  version 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: mattonsoftware.com

mattonsoftware.com



Perennial Thoughts on Software Development



 



PPUtil: A Utility for Publisher Policy Generation

Sun, 11 Mar 2007 08:23:00 GMT

The conventional method of creating publisher policy (PP) assemblies becomes cumbersome when dealing with many assemblies, and many earlier versions of assemblies1. PPUtil is a configuration-based utility for generating PP for many assemblies/versions. This tool was authored using .NET 2.0, however, the resultant PP assemblies can be used with .NET 1.0/1.1-compiled assemblies. Download Binaries: PPUtil_Binaries_v1_0_0_0.zip Source: PPUtil_Source_v1_0_0_0.zip This work is licensed under a Creative Commons Attribution 3.0 License. Usage PPUtil configurationFile outputDirectory Common Usage Scenarios  Redirect a specific earlier version of an assembly to a later version;Redirect a range of earlier versions of an assembly to a later version. In both scenarios, resolution of the redirection for the earlier assembly versions is limited to major/minor version combinations i.e. build and revision numbers are not considered. This is due to the design of the publisher policy mechanism itself.  Configuration Examples Redirect a specific earlier version of an assembly to a later version Use the oldVersion attribute of the bindingRedirect element to specify the specific earlier version to redirect from. The major/minor component of the oldVersion will typically correspond to the oldMajorMinorVersion attribute of the publisherPolicy element.                                                                           Redirect a range of earlier versions of an assembly to a later version Use the oldLowestVersion and oldHighestVersion attributes of the bindingRedirect element to specify the range of earlier versions to redirect from.                                                                         Tips The provided configuration file must include a configuration section declaration for the publisherPolicy configuration section, as follows. The utility will also detect the absence of this declaration and prompt the user [...]



IIS 6: Logging Application Pool Recycling Events to the Event Log

Wed, 18 Oct 2006 11:40:00 GMT

By default, IIS 6 logs application pool recycling events to the event log when memory limits are exceeded (noting that a memory limit is not set by default) and after elapsed time (29 hours by default).

There are other reasons for application pool recycling events, such as modifications to configuration files and manual recycling requests issued by administrators. Logging of recycling events to the event log is controlled by the LogEventOnRecycle metabase property (interpreted as a bitflag).

Updating the LogEventOnRecycle property to consider other recycling events can be achieved using adsutils.vbs, or by manually editing the metabase. The following examples enable logging for all possible recycling events.

Updating using adsutils.vbs

cscript adsutil.vbs Set w3svc/AppPools/DefaultAppPool/LogEventOnRecycle 255

Updating by Editing the Metabase
  • Stop IIS: iisreset -stop
  • Backup the metabase (found at: %WINDIR%\system32\inetsrv\MetaBase.xml) 
  • Modify the LogEventOnRecycle property:
Branch :            /LM/W3SVC/AppPools/
Key Name:       LogEventOnRecycle
New Value:      255 (default is 137)

The metabase can be edited using the Metabase Explorer (available as part of the IIS 6 Resource Kit Tools).
  • Start IIS: iisreset -start
For further information about the LogEventOnRecycle metabase property, see the following articles:
How to modify Application Pool Recycling events in IIS 6.0
LogEventOnRecycle Metabase Property
Also note that IIS creates worker processes for application pools on demand. Thus, a recycle request may be issued but not result in an event log entry if no actual worker process is active. For more information:
Why IIS6 Application Pool Recycle Events are Not Logged
(image)



LibCheck: Highlight Public API Differences Between Assembly Revisions

Thu, 28 Sep 2006 12:50:00 GMT

LibCheck is an assembly comparison tool that:

"... allows you to compare two versions of an assembly, and determine the differences. The tool reports the differences as a combination of 'removed' and 'added' APIs."

The comparison results present:
  • "removed" items: the original member has been either removed or modified;
  • "added" items: member has been added to the new version, or is a modified form of an original member;
  • breaking changes highlighted in red.
The following example compares two versions of an assembly.

Generating Metadata for Comparison

libcheck.exe -store AssemblyName FolderNameToStoreResults -full FolderContainingAssembly

For example:

  libcheck.exe -store HelloWorld.dll 1.0.0.0 -full C:\HelloWorldV1\

  libcheck.exe -store HelloWorld.dll 2.0.0.0 -full C:\HelloWorldV2\

Performing the Comparison

  libcheck.exe -compare FolderContainingFirstStoreResults FolderContainingSecondStoreResults

For example:

  libcheck.exe -compare 1.0.0.0 2.0.0.0

Here is an example comparison report.
(image)



Debugging Production Applications using ADPlus

Fri, 22 Sep 2006 02:02:00 GMT

ADPlus is used to take snapshots of processes in environments where development-time debugging tools are not available e.g. Production server farms, end-users workstations. ADPlus is a Visual Basic script provided as part of the Debugging Tools for Windows that wraps the CDB debugger. Snapshots of processes taken with ADPlus are analysed using the Windows Debugger (WinDbg). Managed processes in particular are analysed using SOS.dll, which contains extensions to WinDbg for debugging managed processes.Practical applications include taking snapshots of WinForms and ASP.NET processes to interrogate unhandled exceptions, memory utilisation, resource contention etc. Installing Debugging Tools for Windows in Target Environment Download debugging tools; XCOPY deploy to target environment; Create a folder to store snapshots; Set CScript as the default scripting engine (required by ADPlus, also requires Windows Script Host 5.6 or higher, interrogate version using CSCRIPT /? command) CSCRIPT /H:CScript Taking a Snapshop using ADPlus The following examples demonstrate taking a snapshot of a WinForms process: Via process idADPlus.vbs -c ADPlus_Config.xml -p 968 Via process nameADPlus.vbs -c ADPlus_Config.xml -pn HelloWorldGUI.exe Note that ADPlus will warn that the _NT_SYMBOL_PATH environment variable is not set. This is ok as the environment variable is not required for taking snapshots, however, it is required for analysing the snapshot later. The following example ADPlus_Config.xml file configures ADPlus for Hang mode (hang mode instructs ADPlus to take the snapshot immediately, crash mode is another option that attaches the debugger to the process, then waits for process to exit before generating the snapshot):             HANG                C:\Snapshots                     .load C:\Program Files\Debugging Tools for Windows\clr10\sos.dll                                                              AllExceptions                                         FullDump;                                         GN                        Using WinDBG and SOS.dll Install debugging tools; Add installation location to PATH environment variable; Create a folder to store symbols; Add new environment variable, referencing the symbols folder: Name: _NT_SYMBOL_PATHValue: SRV*c:\temp\symbols* http://msdl.microsoft.com/download/symbols This setting is used by WinDbg to dynamically download symbols (pdb files) on demand. Launch WinDbg.exe; Open the snaps[...]



OPML Listing

Sat, 05 Aug 2006 05:02:00 GMT

From time to time, I'm asked by my colleagues which feeds I subscribe to. The following is an OPML listing of my subscriptions:

IT Subscriptions.xml

Enjoy!
(image)



.NET Resources: Updated

Sat, 06 May 2006 08:25:00 GMT

Managing hyperlinks via CommunityServer has become too cumbersome, I've shifted these resources to del.icio.us, as follows:

http://del.icio.us/MattDunn

You can also subscribe to changes via the following feed:

http://del.icio.us/rss/MattDunn

Many thanks to Grant for the tip!
(image)



Issues Migrating from .NET 1.0 to .NET 1.1

Mon, 06 Mar 2006 10:48:00 GMT

Mainstream support for .NET 1.0 ends 30 June 2007. For organisations migrating from .NET 1.0 to .NET 1.1, the following changes are for  consideration: Backwards Breaking Changes from version 1.0 to 1.1 API Changes between versions of the .NET Framework: Version 1.0 to Version 1.1In addition to the changes listed above, the following issues were encountered during a recent migration activity. Web Service WSDL Generation IssueAfter upgrading websites from ASP.NET 1.0 to 1.1, the following error message may be encountered: The XML element named 'HelloWorldMethodResponse' from namespace 'http://www.test.com' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute. This error occurs when the WSDL for a web service is being generated. Note that the error message includes two possible solutions. The first of these solutions which recommends changing the web methods message name using the WebMethodAttribute is undesirable as this will alter the WSDL contract and break existing consumers. The second of the two solutions, applying the XmlRoot attribute to the web methods return type, will resolve the error, however, this requires recompilation of existing web service assemblies. Properties of web methods that cause this error include: The return type is a class or structure; The return type is named [WebMethodName]Response; The web method accepts no parameters (or has parameters that do not serialise to a complex type in the WSDL, for example, strings, integers). This error does not affect the invocation of existing client proxies as they do not consume the WSDL at runtime.  This issue will affect development activities when the WSDL is requested, for example, when re-generating client-side proxies using the Visual Studio Add/Update Web Reference feature. To resolve this issue, apply the XmlRoot attribute to the return type of the WebMethod, noting the following: The ElementName should be of the form [ResponseType]Dummy. Note that no element named HelloWorldMethodResponseDummy will appear in the WSDL; The DataType property should be set to the response type. An example application of the XmlRoot attribute is as follows: [WebMethod(Description = "Test Method")][return: XmlRoot(Namespace = "http://www.test.com/",         ElementName = "HelloWorldMethodResponseDummy",         DataType = "HelloWorldMethodResponse",         IsNullable = false)]public HelloWorldMethodResponse HelloWorldMethod(){    return new HelloWorldMethodResponse();}Activator.CreateInstance() raises a System.MissingMethodException exception when creating instances of ArraysIn order for the Activator.CreateInstance() method to create instances of a given type, the type must define a public default constructor. In .NET 1.0, the Activator does not raise an exception when creating instances of Arrays (which has a private default constructor), however, this issue has been fixed for .NET 1.1 and now raises a System.MissingMethodException ("No parameterless constructor defined for this object") exception as expected.To resolve this issue, the Array.CreateInstance() method can be used instead of Activator.CreateInstance(), as follows: ...if (typeToInstantiate.IsArray) {     Type elementType = typeToInstantiate.GetElementType();     newInstance = Array.CreateInstance(elementType, arraySize); } else {     newInstance = Activator.CreateInstance(typeToInstantiate); }[...]



Diagnosing Binary Formatter Version Incompatability Problems

Tue, 28 Feb 2006 10:37:00 GMT

Clients consuming remoting services hosted in IIS (and therefore exposed via the HTTP channel) configured to use the binary formatter may receive the following error: An unhandled exception of type 'System.Runtime.Serialization. SerializationException' occurred in mscorlib.dll Additional information: BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 1008738336.1684104552. This article explains that the above error is masking the original exception, and describes a mechanism for tracing this exception. However, this tracing process requires opening additional ports on the server, which may be problematic if the application under inspection is hosted in a secured environment. An alternative to tracing the error is to configure the remoting service to use the SOAP formatter instead of the binary formatter, which will allow the original exception to propogate to the client correctly. The SOAP formatter is the default formatter for the HTTP channel, so assuming the remoting system is configured declaratively, the following elements can be removed/commented out of the configuration files: Client                                                                                                                                                 Server                                                                         Also note that custom errors must be disabled on the server for the original exception to propogate correctly:                  [...]



WinForms use of AssemblyInformationalVersion Attribute

Sun, 26 Feb 2006 05:58:00 GMT

The AssemblyInformationalVersion attribute provides a secondary mechanism for versioning an assembly without modifying the value of the AssemblyVersion attribute, thus consumers of an assembly do not need to apply binding redirects or publisher policy when revisions of an assembly are deployed.

Contrary to the documentation:

The attribute defined by this class attaches additional version information to an assembly for documentation purposes only. This data is never used at runtime.

this attribute is referenced by the System.Windows.Forms.Application.ProductVersion static property, which in turn is referenced by the Application.CommonAppDataPath, Application.LocalUserAppDataPath and Application.UserAppDataPath static properties. This is the case for the  .NET 1.* and .NET 2.0 class libraries.

If the AssemblyInformationalVersion attribute is applied to the base executable, the ProductVersion property and its dependent properties will use this value instead of the AssemblyVersion attribute value.

Microsoft states that this behaviour is by design.
(image)



Writing Well-Factored Code

Sat, 27 Aug 2005 11:24:00 GMT

Coding is a design activity conducted at the lowest level. Similar to analysis and design patterns aiding their respective phases of the software development process, coding patterns exist to aid the implementation phase. Common coding patterns/techniques include:Keep methods small, focussing on discrete tasks;Early exit to reduce nesting;Use private fields to reduce internal parameter passing;Use regions as a categorisation mechanism, not to hide code; andUse internal commenting sparingly.Keep Methods Small, Focussing on Discrete TasksImplementing methods of short length facilitates functional decomposition, making it easier to debug errors and more clearly communicate the intent of code. Consider the following example:public class Employee {     public void DoWork()     {         this.ProcessOrders();         this.TakeBreak();         this.SweepFloor();     } }Issues associated with this technique include:Appropriate method length; Method naming; Focus on allocation of responsibilities; Reuse benefits; andPerceived Performance Implications.Appropriate Method LengthWell-factored methods should be 5-10 lines in length. If methods exceed this length, then further factoring is required. There will be instances whereby decomposing methods to achieve this goal does not add value, examples being methods that perform mapping functions or rudimentary validation.Method Naming It is imperative to name methods that reflect the intent of the behaviour of the method. Such names should also be kept as short as possible. Appropriate naming of methods significantly reduces the need for internal commenting. Focus on Allocation of Responsibilities Decomposing methods into smaller functions, or responsibilities, also makes it easier to see which classes are responsible for what behaviour. Reallocation of responsibilities often results from method factoring. This is a key component of Responsibility-Driven Design. Reuse BenefitsFactoring methods into smaller functions makes it easier for functionality to be reused/overridden/extended by subclasses. This also avoids the common problem of large methods being copied into subclasses to change a small part of the method, leading to future maintenence issues.Perceived Performance Implications Factoring methods into smaller functions implies an increase in the number of method invocations, which can lead to performance concerns regarding the overall increased cost of  method invocation. For normal business code, this low-level concern is unfounded. If you are writing a core function for a framework (similar to the core services provided by the .NET Framework), then the cost of method invocation may become important. To address this issue, profiling of the problem area should be conducted, then act accordingly.Early Exit to Reduce NestingExiting early from methods reduces nesting and indentation. Consider the following example:Before:public class Employee {     public double CalculateExpectedBonus(double salary)     {         double total = 0;         if ((salary != null ) && (salary > 0))         {             if ((_name != null) && (_name.StartsWith("FRED")))             {                 total = salary * (_weight / _height);             }         }      &nbs[...]



Implementing the State Pattern in C#

Tue, 26 Jul 2005 12:45:00 GMT

Implementing behavior that adapts to changes to the internal state of an object is a difficult task.  If not designed correctly, such behavior can contain duplicate/nested conditional logic that is difficult to understand and maintain. Overview of the State PatternThe state pattern encapsulates state-based behavior in discrete classes. Responsibilities are identified and delegated to appropriate states, whilst polymorphism eliminates conditional logic, and delegation removes duplication. Such factoring simplifies logic and ultimately results in code that is easier to maintain and extend over time. Applying the State PatternApplying the state pattern entails: Defining the state machine, including the states and transitions; Defining an abstract base class that includes default implementations for all properties and behavior handled by the state machine; Defining concrete classes for each state which derive from the abstract base class; Define properties and methods for each concrete class which override default implementations from the base class; Delegating to the state machine from the enclosing class.Consider the following application of the state pattern.An Example, the Order ClassAn Order can be processed (either successfully or unsuccessfully) or cancelled. Defining the State MachineThe states (including the initial and final states), and the transitions with respect to the Order class are:States:   New, Processed, Cancelled.Initial State: The New state.Final States: The Processed and Cancelled states.Transitions: Process() = Successful, between the New and Processed states; Process() = Unsuccessful, both starting and finishing at the New state; Cancel() between the New and Cancelled states.The complete Order state machine is as follows:Defining the Abstract Base ClassThe abstract base class of the state machine is defined as follows: Methods corresponding to each of the state transitions are required. These methods will do nothing by default, and will be overridden by subclasses as appropriate. Each method will accept a reference to an object of the enclosing class as a parameter (the Order class in this example) which they can manipulate if required; For each state, an associated querying property is required, the default implementation of which will return false; The abstract base class, and derived classes, should be marked as internal as they are only intended to be accessed by the enclosing class.The abstract base class for the Order example will be called OrderState, the implementation of which is as follows:    internal abstract class OrderState    {        #region Public Properties        public virtual bool IsNew        {            get { return false; }        }        public virtual bool IsProcessed        {            get { return false; }        }        public virtual bool IsCancelled        {            get { return false; }        }        #endregion        #region Public Methods        public virtual void Process(Order order)        {        }        public vi[...]



Greetings

Tue, 26 Jul 2005 12:27:00 GMT

I'm Matt Dunn, a twenty-something IT professional based in Canberra, Australia.

My intent is to illustrate solutions to software development issues, focussing on Object-Oriented software development, with examples primarily implemented in C#.

Enjoy!(image)