Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Lost on how TO Work Around Multiple constructors accepting all given argument types have been found in type

$
0
0

I have a form accepting inputs and allowing an upload for a file.

In code I have:

public class ClientsController : Controller
    {
        private readonly Eva804Context _context;

        static public IHostingEnvironment _environment;

        public ClientsController(IHostingEnvironment environment)
        {
            _environment = environment;
        }
................ blah, blah, blah...................Then

 model.ShentonAcc = viewModel.ShentonAcc;
                    model.Suburb = viewModel.Suburb;

                    if(fmodel != null)
                    {
                        fmodel.DocTypeID = fmodel.DocTypeID;

                        var uploads = Path.Combine(_environment.WebRootPath, "FileName");

                        foreach (var file in FileName)
                        {
                            if (file.Length > 0)
                            {
                                using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
                                {
                                    await file.CopyToAsync(fileStream);
                                }
                            }
                        }

                        fmodel.FileName = uploads;


                    }

After mucking about I realise the issue is with Path.Combine(_environment.WebRootPath as the examples I have all declare IHostingEnvironment as a DI.  This conflicts with the existing DI.  

All okay sort of, until I try and find a replacement for the Path.Combine that doesn't require DI.  What should I be looking for?  Is there a work around for this?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>