Delegate results in "This is not an array but you are using it as one" errors

After converting a method to a delegate, the IDE now tells me every instance of a call to this method is a case of “This is not an array but you are using it as one”, which makes no sense.

Here’s what I did:

  1. created a delegate MyDelegate with the same parameters as the original method MyMethod
  2. made a property of MyMethod of type MyDelegate
  3. assigned in code: MyMethod = WeakAddressOf MyDelegate

And when I try to compile, now I get all these (incorrectly identified) “This is not an array but you are using it as one” errors. What have I done wrong?

Thanks.

can you make sure the method, the delegate class and the variable names are all different?

Yes, they are all different names.

Oh no, (this is embarrassing) here is what I forgot …

The method calls all need to be changed to .invoke

So, for anyone else who ran into this, the process needs to be:

  1. create a delegate MyDelegate with the same parameters as the original method MyMethod
  2. make a property of MyMethod of type MyDelegate
  3. assign in code: MyMethod = WeakAddressOf MyDelegate
  4. search and replace all your method calls MyMethod with MyMthod.Invoke

Then it works. The error makes sense if you see that since the method is now a property (of type MyDelegate) then sending the parameters to that method name MyMethod( parameters ) without .Invoke makes the compiler see that you are trying to treat the property as an array. When it is MyMethod.Invoke( parameters ) then it is correct syntax for the delegate class.