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

     Introduction:

 

          One of my friend ask me a question regarding an exception that he was getting when he upgrade his DotNetNuke CMS from 5.4.2.66 version to 5.6.0.459 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. 

 

    Description:

 

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

 

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

 

 

          In DotNetNuke 5.6.0.459, 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 5.4.2.66 the above method returns bool and in DotNetNuke 5.6.0.459 the above method does not return anything.  My friend was using the DotNetNuke Dynamic Module which was built with DotNetNuke version earlier than 5.6.0.45. Internally this module calls the above method which returns bool. So when upgrading to DotNetNuke 5.6.0.459, 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 5.6.0.459.

          To redefine this method in DotNetNuke 5.6.0.459, 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 5.4.2.66 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, dnn56.il and dnn56.res.   

 

 

 

 

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

            Now just open dnn42.il file with NotePad and copy DotNetNuke.Common.Utilities.Config.Touch method IL. Then open dnn56.il 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.

 

    Summary:

 

          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.

 

2 Comments

Comments have been disabled for this content.