2

I'm in a bit of a predicament.

I've been assigned the task of maintaining an existing ASP.NET web application for which the source code is not available - all code is compiled and put into the bin folder.

Now I need to change a few methods' implementations, this is the first time that I'm dealing with such a situation so I would really appreciate your suggestions and recommendations regarding the best way to do this.

Saeb Amini
  • 23,054
  • 9
  • 78
  • 76

3 Answers3

1

You could try to decompile it for example with the tool Reflector. The real question is: If have don't have the source code are you allowed to change this application?

codymanix
  • 28,510
  • 21
  • 92
  • 151
1

Do you need to change the implementation such that all internal references inside your legacy assembly uses the new implementation? If so, it can't be done as it would require you to change the legacy binaries (not in a way that's plausible to maintain at least).

As of refacs for client needs (i.e. references from assemblies you have control over), I suggest you write proxies and replace all references to the legacy library with proxies. This allows you to gradully extend/change the behaviour of the legacy library. Down the road this will allow you to change the legacy library with something else.

larsmoa
  • 12,604
  • 8
  • 62
  • 85
  • from his question I read that he doesn't have any source code from the web application. – Justin Shield Jul 19 '11 at 11:32
  • @Justin: yes, but altering the behaviour of the library (i.e. inject code) is totaly different from changing the usage of the library (i.e. to write clinet wrappers). – larsmoa Jul 19 '11 at 11:45
  • Even using something like Interceptors from Castle Windsors Dynamic Proxy is not a permanent solution as there's limitations as to what you can override (no static methods, no static classes and need an interface). Writing a facade or wrapping the legacy API can work for a while (as you've pointed out). Until you hit something you can't proxy. Then you're stuck re-implementing large chunks of functionality in the legacy API. – Justin Shield Jul 19 '11 at 12:06
  • @Justin: Definitly. Proxies/wrappers are just an intermediate stage before replacement/reimplementation. – larsmoa Jul 19 '11 at 12:34
1

Along with what @codymanix said.

Just decompile the assembly with ILDASM. Make the needed methods virtual (or unsealed). Recompile with ILASM. Done.

You may have to fixup calls to these methods to use callvirt, instead of call.

leppie
  • 115,091
  • 17
  • 196
  • 297