Forest controller does not work with Visual Studio 2013 2 update

Problem:

I updated the update for Visual Studio 2013 2, and now I can not control the controllers.

The problem is not related to a specific project: when I try to raise the controller, I get the following error in ALL and ANY projects:

There was an error running the selected code generator: 'Exception has been thrown by the target of an invocation.' 

It worked before upgrading to the upgrade version for Visual Studio 2013 2.

Guessed the problem to death, but none of the various suggestions work

For example:

  • Commenting OnModelCreating in my context;

  • Removing packages such as MvcScaffolding, etc. (I do not have installed and it does not work with ANY project);

I changed / configured some of the templates, but it worked after the changes.

EDIT:

I uninstalled Visual Studio 2013 Update 2 and thus returned to Visual Studio version 12.0.21005.1 REL.

The problem is gone. Therefore, the problem is most definitely with Update 2.

Question:

Does anyone (including Microsoft) know about the fix?

EDIT 2:

Farruk Subhani's answer does not address the question: the question clearly states that removing links to MVCScaffolding does not solve the problem.

I added 200 points, please ask a question, as clearly stated.

+64
visual-studio-2013 asp.net-mvc-5 asp.net-mvc-scaffolding
May 28 '14 at 11:17
source share
16 answers

A combination of things worked for me:

  • Update to version 5.0 for Visual Studio 3.

  • Upgrading Entity Framework to 6.1.1

  • Change the context configuration to use IDbSet <...> instead of DbSet <...> (I heard that this could affect the use of asynchronous actions, but apparently not in my case, since I use this in my actions login, etc., as supplied by the Nuget package for the ASP.NET Identity sample 2).

Quite why this combination works, I have no idea. But then, given the rumbling silence from MS, I'm probably not alone. I think update 2 just didn't work ...

+12
Oct 29 '14 at 2:03
source share

Hey, for all of you that nothing works, the real answer is: you need to remove NOTHING that has configSource on web.config, and the connection string should be inline.

EDIT:

Someone noted that it should only be <configSettings> , <appSettings> and <connectionStrings> NOT tags using the configSource attribute. And that he could still use the configSource attributes elsewhere, like a rewrite tag.

I think the toolkit cannot follow configSource locations for what it uses as connection strings and application settings.

Microsoft should be in this problem, if it has not yet been fixed.

EDIT 2:

Even @awrigley’s thoughts marked his answer as correct, this is a known Visual Studio bug. I managed to say this, and I think that soon it will attract attention. https://github.com/aspnet/Tooling/issues/169#issuecomment-144197015

+35
Oct 07 '14 at 10:47
source share

Please run the following command in the Package Manager Console :

 Uninstall-Package EntityFramework -Force Install-Package EntityFramework Uninstall-Package MvcScaffolding Install-Package MvcScaffolding 
+4
Mar 04 '15 at 20:11
source share

I had the same issue with Visual Studio 2013 Update 3, but only for forests running with Entity Framework. This issue appears to be caused by incompatibility between Entity Framework 6.1.0 and file systems in Visual Studio 2013 Update 2 and later.

Follow these steps to upgrade EF:

Uninstall-Package EntityFramework -Force

Install-Package EntityFramework

This answer is borrowed from here.

After the upgrade, the forests work fine for me. Be sure to install the new version in every project that requires the Entity Framework.

+3
03 Oct '14 at 8:54
source share

Decision

Make sure the section

 <connectionStrings>..</connectionStrings> 

after

 <configSections>..</configSections> 
+3
Oct 03 '16 at 16:27
source share

n In my case, I solved the problem with the connection string in the web.config file.

Prevents the problem I have

  <connectionStrings configSource="Configs\ConnectionString.config"/> 

and I don't know why, but vs can not connects to the database and fails.

after change

 <connectionStrings> <add name="UIBuilderContext" connectionString="metadata=res:/ ..... " /> </connectionStrings> 

and he works

+2
Aug 05 '14 at 21:40
source share

This can be useful for people who have not installed scaffolding nuget packages in their solution.

In fact, I do not have mvcscaffolding or t4scaffolding installed and received the same error message.

