muonlab » 2011 » August

random .NET and web development musings

Want to see the most unhelpful code ever written?

Check out System.Transactions.TransactionManager.ValidateTimeout:

internal static TimeSpan ValidateTimeout(TimeSpan transactionTimeout)
    if (transactionTimeout < TimeSpan.Zero)
        throw new ArgumentOutOfRangeException("transactionTimeout");
    if (!(MaximumTimeout != TimeSpan.Zero) || ((transactionTimeout <= MaximumTimeout) && !(transactionTimeout == TimeSpan.Zero)))
        return transactionTimeout;
    return MaximumTimeout;

So thats saying, if you provide a timeout greater than the machine.config value, ignore it and use the machine.config one. Silently. No complaining, no warning.

To increase the machine.config timeout you need to add the following to machine.config (or adjust existing values if they are present):'

  <machineSettings maxTimeout="02:00:00"/>
  <defaultSettings timeout="02:00:00"/> 

Pretty self explanatory when you know how:

Updated this code to use Mono.Cecil

var assembly = AssemblyDefinition.ReadAssembly(@"path\to\assembly");

var someType = assembly.MainModule.Types.FirstOrDefault(v => v.Name == "SomeTypeName");

someType.Namespace = "I.Live.Somewhere.New";
someType.Name = "NewName";