0
votes

Using Unity 2018-2017 with same problem on building for net- error CS0117: 'Delegate' does not contain a definition for 'CreateDelegate' This is the method:

 private V CreateDelegate<V>(MethodInfo method, Object target) where V : class
    {

        var ret = (Delegate.CreateDelegate(typeof(V), target, method) as V);

        if (ret == null)
        {
            throw new ArgumentException("Unabled to create delegate for method called " + method.Name);
        }
        return ret;

    }

Building for UWP. Using system.Linq I tryed with "MethodInfo" but maybe some parameters are wrong. This method isn“t available?

2
Is the Delegate name perhaps overloaded? Try it with System.Delegate.... - 500 - Internal Server Error
Using var ret = (System.Delegate.CreateDelegate(typeof(V), target, method) as V); with same error when i try to do a build with net : 'Delegate' does not contain a definition for 'CreateDelegate' - pacogp
Which method are available in the intellisense list? Also select Delegate and press F12 to the definition, what is the full path to the library in which Delegate class is defined? - kennyzx
I dont know if i can paste here all the code: pastebin.com/ktu4Wiad - pacogp

2 Answers

0
votes

Which platform/runtime are you targeting? I don't know about Mono, but .Net standard 1.x doesn't support Delegate.CreateDelegate. Always keep in mind that you're writing your code against a limited subset of the .Net framework. Also keep in mind that your code will inevitably be AOT-compiled on some platforms (il2cpp, iOS, etc.), so some reflection/emit features will be unavailable.

Note: AOT means ahead-of-time, meaning your code is compiled to machine instructions rather than an intermediate language. Reflection is when you use the code itself as data, so for example you can get a list of the properties a class defines. Emit means generating code at runtime. If you don't understand what those are, you should probably do some studying. It's well worth the effort in the long run.

0
votes

1. Your return type is a class, not a delegate.

where V : class

So this method doesn't even make sense. You're going to get an invalid cast exception.

2. CreateDelegate takes 2 parameters, not 3.

I'm not even sure what purpose target even serves here, so I can't even guess what you're trying to do.