views:

333

answers:

7

I have a control library in my application that's a bit big for the type of application I'm developing. The library is more than 2Mb and I barely use it's functionality, I would say I use like 5% to 10% of all it's functionality.

Is there anyway to remove code that my application never uses from the library?

P.S: The library is not developed by me and it's not open-source (you can buy the code though).

EDIT: I posted this because I though this could be achieved using ILMerge, that's what someone said to me in the past... I tried to use ILMerge but didn't work and I'm not sure I'm using it right...

A: 

Umm, no

You could try to write the code you DO use from the library yourself, but you can't eliminate code from the dll your referencing.

hunter
That's out of the question (see first post edit).
Nazgulled
A: 

2Mb is not large.

If you feel it's too much, and since it's your code, you should consider refactoring it into separate assemblies, still using the same namespaces. That way, your code could reference only the assemblies it needs.

John Saunders
It is too much when the app is supposed to have only a few kbs, 2mb of additional code is too much. And the library code is not mine.
Nazgulled
2Mb is not large on any modern computer with at least 256 Mb of memory, considering that it's _virtual_ memory. It won't be taking up space if you don't touch it.
John Saunders
A: 

If it's open source you can take a look at the code and selectively take out what you want and build a separate assembly.

If it's not open source you can use Reflector on the assembly and wring out the code you want to keep (and all its dependencies) and then rebuild it in your own assembly. I'm not sure how legal that is. It probably depends on the license of your library.

Martinho Fernandes
It's not open-source (see first post edit) and even if it was, that would be too much work...
Nazgulled
Unfortunately, ILMerge does the exact opposite (make assemblies have more code...)
Martinho Fernandes
A: 

You can do that, but needs some programming. take a look at mono cecil project, you can open the assembly, remove the unwanted types and save it. the programming is involved with determining what types are not used (type A is using type B, so if YOU use type A, you should keep type B)...

Ali Shafai
Too much work, I was looking for something automatic...
Nazgulled
+1  A: 

My boss worked with an obfuscation product that did this, by bringing the code that was used into a combined assembly. Can't remember what it was called though, might have been DotNet Reactor (we used a few different products before settling on one).

Jamie Penney
I don't remember what it is called but in VS2008 there is a stripped down obfuscator that will work a bit, and I expect that if you bought the licensed version it would greatly reduce the code size.
James Black
That kind of thing probably costs money for such a feature, no? This is a minor inconvenience for me, I'm not going to pay because of that...
Nazgulled
A: 

There's a product called SmartAssembly that does this. It's a bit pricey, at least for me.

hectorsosajr
+1  A: 

Just as a caveat, make sure what you are doing is permissible according to the EULA of the vendor company which made library.

AB Kolan