Search code examples
dllreferenceinternalstrong-typingildasm

ildasm Reference Internal Classes in third Party DLL


Grreting guys,

A problem is bothering me for a few days and I thought may be it's time I share it with the community.

I need to make changes to an old project in the corp. This Dll references a third party dll and uses an Internal Class in that DLL. The referenced Dll had this file declared as a friend or InternalVisibleTo was set to this file name and publicToken.

Now, I want the referenced dll to allow me to access it's Internal contents but in my project I get the error "'BlaBla' is inaccessible due to its protection level" which clearly states that it wont allow me to access an Internal class from a new Dll.

Solutions I have tried so far:

  1. Used Ildasm on the referenced DLL and in the il file in the InternalVisibleTo section for my file, I removed the whole PublicTokenKey. Ilasm it again but no success.

  2. Made a new Strongly Typed name for my dll same as the name it had before, but it didn't work.

    ilasm foo.dll /dll

So now I am left here unable to go any further. I really appreciate any helps or discussions related to this matter.

PS: I want to share a question very similar, which I followed line by line and it didn't work https://stackoverflow.com/a/12202623/861489


Solution

  • OK, it seems I have finally managed to break the spell! I share it with you guys for anyone came here in future.

    The process was correct, The only problem was the friendship declaration in the referenced Dll Manifest. I used "JustDecompile" tool from Rad tools and saw the problem JustDebug Screen

    You see the Dll I declared as a friend was defined wierdly! I found out that there is no way I can do this in IL file editor without making errors. So I used the "JustDecompile" to decompile the code for me and make the project. It had so many errors and didnt compile. But I didnt care. I removed all the code files and added an empty code file. Then in the AssemblyInfo.cs file I found the declarations of InternalVisibleTo tags I was looking for. I changed my intended file and removed the PublicTokenKey from it and compiled the project with 1 cs file. I just ildasmed it and got the new record for it in the manifest file! I used this new record in my old file manifest and ilasm it. put it in my project and vola! it works! God it was fun!