23

I’ve created a new C# asp.net mvc 4.0 (beta) Internet Application and I’m having a somewhat odd behavior in the Add View dialog in Visual Studio 2010 (sp1). When I decide to create a strongly-typed View, inside the Add View dialog, the Model class dropdown does not show my ViewModel class.

For the record, yes I did compile the application before triggering the Add View dialog.

I believe I have pinpointed the issue but do not know how to fix it. Below are the repro-steps if anyone cares to reproduce the behavior:

  1. In Visual Studio 2010 (sp1), create a new C# asp.net MVC 4.0 (beta) Internet Application.
  2. Inside the Models folder, create a new simple class called “GazouViewModel.cs”
  3. Build the application, open the HomeController, right-click the Index() ActionResult and select Add View…
  4. In the Add View dialog, check the “strongly-typed view” checkbox and in the Model class: dropdown, you’ll notice your “GazouViewModel”

  1. In Solution Explorer, right-click your project and select “Manage NuGet Packages”
  2. Search, find and install the “Bootstrapper.Autofac” package.
  3. Rebuild the application and verify if your “GazouViewModel” still displays inside the Add View dropdown’s dialog.
  4. The “GazouViewModel” should still be displaying in the dropdown.

  1. In Solution Explorer, right-click your project and select “Manage NuGet Packages”
  2. Search, find and install the “Autofac ASP.NET MVC4 (Beta) Integration” package.
  3. Rebuild the application and verify if your “GazouViewModel” still displays inside the Add View dropdown’s dialog.
  4. The “GazouViewModel” should still be displaying in the dropdown.

  1. In Solution Explorer, right-click your project and ADD a new class (Class1.cs) anywhere it doesn’t matter.
  2. Make that Class1 implement IAutofacRegistration and implement the interface.
  3. Rebuild the application and verify if your “GazouViewModel” still displays inside the Add View dropdown’s dialog.
  4. The “GazouViewModel” is no longer showing inside the Model class dropdown.

It appears that as soon as I create a class that implements the IAutofacRegistration interface and build the application, I’m no longer capable of viewing my ViewModels in that dropdown.

Can anyone confirm if they are getting the same results as me? And more importantly, how can one fix this?

IMPORTANT: I have tried the exact same steps with an mvc 3.0 application and the exact same behavior occurs…so this is not relevant to the BETA version.

Sincerely Vince

Vlince
  • 5,885
  • 7
  • 45
  • 62
  • If someone else can repro I'll investigate. Ping me when you get confirmation. – RickAndMSFT Mar 12 '12 at 14:54
  • I can reproduce. VS2010 SP1. MVC4 Beta. Clean install. If I comment the IAutofacRegistration implementation, suddenly it starts working. Very weird. – Maxime Rouiller Mar 12 '12 at 17:02
  • Same here, I am experiencing the same issue while reproducing those steps. I think this is a plot against the usage of the very powerful Autofac module combined with Bootstrapper (or probably not, who knows ^^) – Flo. Mar 13 '12 at 14:15
  • I'm also experiencing the same behaviors! I also get the message:"Running transformation: The input file appears to be using a schema version not supported by this template. This may lead to compile errors. Please use 'Add New Generated Item' to add an updated template" – GRGodoi Apr 04 '12 at 18:20
  • You mention it doesn't show in the dropdown, but if you make the view manually and assign it to the model manually does it still work? – Roger Apr 27 '12 at 00:22
  • Yes, if I create the View manually and manually strongly type it, it works. The reason I wanted to use the dialog is that it would auto-magically create all the fields and what not. In addition, if I created my own T4 templates which I’d like to use from the dialog, I can’t. I realize this is not a show stopper and there is a workaround. – Vlince May 01 '12 at 13:20
  • I had same problem. Check for all Nuget Package versions. Before creating new project update all. I did the same and created new project. and it worked – Angry Coder May 12 '22 at 21:51

9 Answers9

15

If you get error message: "Running transformation: The input file appears to be using a schema version not supported by this template. This may lead to compile errors. Please use 'Add New Generated Item' to add an updated template".

You are used EF 5.x. You have to add metadata for EF 5.x to your T4 template. In file header call DefineMetadata()

<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ include file="EF.Utility.CS.ttinclude"#><#@ output extension=".cs"#><#

DefineMetadata();

at the bottom of your template create method

private void DefineMetadata()
{
    TemplateMetadata[MetadataConstants.TT_TEMPLATE_NAME] = "CSharpDbContext.Types";
    TemplateMetadata[MetadataConstants.TT_TEMPLATE_VERSION] = "5.0";
    TemplateMetadata[MetadataConstants.TT_MINIMUM_ENTITY_FRAMEWORK_VERSION] = "5.0";
}
user1583948
  • 151
  • 1
  • 3
9

I solved this issue by beeing mad in like 2 hours and then deleting the Assembly.cs from the Properties-folder in the solution. After I made a rebuild of the solution, the "Add-view" model-dropdown suddently could find all my ViewModels, strange enough.

I guess the assembly version defined in Assembly.cs somehow got mixed up with the actual version used in the project. Anyhow, it works now for my case.

Simon Sessingø
  • 335
  • 2
  • 10
  • I haven’t tried your solution simply because I can no longer reproduce the error most likely due to the fact that the NuGet packages have been updated…but thank you for sharing your findings. – Vlince May 01 '12 at 13:37
  • 4
    Just rebuilding worked perfectly for me, no need to delete the Assembly.cs! – Tim Ferrell Jul 06 '12 at 19:40
  • Just ran into this problem as well, and a rebuild worked for me (Visual Studio 2012 Ultimate) – qrazi Oct 02 '12 at 20:47
  • Your solution worked for me(in VS 2012 ultimate) perfectly . I rebuild the program, but that did not solve the issue. When I delete the assembly.cs and rebuild the solution, then it worked. – Pankouri Apr 16 '13 at 14:50
  • Worked for me in VS2010. Removed AssemblyInfo.cs, and set the properties on the project again. – Parag Doke Apr 17 '13 at 05:12
  • Yeah.. its working correct.. i have removed all the data in assembly.cs file. after i made a rebuild of the solution. – BasK Jun 05 '15 at 07:23
  • I want to use model from another class libraby in my view.But I cannot find it in model class dropdown while creating view. I tried removing AssemblyInfo.cs, but it did not work. – RSB Apr 28 '17 at 10:44
3

What worked for me was to simply build the solution after creating my model. Then I was able to find my model in the dropdownlist.

2

I've noticed this issue as well (using MVC 4 Beta on Visual Studio 2010). Re-starting Visual Studio solved the problem for me.

Ivan Karajas
  • 1,081
  • 8
  • 14
2

Just another solution to add to the pile as none of the other ones worked for me. This is another example of Visual Studio being terrible at handling long file paths and namespaces.

In my case the namespace was too long to display in the "Model class" dropdown. Shortening the namespace (a ridiculous pain in of itself) made the drop down work again!

Gerard Wilkinson
  • 1,512
  • 14
  • 33
  • Another possible solution, which even works when the model is in a dependency instead of the project itself: Create a subclass, (in your case, in a shorter namespace); once the view is created, you can easily change the `@model` declaration to point to the parent class, and delete the subclass --- or not. – jpaugh May 09 '17 at 19:50
1

UPDATE: As of this writing, I can no longer reproduce the error. Perhaps the NuGet packages I use have been updated to a newer version and incidentally fixed the error.

I will mark this post as closed.

Thanks for everyone’s input on this!

Vince

Vlince
  • 5,885
  • 7
  • 45
  • 62
1

Just Clean and build your solution. It worked for me.

0

Using VS 2010 and MVC 3.0, at one point the Add View Model class dropdown was not showing any classes for me. Ivan's suggestion of restarting VS appeared to work for me.

I tried deleting AssemblyInfo.cs, did a Clean, and a Rebuild, but those didn't resolve the issue. When I restarted VS, the model classes were back in the dropdown.

Jayce
  • 11
  • 2
0

I realize this is a bit out of date. I had a similar situation where my classes wouldn't load into the View Template wizard. I'm using VS 2012 with MVC3. Everyone else in the team was OK, just luckily old me had issues. After much research and trying lots of things the only thing that has consistently fixed it is running VS in safemode (from the command prompt: "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /safemode). One of my extensions must be causing the issue and by running in Safe Mode those aren't loaded.

Craig B
  • 333
  • 5
  • 8
  • Gave this a try, but it disabled the Entity Framework scaffolding that I was using to enumerate the models in the first place. Live and learn. I appreciate the tip though. I keep forgetting that VS even has a Safe Mode. – jsuddsjr Feb 25 '15 at 23:11