1

well I am having a problem renaming the ICSharpCode.SharpZipLib.dll file to anythig else. I am trying to shorten the file name. I reference the assembly in the project, but when the program reaches the statements where I use the library. It spawns an error that it could not find the assembly or file 'ICSharpCode.SharpZipLib'. When I change the file name back to ICSharpCode.SharpZipLib.dll the application works noramally. So, is there any way to change the file name. Also, am I allowed to change it without violating the license (I am going to use it in a commercial application). Thanks.

McNeight
  • 21
  • 3
None None
  • 195
  • 1
  • 3
  • 9
  • Probably you are having a reference in your application that still references the name before you renamed the assembly? – Uwe Keim Jan 13 '11 at 18:47
  • 1
    Just curious on what exactly is the issue with the name length? – Aaron McIver Jan 13 '11 at 18:52
  • 1
    In computing, names are only just becoming descriptive, we're leaving a lot of terrible mistakes behind; Here's hoping you're not creating a time machine, to take us back there. – Grant Thomas Jan 13 '11 at 19:08

3 Answers3

7

You could try to disassemble the library and then re-assemble with a new name.

E.g.

1) Open Visual Studio command prompt.

ildasm /all /out=ICSharpCode.SharpZipLib.il ICSharpCode.SharpZipLib.dll
ilasm /dll /out=shortname.dll ICSharpCode.SharpZipLib.il

2) Add shortname.dll to the project

user797717
  • 758
  • 1
  • 6
  • 18
  • 1
    I also had to edit the intermediate (.il) file and find/replace the old name with the new name. The replacements occurred in the ".assembly" and ".module" entries, specifically. This is definitely the easiest way to rename an assembly. Thanks. – Jin Feb 28 '15 at 09:44
  • This is great, but it doesn't work when there is unmanaged code. – nurettin Mar 15 '17 at 18:32
  • @user797717 I tried de-assembling and re-assembling to short name using this, but I get an error during one step https://imgur.com/kZxtBZY . Any insights? –  Jun 08 '21 at 00:49
  • so i removed the code from .il which was giving error since I didn't need to s=thise functions , but now it gives me this error that : Could not create output file, error code=0x80070005 –  Jun 08 '21 at 01:08
5

SInce you renamed the DLL, the .Net runtime doesn't know how to find it automatically.

You can call Assembly.Load to manually load the renamed file.
Note that you'll need to do that before calling any methods that use the assembly, since the JITter needs to load all types used (directly) by a method before the method starts executing.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    @John: You probably loaded it too late. Load it before calling any methods that use it, so that the JITter can find it. – SLaks Jan 14 '11 at 16:22
  • Slaks, that is what I did exactly (I have loaded the assembly on the form load event). I have spent about 6 hours looking for an answer, but what I should have done is dig into the documentation. After spending about half an hour reading on how the assembly resolution is done, I have figured out how it should be handled. Thanks a lot for your time. – None None Jan 14 '11 at 18:08
  • You can listen to the AppDomain.AssemblyResolve Event which is raised when the JITer fails to load an assembly. In your event handler you can manually load the required assembly in the manner SLaks suggests. – David Pond Jan 05 '14 at 15:44
-2

The DLL is compiled so renaming the file will not change the namespace's inside of it anyway. You can assign an alias to it through a using directive.

using zip = ICSharpCode.SharpZipLib;
Dustin Laine
  • 37,935
  • 10
  • 86
  • 125