Search code examples
nant

Script task in NANT now complains about SortedDictionary


I've been trying to upgrade Nant from 0.86-beta1 to 0.92 in my build server, which runs Cruise Control.Net. Now (seemingly since the time I restarted the server), a <script> task fails. Even reverting to the old Nant didn't help. Here's the task:

<script language="C#">
    <code>
        <![CDATA[
            public static void ScriptMain(Project project)
            {
                    System.Collections.Generic.SortedDictionary<string, string> sortedByKey = new System.Collections.Generic.SortedDictionary<string, string>();
                    foreach(DictionaryEntry de in project.Properties)
                    {
                            sortedByKey.Add(de.Key.ToString(), de.Value.ToString());
                    } 

                    NAnt.Core.Tasks.EchoTask echo = new NAnt.Core.Tasks.EchoTask();
                    echo.Project = project;
                    foreach(System.Collections.Generic.KeyValuePair<string, string> kvp in sortedByKey)
                    {
                            // Omit the many boring nant.tasks properties
                            if(kvp.Key.StartsWith("nant.tasks"))
                                    continue;

                            echo.Message = String.Format("{0}: {1}", kvp.Key, kvp.Value);
                            echo.Execute();
                    }
            }
        ]]>
    </code>
</script>

This is a script I copied from somewhere to echo the values of all defined properties as a debugging aid. Nant complains that SortedDictionary cannot be found in the namespace System.Collections.Generic, though that's where it should be, both in .Net 2.0 (which Nant 0.86-beta1 uses), and in .Net 4.0 (for Nant 0.92). It's in the assembly System.DLL, so it seems like Nant should certainly be able to find it.

To do the Nant upgrade, I just installed the new verion in a folder next to the prior version, and changed the PATH variable. For some reason, restarting just the CC.Net service was not enough for it to start using the new version, but a restarting the computer did the trick. But then I started getting this problem. Switching the PATH back (and another restart) didn't fix it.


Solution

  • Long shot: is it possible you also have .NET 1.1 installed and it somehow is using that one?

    Just to double check, can you replace the faulting script with a script that compiles and have that script just print out the version of the .NET framework used?

    Edit actually I found another question in Stackoverflow with a similar problem. Apparently, NAnt won't reference System.dll by default. Have a look at that question for more details.