Project A has a dependeny on Project B.
Project B has model class
If you try to run scaffolding on Project A by using model class from Project B, it fails with the below error:
No model type returned for type: <class name>

Related #249 #140
TFS Bug#232614
I honestly do not understand how this bug wasn't detected before RC.
It's so common (and recommended) to put the POCOs in a different DLL.
Something is wrong here.
I hope you're aware that scaffolding doesn't work at all unless the project is a demo one with a single assembly.
Is this ever going to get fixed?
Hi @DamianEdwards, @shanselman
(At least) since RC the scaffolding doesn't seem to work if the entities are in a different project.
That's not an exceptional scenario, every real project has its models/entities classes in a different assembly.
Is someone taking care of it? I tried with the latest bits (1.0.0-preview3-003180) and it still happening.
I counted at least 3 issues in this repo of this bug, and they are all opened without an answer of its status.
Thanks.
@prafullbhosale opened this issue and he owns the scaffolding code in VS. We plan to add the support in future version of VS "15".
/cc @mlorbetske
That's ridiculous.
How much time does it take to fix it?
It's not working at least since December!
At least release a hotfix for this.
Ridiculous.
@prafullbhosale is this Issue already fixed. If yes, can i get solution. If not, when are we expecting it to be closed.
@RupeshY, this issue is fixed in the Dev branch.
And when will be released?
Approved for 1.0.0-preview2-update1.
i am using v1.1.0 and this issue is still there
@Vikaskumargd can you provide the project.json for your projects?
{
"userSecretsId": "aspnet-TSMS-c87dcdb9-804d-4386-b2bd-d6f626645626",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"TSMS.Entities": "1.0.0-*",
"BundlerMinifier.Core": "2.2.306",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
"Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Routing": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
"NETStandard.Library": "1.6.1",
"TSMS.Service.Interfaces": "1.0.0-*",
"TSMS.ViewModels": "1.0.0-*",
"TSMS.Repositories.Interfaces": "1.0.0-*",
"TSMS.Repositories": "1.0.0-*",
"Microsoft.DotNet.InternalAbstractions": "1.0.1-beta-003206"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.1.0-preview4-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": ["bower install", "dotnet bundle"],
"postpublish": ["dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"]
}
}
@prafullbhosale above json is from project.json of Main project
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"NETStandard.Library": "1.6.1",
"System.ComponentModel.Annotations": "4.3.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
@prafullbhosale and this one is from my entities project
also this is my project repo :- TSMS
can anyone please help me on this ?
@Vikaskumargd I was able to scaffold a controller below.
C:\git\tsms\src\TSMS (master)
位 dotnet aspnet-codegenerator -p . controller -name HelloController -m TSMS.Entities.hello -dc TSMS.Data.HelloContext -nv
Building project ...
Finding the generator 'controller'...
Running the generator 'controller'...
Generating a new DbContext class TSMS.Data.HelloContext
Attempting to compile the application in memory with the added DbContext
Attempting to figure out the EntityFramework metadata for the model and DbContext: hello
info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
User profile is available. Using 'C:\Users\prbhosal\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Added DbContext : \Data\HelloContext.cs
Added Controller : \HelloController.cs
RunTime 00:00:05.84
Can you share the command line and the error that you are getting?
@prafullbhosale currently i am using visual studio 2015 update 3 and trying to create Views by right click on Views folder and i will send you error after 6 PM UTC.

@Vikaskumargd The commandline and more detailed output should be available in the output window.
Looking at the error, it looks like scaffolding tried to edit the DbContext (I am assuming you used ApplicationDbContext) and failed. The edit to add a DbSet<> property to the DbContext if it doesn't exist, but in your case it looks like the ApplicationDbContext already contains properties for Pricing and Delivery, so it should not try to do that.
I will look more into it now that I know the repro steps.
Thanks @prafullbhosale
the output :-
C:\Program Files\dotnet\dotnet.exe aspnet-codegenerator --project "E:\New Projects\TSMS\src\TSMS" view View Create --model TSMS.Entities.Pricing --force --dataContext TSMS.Entities.ApplicationDbContext --referenceScriptLibraries --relativeFolderPath Views --useDefaultLayout
Building project ...
Finding the generator 'view'...
Running the generator 'view'...
Attempting to compile the application in memory
There was an error creating/modifying a DbContext, there was no type returned after compiling the new assembly successfully
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:16.61
Thanks @Vikaskumargd, The problem is with the DbContext being in the library, not the model classes.
The DbContext in libraries isn't supported fully because editing it is not possible, however, it is possible to make it work if no edits are needed.
I have filed https://github.com/aspnet/Scaffolding/issues/365 to enable this scenario.
As a workaround for now, you can try to move the DbContext to the main project.
Thanks a lot @prafullbhosale it works like a charm 馃憤 馃憤 .
So what I get is that the main project is not have enough permissions to edit the files of other class libraries or something like that. Is this correct?
the main project is not have enough permissions to edit the files of other class libraries
Well to put it in a clearer way, scaffolding treats classes from all dependencies of the main project as non-editable, as the sources are not really part of the project.
Ok but i am getting a issue when i moved ApplicationDbContext file in main project .Its dependent projects give me an error of reference not found and when i referenced project using Add Reference it gives me error of circular reference .
July 2017 and still the same issue. Not being able to scaffold when my model and my dbcontext are in separate libraries. Is there any plan to have this fixed for V2 release in September?
Still, exists.
Still exists...
Still exists.
still not fixed :(
still not fixed...
This is still happening.
Still exists
I was able to resolve the issue by following the steps listed here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app-xplat/adding-model?view=aspnetcore-2.1#prepare-the-project-for-scaffolding
It seems to work if the model in the class library is public. The scaffolder does not generate code if the public keyword is absent.
Most helpful comment
Still, exists.