Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

No parameterless Constructor defined #4895

Closed
fhnainia opened this issue Jun 22, 2016 · 6 comments
Closed

No parameterless Constructor defined #4895

fhnainia opened this issue Jun 22, 2016 · 6 comments
Assignees

Comments

@fhnainia
Copy link

fhnainia commented Jun 22, 2016

When posting a form with a POCO object and FormCollection object to a Controller Action a SystemMethodException occurs. This was working fine in RC1 but since the upgrade to RC2 the exception started.
Here is the part of the Action:

// POST: Candidate/Create
        [Authorize]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> Create(Candidate candidate, FormCollection obj, IList<IFormFile> files)
        {
            var auser = await _userManager.FindByNameAsync(User.Identity.Name);
            var employee = _employeeService.GetEmployee(auser.Id);
            if (employee != null && employee.PartnerId != null)
            { 
                ViewBag.PartnerId = employee.PartnerId;
            }
       ...
       }
@rynowak
Copy link
Member

rynowak commented Jun 22, 2016

This should be IFormCollection instead of FormCollection, we intentionally dropped support for the concrete type here in RC2 because IFormFeature is replaceable.

@fhnainia
Copy link
Author

That did it. Thanks.

@pranavkm
Copy link
Contributor

pranavkm commented Jun 22, 2016

@rynowak - does the exception message include the type that couldn't be constructed? If not, should we modify places where we call CreateInstance to try-catch and explicitly call out the object type?

@rynowak
Copy link
Member

rynowak commented Jun 22, 2016

We should also consider handling this within the provider. Then you'd get an error about "could not create a model binder for type foo". We don't need to do anything fancy, just have the complex type binder check for a no-arg constructor.

@rynowak
Copy link
Member

rynowak commented Jun 22, 2016

@fhnainia glad we could help. Let's keep the bug open for now to track and improvement in the experience when this happens.

@Eilon Eilon added this to the 1.0.1 milestone Jun 22, 2016
@rynowak
Copy link
Member

rynowak commented Sep 1, 2016

@kichalla - please discuss with me and @dougbu before starting

kichalla added a commit that referenced this issue Oct 5, 2016
…FormCollection model type.

[Fixes #4895] No parameterless Constructor defined
kichalla added a commit that referenced this issue Oct 7, 2016
…FormCollection model type.

[Fixes #4895] No parameterless Constructor defined
kichalla added a commit that referenced this issue Oct 8, 2016
…FormCollection model type.

[Fixes #4895] No parameterless Constructor defined
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants