Have you ever been in a situation that a 3rd party DLL you are using has a bug but no one is supporting that code anymore? Ever wish you could decompile the code and make your own updates? I ran into this at work recently. The code in question was doing validation on an email address and it also had a hard coded regex expression. The problem was that the regex only allowed domains with 1-4 letter extensions. There are a lot more domain extensions out these days that are longer than 4 letters and we had a client that was using such a domain extension.
I went searching the web for a program that could decompile DLL code. The first one I used decompiled it to a point I could read most of it but it wasn’t able to decompile everything and so the code wouldn’t build after I made changes. The decompiler left unicode characters and other things in the code and .Net had a problem recompiling.
I then came across an open source project on Github called dnSpy. Again, it decompiled the code in question but I still wasn’t able to compile. What I was able to do though was edit the code right inside of dnSpy and re save the DLL. To do so, find the class in the DLL which has a method you want to edit. Expand the class to see all the methods for that class. Then you can right click on the method and choose either Edit Method or Edit Method Body.
After editing the method body, you can go to File -> Save All and it will re save the DLL for you.
This turned out to only be part of the solution. This DLL in question was signed and couldn’t be verified when I tried to run my web application.
The solution? Add this to your web.config:
<system.web> <hostingEnvironment shadowCopyBinAssemblies="false" /> </system.web>
Be sure to only add the hostingEnvironment property if you already have a system.web section in your web.config.
After adding that, the application fired up and worked.
You could work around the system.web thing by getting rid of all the references to the DLL in your Asp.Net temp folders. For me, that was going to be a hassle because I’d have to do it on a lot of different environments.