Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Exception in VS2017 Community #9

Closed
davegi opened this issue Mar 15, 2018 · 6 comments
Closed

Exception in VS2017 Community #9

davegi opened this issue Mar 15, 2018 · 6 comments
Labels
bug Something isn't working fixOnDevelop

Comments

@davegi
Copy link

davegi commented Mar 15, 2018

As soon as the 'Generating mapping code" context menu gains focus:

System.NullReferenceException : Object reference not set to an instance of an object. at MappingGenerator.MappingGenerator.<MapTypes>d__4.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at Microsoft.CodeAnalysis.SyntaxList1.CreateNode(IEnumerable1 nodes) at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.AsStatementList(IEnumerable1 nodes) at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.CreateBlock(IEnumerable1 statements) at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpSyntaxGenerator.MethodDeclaration(String name,IEnumerable1 parameters,IEnumerable1 typeParameters,SyntaxNode returnType,Accessibility accessibility,DeclarationModifiers modifiers,IEnumerable1 statements) at Microsoft.CodeAnalysis.Editing.SyntaxGenerator.MethodDeclaration(IMethodSymbol method,String name,IEnumerable1 statements) at async MappingGenerator.MappingGeneratorCodeFixProvider.GenerateMappingMethodBody(<Unknown Parameters>) at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputePreviewOperationsAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>) at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)

@cezarypiatek
Copy link
Owner

cezarypiatek commented Mar 15, 2018

It's really hard to diagnose without example. Please provide code where you are trying to apply generator. (Source and target class definitions and mapping method)

@davegi
Copy link
Author

davegi commented Mar 15, 2018

Yeah...I figured it would be but was hopeful that the ST would be enough:-).

The Quick Action "Implementation of mapping method can be generated" appears on the first line of the following .ctor:

public SegmentedString(Option<string> @string) : this(string.Empty, @string, string.Empty) { }

Option is a type defined in the library lang-ext.

As mentioned, as soon as the MG menu item gains focus in the Quick Action context menu...boom...VS displays the extension error bar; "MappingGeneratorCodeFixProvider encountered an error and has been disabled", w/ the link for the ST, and buttons to re-enable.

Hope this is more helpful.

@cezarypiatek
Copy link
Owner

@davegi you forgot about SegmentedString class definition.

@davegi
Copy link
Author

davegi commented Mar 16, 2018

Sorry...I realize that you asked for the class definition but I read .ctor...here's the definition:
`

[Pure]
public class SegmentedString {
    private readonly string @string = string.Empty;
    private readonly string begin = string.Empty;
    private readonly string middle = string.Empty;
    private readonly string end = string.Empty;

    public SegmentedString(Option<string> @string)
        : this(string.Empty, @string, string.Empty) {
    }

    public SegmentedString(Option<string> begin, Option<string> middle, Option<string> end) {
        this.begin = begin.IfNone(string.Empty);
        this.middle = middle.IfNone(string.Empty);
        this.end = end.IfNone(string.Empty);

        this.@string = this.begin + this.middle + this.end;
    }

    public Option<SegmentedString> Begin => Option<SegmentedString>.Some(Option<string>.Some(this.begin));

    public Option<SegmentedString> Middle => Option<SegmentedString>.Some(Option<string>.Some(this.middle));

    public Option<SegmentedString> End => Option<SegmentedString>.Some(Option<string>.Some(this.end));

    public static implicit operator SegmentedString(Option<string> @string) => new SegmentedString(string.Empty, @string, string.Empty);

    public static implicit operator SegmentedString(string @string) => new SegmentedString(string.Empty, Option<string>.Some(@string), string.Empty);

    public static implicit operator SegmentedString((Option<string> begin, Option<string> middle, Option<string> end) @string) => new SegmentedString(@string.begin, @string.middle, @string.end);

    public static implicit operator SegmentedString(Option<ValueTuple<string, string, string>> @string) => @string;

    public static implicit operator string(SegmentedString segmentedStringEx) => segmentedStringEx.ToString();

    public override string ToString() => this.@string;
}

`
And the method in question is:

public SegmentedString(Option<string> @string) : this(string.Empty, @string, string.Empty) { }

@cezarypiatek
Copy link
Owner

Thanks, I will investigate it later.

@cezarypiatek
Copy link
Owner

cezarypiatek commented Mar 16, 2018

It looks like the readonly properties are the culprit. This issue has been fixed on develop branch and new version should be release in few days.

By the way, currently MappingGenerator maps only properties, but not fields. I will take this option under advisement.

@cezarypiatek cezarypiatek added bug Something isn't working fixOnDevelop labels Mar 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fixOnDevelop
Projects
None yet
Development

No branches or pull requests

2 participants