3

I am trying to upload a file to MVC 6 application using following code.

public void UploadFile(IEnumerable<IFormFile> files)
{
    foreach (var file in files)
    {
        var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
        using (var reader = new StreamReader(file.OpenReadStream()))
        {
            var fileContent = reader.ReadToEnd();
            var Filename = parsedContentDisposition.FileName;

        }
    }
}

I am getting following error. Any help please? I am not sure how to resolve this. i have tried all latest versions of Microsoft.AspNet.StaticFiles as well.

System.TypeLoadException
Method 'get_WebRootFileSystem' in type 'Microsoft.AspNet.Hosting.HostingEnvironment' from assembly 'Microsoft.AspNet.Hosting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
at Microsoft.Framework.DependencyInjection.HostingServicesExtensions.AddHosting(IServiceCollection services, IConfiguration configuration) 
at Microsoft.AspNet.Hosting.HostingServices.Create(IServiceProvider fallbackServices, IConfiguration configuration) 
at Microsoft.AspNet.Loader.IIS.KlrHttpApplication.ApplicationStart(IHttpApplication application) 
at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.InvokeApplicationStart(IHttpApplication application)

2 Answers 2

1

This is mostly sure because of a mismatch between the package versions, or package versions and runtime version. I would bet on the former.

Check the following:

  1. The application uses the same versions for all packages (e.g all of them end with Beta2). You can see this in the project's references node in VS.
  2. The runtime is from the same release (e.g Beta2). You can check this by right clicking the project -> Properties and look at the runtime version.

If none of these work, please post here the project.json file of your project and the output of the RuntimeInfo middleware which will show exactly what packages are loaded.

1
  • I'm getting this problem too, and versions do match. I got the Mvc 6.0.0-beta2 using git (also as a zip neither worked).
    – Ciantic
    Feb 15, 2015 at 15:02
0

Be sure all your packages and KRE runtime targets the same beta version and kill all your running Application Server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.