View Full Version : dotnet Dictionary problem with compiled CSharp

02 February 2012, 02:20 PM
I'm trying to compile some c# within a script. I need to return a dotnet dictionary. Whatever way i try I always seem to be getting a compile error:

"Using the generic type 'System.Collections.Generic.Dictionary<TKey,TValue>' requires 2 type arguments"

As you can see from the example, the types are specified. I've tried every which way but still seemt o get the same error. Have I overlooked something obvious or is something else going on?

max2012 x64

source = "
using System;
using System.Collections.Generic;

public class testDict
public Dictionary Process()
var dict = new Dictionary<String, String>();
dict.add(\"key\", \"value\");
return dict;
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

compilerParams.ReferencedAssemblies.AddRange #("System.dll")

compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

assembly = compilerResults.CompiledAssembly
assembly.CreateInstance "testDict"

Thanks for any help.

02 February 2012, 02:28 PM
Sorry I almost see my mistake right away in the return type I had not defined the types for the Dictionary

should be

public Dictionary<String, String> Process()


CGTalk Moderation
02 February 2012, 02:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.