Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast Object of type(...) to ICommandHandler #46

Closed
pkskelly opened this issue Mar 17, 2019 · 6 comments
Closed

Unable to cast Object of type(...) to ICommandHandler #46

pkskelly opened this issue Mar 17, 2019 · 6 comments

Comments

@pkskelly
Copy link

Following your recent Part 1 video on using FunctionMonkey and once I have a simple structure created to verify the plumbing works, I get the following error:

[3/17/19 2:00:58 AM] AzureFromTheTrenches.Commanding: Error occurred during command execution. Anonymously Hosted DynamicMethods Assembly: Unable to cast object of type 'ThreeWill.Functions.Application.Handlers.HelloWorldCommandHandler' to type 'AzureFromTheTrenches.Commanding.Abstractions.ICommandHandler`2[ThreeWill.Functions.Commands.HelloWorldCommand,System.String]'.``` 

Using the v1.0.0 versions of FunctionMonkey an FunctionMonkey.Compiler.  
Using v9.0.1 of the Commanding Abstractions.  
Azure Functions Core Tools 2.4.401
Function Runtime Version: 2.0.12309.0

Have you seen this before?  Both macOS w/ VS Code and VS 2017 enterprise get the same result.  Debugging does not seem to get past some of the Function framework prices, or maybe I am missing a way to debug into the actual issue.  

I'll keep digging, but thought I would ask if this might be something simple.  
@JamesRandall
Copy link
Owner

Can you share your HelloWorldCommandHandler and HelloWorldCommand implementations?

@pkskelly
Copy link
Author

Hello James, thanks for the quick response! Below are the sample files.

The following is in a netstandard2.0 library named "ThreeWill.Functions.Commands"

using System;
using AzureFromTheTrenches.Commanding.Abstractions;

namespace ThreeWill.Functions.Commands
{
    public class HelloWorldCommand : ICommand<string>
    {
        public string Name { get; set; }
    }

}

The following is in a netstandard2.0 library named "ThreeWill.Functions.Application"

using System;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using AzureFromTheTrenches.Commanding.Abstractions;
using ThreeWill.Functions.Commands;

namespace ThreeWill.Functions.Application.Handlers
{
    internal class HelloWorldCommandHandler : ICommandHandler<HelloWorldCommand>
    {
        public Task ExecuteAsync(HelloWorldCommand command)
        {
            throw new NotImplementedException();
        }
    }
}

I can also share the entire solution if you'd like. Nothing in there of any import yet. Let me know. Very interested to get FunctionMonkey working - Thanks for creating it!

@pkskelly
Copy link
Author

@JamesRandall, I created a private repo and added you as a collaborator to the project. Likely something simple on my part is missing. :-)

@JamesRandall
Copy link
Owner

Thanks for that. The line:

internal class HelloWorldCommandHandler : ICommandHandler<HelloWorldCommand>

needs to read

internal class HelloWorldCommandHandler : ICommandHandler<HelloWorldCommand, string>

Your ExecuteAsync method signature will then become:

public async Task<string> ExecuteAsync(HelloWorldCommand command, string previousResult)

If your command returns a result the command handler needs that as part of its generic type definition.

Hope that helps! Will leave this issue open for the moment in case not!

@pkskelly
Copy link
Author

pkskelly commented Mar 17, 2019

Thanks James, I knew it was likely something simple! Sorry for the bother but very much appreciate the response and patience! Works perfectly!

@JamesRandall
Copy link
Owner

No problem at all.

I moved Function Monkey to v1.0.0 since I recorded the first 2 videos and there were a couple of breaking changes - in case you run into any issues there is a very short doc here that describes them and how to resolve them:

https://functionmonkey.azurefromthetrenches.com/guides/upgradingTo1.0.html

I also cover them in part 3 which I should be publishing later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants