System.MissingMethodException: Method not found: Boolean DotNetNuke.Common.Utilities.Config.Touch()



          One of my friend ask me a question regarding an exception that he was getting when he upgrade his DotNetNuke CMS from version to version. The complete exception was: "Method not found: 'Boolean DotNetNuke.Common.Utilities.Config.Touch()' System.MissingMethodException: Method not found: 'Boolean DotNetNuke.Common.Utilities.Config.Touch()'". I was able to solve this problem and decided to add a blog post to share the solution with others. In this article, I will discuss why this exception is thrown and give you a solution. 




          The very first think I did was check the source of DotNetNuke.Common.Utilities.Config.Touch() method through Reflector. In DotNetNuke, the following source is found,   


	public static bool Touch()
	    bool flag;
	    File.SetLastWriteTime(Globals.ApplicationMapPath + @"\web.config", DateTime.Now);
	    return flag;



          In DotNetNuke, the method source is changed little bit,


	public static void Touch()
	    File.SetLastWriteTime(Globals.ApplicationMapPath + @"\web.config", DateTime.Now);



          The difference is that, in DotNetNuke the above method returns bool and in DotNetNuke the above method does not return anything.  My friend was using the DotNetNuke Dynamic Module which was built with DotNetNuke version earlier than Internally this module calls the above method which returns bool. So when upgrading to DotNetNuke, the method which returns bool was absent, that's why the above exception was thrown by runtime. So the quick solution of this problem is to redefine this method in DotNetNuke

          To redefine this method in DotNetNuke, open Visual Studio Command Prompt,



          Note, here I am opening the Visual Studio 2010 Command Prompt. Make sure to open the correct Visual Studio Command Prompt. For example, if your DotNetNuke CMS targets .NET 3.5 then open Visual Studio 2008 Command Prompt. Also note that I am opening Visual Studio Command Prompt by right-clicking on the icon and selecting Run as Administrator, which is important. Next just type ildasm to open MSIL Disassembler.




          Now just open DotNetNuke in ILDASM from File>Open dialog,




           Now just dump this assembly from File > Dump dialog. Name it dnn56(or anything else). It will create two files, and dnn56.res.   





            Now repeat the same procedure again with DotNetNuke After dumping this assembly, two additional files will be created, and dnn42.res.

            Now just open file with NotePad and copy DotNetNuke.Common.Utilities.Config.Touch method IL. Then open with Notepad, paste the copied method, save your changes and then close this file.




             Finally just type ilasm dnn56 /dll /res:dnn56.res /out:DotNetNuke.dll on Visual Studio Command Prompt, 





          Running this command will create DotNetNuke.dll assembly. Just copy and paste this assembly into your application bin folder and run your application again, your application will run without any error.

          One important thing to note here is that, in this new assembly you have two overloads for Touch method with same signature but with different return type. C# compiler will not allow such overloads but IL compiler allows you do this. So your application will run perfectly. But if you are currently developing this application and using DotNetNuke.Common.Utilities.Config.Touch method some place then I will suggest to use File.SetLastWriteTime(Globals.ApplicationMapPath + @"\web.config", DateTime.Now) instead.




          In this article I showed you an exception in DotNetNuke and also showed you how you can work around this exception quickly using IL. I hope this will be helpful and enjoyful for you.



Comments have been disabled for this content.