I’m defining a function that takes another function as a parameter (using Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.4927) but I get a weird error.
Here’s the function definition:
public ManagementScope ConnectComputerWMI(string computerName,
string username, string password,
Action callbackProcessEnd) {... }
And here’s the error:
error CS0305: Using the generic type 'System.Action<T>' requires '1' type arguments
I’m not sure what type System.Action needs.
The error message makes it look like it doesn’t know about the non-generic
Actiondelegate, and the only reason I can think of for that is that you’re targeting .NET 2.0. In .NET 2.0, onlyAction<T>existed; more versions were introduced in .NET 3.5, and even more in .NET 4.EDIT: I’ve just seen that you’re using Visual Studio 2005 – which means you are targeting .NET 2.0. (Did you have a previous version of the question which specified .NET 4? I could have sworn you did…)
That’s the problem… now there are various solutions. You could declare your own delegate:
Or you could use
MethodInvokeror (which has an equivalent signature, but is unfortunately in the Windows Forms namespace – not ideal if you’re not using Windows Forms)…Or you could upgrade to a more modern version of Visual Studio and .NET.