## random .NET and web development musings

Pretty self explanatory when you know how:

Updated this code to use Mono.Cecil 0.9.5.0

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";

assembly.Write(@"path\to\output");

Jb Evain
August 2, 2011

Hi, I suggest you use the more modern 0.9 version of Cecil from:

http://github.com/jbevain/cecil

Or available in nuget. It requires some changes outlined there:

http://github.com/jbevain/cecil/wiki/Migration

But speed and API wise, it’s totally worth it

August 2, 2011

Interesting, I’ve updated the post. Thanks!

Matthew Steeples
May 15, 2013

I know this is an incredibly old post but I tried doing this today and it failed on updating the references to types that were used in custom attributes. I’m investigating why and I’ll post here if I find out.

May 15, 2013

Failed how? The Cecil mailing list is quite active and @jb is active on github and twitter iirc

Matthew Steeples
May 15, 2013

That’s a bit strange. Merely enumerating over the Attributes and their Constructor arguments was enough to update the references so that when I saved the assemblies the references had been updated!

Matthew Steeples
May 15, 2013

Just saw your post when I posted my second one. I’ll have a look on the mailing list and see if anyone knows why or if it’s anything that needs fixing. Thanks