Notifications
Clear all

[Closed] dotnet Dictionary problem with compiled CSharp

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.

1 Reply

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()
 

Doh