In my case, the problem / error was caused by a change in the connection string.

Here I had / steps to play.

  • Installed version of Visual Studio 2013 Community Edition
  • Created MVC Project
  • First model generated code
  • Edited connection string for connecting to a real server, for example:

     <add name="DefaultConnection" connectionString="server=myserv;database=MyCustomerDB;user id=myuser;password=mypass" providerName="System.Data.SqlClient" /> 

Then I turned on migrations via nuget, for example:

  • Enable Migration
  • Add-Migration InitialCreate
  • Update database
  • I started a website and I could register a user. All tables were created correctly.

Then I created the controller using the scaffolding option:

  • right-click on "Controllers"> "Add"> "Controller" ...> MVC 5 Controller with Views using Entity Framework> my selected context and the class to be used. It worked.

Then I decided to make more code changes and start from scratch:

  • I changed the connection string as follows: localdb :

     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Test-20141126094523.mdf;Initial Catalog=aspnet-Test-20141126094523;Integrated Security=True" providerName="System.Data.SqlClient" /> 

Then I continued:

  • transfer folder deleted
  • redirected migrations using the same commands as above in the nuget console
  • launched a website and registered a user
  • checked mdf db. All tables are there, so the connection string works.
  • right click on Controllers> Add> Controller ...> MVC 5 Controller with Views using Entity Framework. I chose my context and the class to be used. This did not work, and this pop-up error appeared:

An error occurred while starting the selected code generator: 'An exception has been thrown to the target.'

DECISION:

After some investigation, what I did is changing the connection string in web.config to the initial one on the "real server" (instead of localdb). I tried again to create a controller with views. It worked!

So, it seems to me the problem with the link string / error or the localdb problem ... I can not explain it. Maybe Visual Studio doesn't like what I did, I had to save my old connection string ...

In any case, now that I need scaffolding, I just change the connection string to the one that works. Then, to test my site, I will put it back in localdb.

+2
Nov 26 '14 at
source share

For me, I had to provide <configSettings> , <appSettings> and <connectionStrings> tags NOT with the configSource attribute.

I could still use the configSource else attributes, where, for example, the rewriter tag.

+2
Apr 02 '15 at 8:51
source share

I think the problem is due to poor configuration in the web.config file.

In my case, I had several <entityFramework> in the web.config file, and the problem was solved after I changed the settings.

+2
May 08 '15 at 3:43
source share

I am in VS 2013 Update 4 and have exactly the same problem. It works for me when moving the connection string from an external file to web.config. Therefore, I think you could try not to use the configureSource attribute for connectionString when creating forests.

My web.config before and after changing Before:

 <connectionStrings configureSource="connectionStrings.config/> 

After:

 <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" /> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net configSource="log4net.config" /> <connectionStrings> <clear/> <add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=YourDb;Integrated Security=False;User ID=sa;Password=YourPassword!#;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> </connectionStrings> 
+2
Jun 19 '15 at 3:26
source share

I performed the following steps to solve this problem:

  • In the package manager, check if there is MVCScffolding or T4Scaffolding (main or preliminary release for vs2013)
  • Remove any packaged ones that depend on either MVCScaffolding or T4Scaffolding
  • Copy the full CopyTemplates folder (do not replace your own templates, but make sure that you have the rest of the files from the root directory of this folder. I assume that you did this part because you configured some templates so that you know where this folder is)
  • Build your project and close it.
  • Restart Visual Studio in Admin Mode
  • Open the package manager console (it should not have any errors, and you can see PM> without errors.
  • Right-click on the Controller folder and select Add-> New Scaffolding Item or select Add-> Controller, and you should ask which one you want, and then select the MVC5 stand or ever displayed in the list.
  • Then you can choose your options if its controller may need to select a DBContext or repository, etc.

This created a controller for me and the corresponding looks.

I added a custom partial QuickView to this folder, however, this procedure for creating forests did not take this into account and only the generated views that it did by default. I'm not sure if you need to add these custom views to a file to tell Scaffolder to also create them.

+1
Jun 10 '14 at 20:23
source share

I will explain here a little more in English, so everyone can understand. Hope this helps someone out there. This is because Visual Studio cannot connect to the database model.

This happens when you change the name and / or path in a class that extends DbContext and does not change it in the Web.config file (in the outermost part of your project: root).

Example:

Imagine that you pinned DbContext code:

a) You right-click on a folder in your project and add "ADO.NET Entity Data Model" and you name it "Model1"

You will receive the following code:

  public class Model1 : DbContext { // Your context has been configured to use a 'Model1' connection string from your application // configuration file (App.config or Web.config). By default, this connection string targets the // 'Skelleton.Models.Model1' database on your LocalDb instance. // // If you wish to target a different database and/or database provider, modify the 'Model1' // connection string in the application configuration file. public Model1() : base("name=Model1") { } // Add a DbSet for each entity type that you want to include in your model. For more information // on configuring and using a Code First model, see http://go.microsoft.com/fwlink/?LinkId=390109. // public virtual DbSet<MyEntity> MyEntities { get; set; } } 

enter image description here

b) Now you decide that the name you just wrote is just bad, so you change it to AppContext

Your code now looks like this:

  public class AppContext : DbContext { // Your context has been configured to use a 'AppContext' connection string from your application // configuration file (App.config or Web.config). By default, this connection string targets the // 'Skelleton.Models.AppContext' database on your LocalDb instance. // // If you wish to target a different database and/or database provider, modify the 'AppContext' // connection string in the application configuration file. public AppContext() : base("name=AppContext") { } // Add a DbSet for each entity type that you want to include in your model. For more information // on configuring and using a Code First model, see http://go.microsoft.com/fwlink/?LinkId=390109. // public virtual DbSet<MyEntity> MyEntities { get; set; } } 

enter image description here

Then you try to fake CRUD (create, read, update, delete) operations with representations, and it won’t work!

enter image description here

Why?

Well, if we go to the web.config file, we will see the following line:

  <add name="Model1" connectionString="data source=(LocalDb)\v11.0;initial catalog=Skelleton.Models.Model1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /> 

(This line is usually below <add name="DefaultConnection" )

enter image description here And there is a problem. You need to change Model1 for the name you gave out!

In this case, he should say "AppContext" instead of "Model1"

And where he says:

 initial catalog=Skelleton.Models.Model1; 

Make sure that:

  • This is the name of the .cs file that has the class

  • The namespace (or series of names (separated by periods) that precedes the name of your class) is correct. It is important to note that you are not adding the extension ".cs"; just the name of your file.

It should look like this: enter image description here

Since I changed the class name, both inside and outside (inside it and its name), and did not change its location, I just rename it to AppContext

After that. You can scaffold normally;)

Hope this helps!

+1
05 Feb '15 at 21:01
source share

It worked for me to make sure that the <configSections> node in the web.config file was the first node right after the <configuration> node.

Initially, when I added my connectionStrings , I actually placed it in front of configSections , which caused the Scaffold tool to break.

It looks like when scaffolding starts up and tries to get connection information, he expects that the configuration section for entityFramework node already exists, so he knows which database provider to use, but when I had the connection string in front of the configuration sections, he did not know how to use LocalDB (this is what I used in the connection string).

0
Dec 10 '14 at 19:50
source share

I had the same problem in Update 4. I found that the problem came from <configSections></configSections> that does not have a section name. The fix I installed between the tags is this: all errors have been fixed:

 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 

Build a project and everything should work. Hurrah!

0
May 04 '15 at 18:26
source share

I launch VS 2015RC last before the final cut. Do not discount any solutions here. My solution was related to the nugget package manager and updated my Microsoft.Aspnet.Mvc 5.2.3 package and fixed my problem. I hope this helps anyone using VS 2015.

0
Jul 21 '15 at 12:36
source share

I used the initializer, and when the remove / comment initializer is from the myDbContext constructor, the scaffolds work fine

 public myDbContext () : base("name=DefaultConnection") { //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DastanakDbContext>()); //Database.Initialize(true); } 
0
Feb 13 '17 at 14:09
source share



All Articles