Skip to content

Issue: DynamicClassFactory fails to create dynamic type without properties #215

@david-garcia-garcia

Description

@david-garcia-garcia

Will work on a PR when got the time, just posting here for the record.

DynamicClassFactory.CreateType() will create a DynamicType with a "duplicate" constructor when the type has no properties and createParamterCtro = true.

This breaks later code when they try to find the constructor implementation.

I found this when doing:

                    var countQuery = query;

                    if (this.GroupBy != null)
                    {
                        countQuery = countQuery.GroupBy(
                            CustomParsingConfig.ParsingConfig,
                            this.GroupBy.KeySelector.Expression,
                            "new()");
                    }

                    result.Count = countQuery.Count();

Here I am using a dummy new() for the projection because I only want to count the results.

As a workaround, I replaced "new()" with "1", but still the bug is there.

The problem is when names.Length = 0:

image

The solution is to not create the second constructor if the type has no parameteres.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions