5

Summary: When creating a new Web Project in Visual Studio 2015 (Update 1), im unable to use the scaffolding tool for Controllers that relates to Entity Framework.

Same issue occures with VS2013 Update 5

It returns the following message:

There was an error running the selected code generator:
There was an error getting the type "failtest.Models.TestModelClass".
Try rebuilding the project.

I have tried to rebuild it, but still nothing.

Anyone got a clue about why im getting this? I actually re-installed my Windows 10 system to see if this could fix this error. - Now, that beeing said, it was in need for some tough love anyway, so i figgured it was about time - Maybe its crashing because i have tried a vast amount of node stuff in the past time, and permission errors. But the error occured both before and after i re-installed it. (complete whipe)

This is a Fresh install of Visual Studio 2015 Professional - Basically nothing else has been added to the system yet.

When i first started this post, i created a blank project for my screenshots just to show the entire process (below) - And i tought i was loosing my mind.

At first, the testproject suddenly worked, so i created a second project to test again. And then it failed with the same error. So just to confirm, i deleted the first project that worked, and set it up again with the exact same name and file location as the one that suddenly worked ( after deleting all folders and existing project files ) - And now it keeps failing again.

How to reproduce:

  1. Create a new "Azure Api App" project - Leave all settings as default (Any project type will produce the same result actually)

New Project

  1. Create a new Model

Model

  1. Build your project (this is mentioned on an article from Microsoft to be nesesary to use the scaffolder)

  2. Add a new Controller by right clicking the "Controllers" folder, and selecting New -> Controller - Select "Web Api 2.0 controller with actions, using Entity Framework"

Add Controller

  1. Fill out the information, since this is a new project, we dont have a context - so click the + icon and create a new one.

Fill out information

  1. Error is produced

Error

EDIT:

Packages.config :

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
  <package id="Swashbuckle" version="5.3.1" targetFramework="net452" />
  <package id="Swashbuckle.Core" version="5.3.1" targetFramework="net452" />
  <package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net452" />
  <package id="WebActivatorEx" version="2.1.0" targetFramework="net452" />
</packages>

Web.Config :

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301879
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings></appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

EDIT 2: I Suspect that this is an EntityFramework issue, as the scaffolder works for everything that doesnt include EntityFramework.

Already tested

  • Switch between Debug and Release config
  • Updated all packages and plugins
  • Verified the solution file and project XML
  • Verified Web.config
  • Deleted Bin / Debug folder
  • New project with different project types

Issues describing the same error - All tested

I also created an issue on this on the aspnet Github issue tracker. https://github.com/aspnet/Tooling/issues/411

And reported it to Microsoft trought the internal Feedback system in Visual Studio.

Community
  • 1
  • 1
Christer
  • 1,651
  • 1
  • 17
  • 34
  • 1
    Try changing configuration to "Release" / "Debug", rebuild, and try again – Catalin Feb 18 '16 at 09:28
  • @RaraituL: Tried your solution without any successfull result. – Christer Feb 18 '16 at 09:33
  • The first thing I'd do is making sure I'm running the latest version of the Azure plugins for VS. That things changes every few months and it's easy to run an outdated version. – MartijnK Feb 18 '16 at 10:36
  • @MartijnK - All plugins are up-to-date. Latest update to both VS and Azure SDK was downloaded yesterday. I also updated all nuget packages in the project to the latest version (packages listed in original question) - without any effect. – Christer Feb 18 '16 at 11:08
  • I'm getting this too, even for a regular green-field WebApi project. I wonder if it's something to do with recent updates or something? – DaveDev Feb 21 '16 at 10:45
  • Check this: http://stackoverflow.com/questions/23910162/scaffolding-controller-doesnt-work-with-visual-studio-2013-update-2 – ehh Feb 21 '16 at 12:07
  • @ehh i have previosly looked over that answer, (updated the tried solutions list) - As you can see in my walktrough on how to reproduce, i am trying to get the scaffolder to create the dbContext class for me, and this will also generate the connection string if the scaffolder completes. As you can see in my web.config theres no configSource, which the majority of the answers in that post says you should remove if it exists. Packages has also been updated. Its a blank project, so no renaming of existing models has been performed, which one of the answers suggest you verify. – Christer Feb 21 '16 at 12:27
  • @DaveDev, please let me know if you ever find a solution to this. :) – Christer Feb 21 '16 at 12:27
  • @Christer: I can't reproduce the problem. I can't of cause to reinstall my Windows 10 and Visual Studio 2015 Update 1 for the test only. I suppose that I have installed some additional components which you don't have. **Could you include the code of `failtestContext`, generated after clicking on "+" button?**. I reproduced the steps, which you described, without any problems. After that I updated NuGet packages to the latest version, but all still work. You can compile [the project](http://www.ok-soft-gmbh.com/ForStackOverflow/failtest.zip) on your computer and try to run. – Oleg Feb 21 '16 at 13:38
  • @oleg, thanks for checking it out. There is nothing beeing generated as the scaffolder fails to create both the controller and the failtestcontext. No files are beeing generated unfortunately. I can upload an entire solution if you want, just so that you can try to reproduce it with the same solution that is beeing generated by my VS2015 instance. – Christer Feb 21 '16 at 20:08
  • @oleg, i will also try with your project by tomorrow - thanks for including. Im just not by my computer atm. – Christer Feb 21 '16 at 20:10
  • @Christer: You are welcome! You can send me the link to your project. I suppose that the click on "+" button have created wrong `failtestContext` and it's the main your problem. You can create manually context in the form `public class FailtestContext : DbContext { public DbSet TestModelClasses { get; set; } }` and use it for the scaffolding. I hope it will work. In any way I'll try to help you to find a workaround for the problem. One more origin of the problem: I don't see `connectionStrings` in `web.config` with `(localdb)\MSSQLLocalDB`. Your project could clear some things. – Oleg Feb 21 '16 at 20:27
  • @oleg, doesnt seem like it has anything to do with the project itself. Tried your solution file, and still got the same issue. And yes, Web.config is missing connectionstring - This is added to the web.config by the scaffolder when you create a new DbContext, which doesnt work here. I have tried with a connectionstring as well. And i also tried with the dbContext you created in the project you sent. I appreciate the effort so far tho! – Christer Feb 22 '16 at 08:08
  • @Christer: It's interesting, that the working project can't be build and executed on your computer. It's clear that some important components or permission are missing. You can try to use [Process Monitor](https://technet.microsoft.com/en-us/sysinternals/bb896645) to see what do Visual Studio before it failed. Probably you will see some ACCESS DENIED error or missing assembly. – Oleg Feb 22 '16 at 08:39
  • @oleg, i can build and run it - no problem! Its just that i cant use the scaffolding tools that include Entity framework. The other scaffolders work fine. – Christer Feb 22 '16 at 08:41
  • @Christer: OK, then it's not so bad. Could you provide `failtestContext`, which generated your Visual Studio on click on "+"? Is it different from the same from my project? Do you tried to create just the context manually like `public class FailtestContext : DbContext { public DbSet TestModelClasses { get; set; } }` ant to try scaffolding *with the context*? – Oleg Feb 22 '16 at 08:46
  • @oleg, the scaffolder never creates the failtestContext, it fails before the files get generated. And yes, i tried with an already existing dbContext (the project you linked has an existing dbContext which i used) - Same error :( – Christer Feb 22 '16 at 08:51
  • @Christer: Which errors exactly? If you want solve the problem you should provides exact information. For example I asked you multiple times to post `failtestContext`, which creates your computer. You wanted to upload the project, which generates your Visual Studio. – Oleg Feb 22 '16 at 09:20
  • @oleg, if you look at my original post, its a detailed walk-trough of the steps leading up to the error message. theres a screenshot there which shows you the error message. You have asked me multiple times for ***failtestContext***, a file that i have replied that i do not have in my project. The reason for not having this file, is because visual studio ***never*** creates this file, because i get the error message that is displayed in the original post. IF i create this file manually, it looks just like you wrote it in your previous comments. Link to project: http://we.tl/NUkxjzYJs2 – Christer Feb 22 '16 at 09:32
  • @Christer: Sorry, but the project which you uploaded have another `Packages.config` as you posted before. It has no `Controllers\ValuesController.cs`, no `App_Start\SwaggerConfig.cs` and so on. Do you deleted some files`? In any way I can use scaffolding on my computer with your project too. – Oleg Feb 22 '16 at 10:12
  • @Christer: I recommend you to do the following: Verify that Azure SDK 2.8 for .NET is installed on your computer. Verify that `Microsoft.AspNet.Scaffolding.Mvc.5.0.dll` exist in `C:\Program Files\Microsoft SDKs\Azure` or `C:\Program Files (x86)\Microsoft SDKs\Azure`. Verify `C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Scaffolding\Templates\EntityFrameworkDBContextCodeGenerator\DbContext.cs.t4` and `C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.AspNet.Scaffolding.12.0\v4.0_14.0.0.0__b03f5f7f11d50a3a\Microsoft.AspNet.Scaffolding.12.0.dll` – Oleg Feb 22 '16 at 10:14
  • @Christer: It seems that [Azure 2.8.2.1 SDK](https://azure.microsoft.com/en-us/blog/announcing-azure-sdk-2-8-2-for-net/) is the current version of Azure SDK (Release date 16 Feb 2016). It can be downloaded from [here](http://go.microsoft.com/fwlink/?linkid=699285&clcid=0x409) – Oleg Feb 22 '16 at 10:25
  • @oleg, sorry for the late reply. Im missing the first .dll your mentioning ```Microsoft.AspNet.Scaffolding.Mvc.5.0.dll``` inside the Azure folder. other than that all is fine. The reason why the packages file is different. is because i re-installed VS, and deleted everything with it to try again without success. so i just uploaded a new project that produces the same result. i got the latest Azure SDK, so that shouldnt be the issue. – Christer Feb 22 '16 at 19:55

2 Answers2

0

Solution / problem found.

I am using Panda Antivirus - During this entire process, i have frequently checked to see if Panda reports any blocked files, threads or any threats to the system. and it didnt report anything - so i ruled out the antivirus to be the issue.

After reading another post regarding a different issue, i noticed that one of the solutions was to deactivate the antivirus, and run a repair. After trying everything else, i did just this.

And its working again. Finally. after ~ 20 days.

There doesnt seem to be a need to repair the installation, as activating the antivirus again, will produce the issue the next time you try to run the scaffolder.

Disabling the process monitor doesnt solve the issue, and adding all the folders to the exceptions folder of the AV would be way to much up-keep, so i will probably switch out my AV.

Hope this helps anyone else thats having this issue.

A big thanks to @oleg for trying to help me out here!

Christer
  • 1,651
  • 1
  • 17
  • 34
0

You can fix this through cli... By using scaffolding command. Before you do this make sure code generator available in your system if it is dot net core 3.1.1 go for the lower versions of code generator.

SaiPutta
  • 1
  • 2