3

I am currently working on a project which uses the AutoFac Inversion of Control container.

I am attempting to convert some example code from C# into a codebase of an existing project of mine which is written in VB.NET and I've hit a problem.

The original line of code is:

EventHub.Subscribe<HandshakingEvent>(container.Resolve<HandshakeAuthenticator>().CheckHandshake);

Which I have converted to:

EventHub.Subscribe(Of HandshakingEvent)(Container.Resolve(Of HandshakeAuthenticator)().CheckHandshake)

But - this is causing an error, "Argument not specified for parameter 'ev' of CheckHandshake".

The type of the parameter for the EventHub.Subscribe(Of HandshakingEvent) procedure is System.Action (of HandshakingEvent)

I can see what the problem is, I'm just not really sure what to do about it! I've tried using 'AddressOf', but that doesn't seem to work, either.

Thanks in advance... - Chris

1
  • What's CheckHandshake? Commented Nov 7, 2010 at 23:48

2 Answers 2

5

Try

EventHub.Subscribe(Of HandshakingEvent)(AddressOf Container.Resolve(Of HandshakeAuthenticator)().CheckHandshake)

(using the AddressOf keyword to get a delegate)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - You're spot on. I had tried 'AddressOf', but it still didn't work. It turns out it was for a different reason, though! I had declared the parameter of CheckHandshake as ByRef, not ByVal!
3

The VB code is trying to call the method instead of creating a delegate for it. Use the AddresOf operator to get a deletegate:

EventHub.Subscribe(Of HandshakingEvent)(AddressOf Container.Resolve(Of HandshakeAuthenticator)().CheckHandshake)

The keyword is not needed in C#, as parentheses are always used when you call a method, but in VB you can call a method without parentheses also.

1 Comment

Thanks - You're spot on. I had tried 'AddressOf', but it still didn't work. It turns out it was for a different reason, though! I had declared the parameter of CheckHandshake as ByRef, not ByVal!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.