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

[.netcore 2 preview 2] ifileprovider + di error #6479

Closed
AerisG222 opened this issue Jul 2, 2017 · 3 comments
Closed

[.netcore 2 preview 2] ifileprovider + di error #6479

AerisG222 opened this issue Jul 2, 2017 · 3 comments

Comments

@AerisG222
Copy link

After upgrading to the latest preview release, I am now seeing the following error when starting up the application (via dotnet run):

System.InvalidOperationException: Unable to activate type 'Microsoft.AspNetCore.Mvc.Razor.Internal.FileProviderRazorProject'. The following constructors are ambigious:
Void .ctor(Microsoft.AspNetCore.Mvc.Razor.Internal.IRazorViewEngineFileProviderAccessor)
Void .ctor(Microsoft.Extensions.FileProviders.IFileProvider)

My application registers its own IFileProvider as part of startup, like this (also suggested here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/file-providers):

.AddSingleton(x => new PhysicalFileProvider(_config["Environment:AssetsPath"]))

If I comment out this line, then everything starts normally, but of course the functionality depending on this does not work.

Should this still work as before?

-- dotnet info:
.NET Command Line Tools (2.0.0-preview2-006497)

Product Information:
Version: 2.0.0-preview2-006497
Commit SHA-1 hash: 06a2093335

Runtime Environment:
OS Name: fedora
OS Version: 25
OS Platform: Linux
RID: fedora.25-x64
Base Path: /opt/dotnet/sdk/2.0.0-preview2-006497/

Microsoft .NET Core Shared Framework Host

Version : 2.0.0-preview2-25407-01
Build : 40c565230930ead58a50719c0ec799df77bddee9

@rynowak
Copy link
Member

rynowak commented Jul 2, 2017

Thanks for this report. FileProviderRazorProject is a infrastructure type for the view engine, and it has two constructors - the IFileProvider constructor is used for our unit tests. We intend the IRazorViewEngineFileProviderAccessor to be used in product scenarios.

We didn't anticipate this, but it looks like something we'll need to fix in 2.0.0.

For now if you want a workaround, for preview 2 you can add the following to your ConfigureServices

services.AddSingleton<RazorProject>(s => 
{
    return new FileProviderRazorProject(s.GetRequiredService<IRazorViewEngineFileProviderAccessor>());
});

@rynowak rynowak self-assigned this Jul 2, 2017
@rynowak rynowak added this to the 2.0.0 milestone Jul 2, 2017
rynowak added a commit that referenced this issue Jul 2, 2017
The RazorProject implementation used by MVC at runtime has a constructor
that takes an IFileProvider (used by tests). This causes ambiguities
when a user registers an IFileProvider in DI.

Cleaning up tests to use a mock instead of the file provider directly
@Eilon Eilon added the 1 - Ready label Jul 3, 2017
@rynowak rynowak closed this as completed in 8d9c161 Jul 4, 2017
@rynowak
Copy link
Member

rynowak commented Jul 4, 2017

This is fixed now for 2.0.0 final, thanks again @AerisG222 for the report

@rynowak rynowak added 3 - Done and removed 1 - Ready labels Jul 4, 2017
@AerisG222
Copy link
Author

Thanks!

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

3 participants