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

CustomReviver does not work if argument type and reviver are not defined in the same assembly #33

Closed
cranej opened this issue Nov 29, 2013 · 2 comments

Comments

@cranej
Copy link

cranej commented Nov 29, 2013

The cause is:

In ValidateArgScaffold method, ArgRevivers.CanRevive is called with the type of the property. But ArgRevivers.CanRevive loads custom revivers by searching the assembly of the type passed in. So if the type and custom reviver are not defined in the same assembly, the custom reviver cannot be found.

I encountered the problem when using System.Net.Mail.MailAddress as argument type. The code is pasted here to help you debug the issue: (in F#)

type MailAddressReviver()=
     [<ArgReviver>]
     static member Revive (key:string) (address:string) = 
           new System.Net.Mail.MailAddress(address)

 [<TabCompletion>]
 type MyArgs()=
     [<ArgDescription("Show this help information")>]
     [<ArgShortcut("h")>]
     member val Help = false with get, set

     [<ArgDescription("Mail to")>]
     [<ArgShortcut("mt")>]
     member val MailTo:System.Net.Mail.MailAddress = null with get, set
@adamabdelhamed
Copy link
Owner

I'll be adding Args.SearchAssemblyForRevivers(myAssembly) to an upcoming release to solve this issue properly. It's already checked in, but not published to NuGet. I'll leave the issue open until then.

As a workaround for now you can Make a dummy call to any Args method that does a Parse and requires a reviver for a type that IS DEFINED in your assembly. That will trigger PowerArgs to search your entire assembly and will find the MailAddress reviver.

@adamabdelhamed
Copy link
Owner

fixed

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