Recently a large project I work on started having a problem with the Add View dialog. When clicking the Add Strongly-typed View checkbox, the spinner comes up the first time for about a second or two, and then the entire dialog just closes and disappears. If I open the dialog and click the button again, it just closes again quickly.
The project is using ASP.NET MVC 2, I have installed VS2010 SP1 and this problem occurs with or without the MVC3 tools update installed. It only happens with this project, and I have replicated the problem on 2 different development machines. If I create a new MVC2 or MVC3 project, this does not happen at all, nor do any other small to medium sized projects I have.
I can of create a regular view and change it to strongly typed by myself, so there is a workaround, but this is still pretty annoying. Any ideas what could be causing this or how to fix it?
Do you use version control? Make sure all the assemblies that your project depends on (i.e. referenced by the project itself or by its referenced assemblies) are in sync. I've just run into this (both "Add View" and "Add Controller" problems) after updating a bunch of projects from SVN and rebuilding some. The issue was fixed after I rebuilt several libraries that my MVC project depends on.
I had the same problem, and I could not open the Add->Controller dialog either as described here: Add Controller after recent tools update fails with dependency error. In my case, I had added models to my domain, but I had forgotten to add contexts for these new models; things like
public DbSet<Region> Regions { get; set; }
I had no error at compile time, and I was not using these models yes in the solution, so there was no error at run time either. I guess the problem can be anywhere though.
Related
I'm trying to update an old webpage that I had developed using MVC. Now I'm adding Razor Pages, but then Edit and Continue won't work anymore.
I can isolate/reproduce the problem in a minimal context. It seems to occur when there are files both in Pages and in Views, e.g. _ViewStart.cshtml.
Here is how to reproduce:
Create an ASP.NET Core Web App, .NET 5.0, No Authentication, no HTTPs, no Docker, enable Razor runtime compilation
Place a breakpoint in IndexModel constructor
Run App
When hitting the breakpoint, edit the code (just add a semicolon in the ctor), continue: code will compile and continue
Add new folder "Views"
Copy _ViewStart.cshtml from Pages to Views
Run App again
When hitting the breakpoint, edit the code (just add a semicolon in the ctor), continue, get message: "Edits were made to the code which cannot be applied while debugging"
I could probably work around the issue, but I'd rather try to understand why this happens.
This also happens when I add the Identity package and try to customize the pages, in which case I also need a double _ViewStart.cshtml...
Any ideas?
Using .Net Core, and Vidsual Studio Community 2015, on an MVC application, if while debugging I make a simple change on my view's HTML (let's say, add an H1) and hit F5 on the browser, I see the changes reflected.
But, if I make a simple change on a partial view's HTML inside that view, and hit F5 on the browser, nothing happens.
I have to start debugging again to see the changes reflected. Is really annoying and a huge time waster.
Any idea? Am I the only one?
Which version of .NET Core MVC are you using? Currently I'm targeting 1.0.1 ( with new csproj ) and it works fine. Did you use IISExpress or cmd boostrap to run your application? Did you try to create a new proj and do that same on that?
I solved it. Weird, in my opinion, but I was including the view with the full path:
#Html.Partial("../Shared/_PartialViewName", Model)
I changed to:
#Html.Partial("_PartialViewName", Model)
And now everything works fine. Shame on you .Net Core. Shame on you.
I am having a Weird and annoying problem. In my ASP.NET MVC 5 project, time to time, I see that _ViewStart file and Shared/_Layout.cshtml files are created automatically even though I did not want. So, I deleted those files but these files are getting created time to time by itself. That cause a great problem because, sometimes, if I dont notice that these files are created, I can accidentally publish the website and then, after publish, I notice that all pages are being wrapped by the auto created _Layout.cshtml file. Is it a smart helping feature of Visual Studio 2013 ? Cant we stop this ?
Emran!
I am not sure that you still need the answer but today I have also met similar problem. By some unknown reason file "Shared/_Layout.cshtml" was automatically added to my Project.
I was realy wondering why could it happen and I found which actions should be performed to make this file be created.
I have added new View to my Project and have used for it standard VS resources:
Right mouse click on Views folder.
Add -> Veiw...
Inside window for adding view I have checked "Use a layout page" and have left field below empty.
Press Add
My VS was thinking a lot and suddenly created new view and also... "Shared/_Layout.cshtml" and "Shared/_ViewStart.cshtml" files!! I do not think that this option might be switched off because it is logically to create layout page when it has been missed.
Hope this info is helpful for you and for anybody else :)
First, let me explain what I have done:
I have installed the Visual Studio 2010 Feature Pack both on my local computer and on the TFS host.
The process is documented by Microsoft
I have a VS 2010 modeling solution with a component diagram.
I have created a work item of type Model (custom work item type).
I have created an association from a component in the component diagram, to the Model WI (using Link to Work Item)
The component diagram correctly links to the Model WI
The Model WI correctly contains a model link to the component in the component diagram
Problem: When I click the model link in the Model WI 'All links' tab, I get the following error:
Cannot find the linked model element. The corresponding diagram file or modeling project might have been renamed, moved, or deleted. To fix the link, click the Edit Link button in this work item to re-link the element
I tried to do exactly this, by re-selecting the component using the 'Select model element' dialog. The error is not resolved.
I tried to delete the link and re-create it by creating a new model link. The error is not resolved.
The link looks like this:
ModelLink: modelbus://ComponentDesignerAdapter.1.0/SystemComponentOverview/Architecture::ComponentName/$source control location/filename%comonent-guid
This works perfectly for another modeling project. The error only occurs in this specific modeling project, however it affects more than one component (I do not know if it affects all components in this project)
So my question is this. What could possibly cause this error?
Update: We just realized the error only occurs on my computer. When my colleague attempts to follow the link, the diagram opens correctly. I have tried 'Get latest version' from source control and restarting Visual Studio. Nothing has resolved the issue.
Update 2: I tried creating a new workspace, to no avail. At this point I am concidering re-installing Visual Studio, but I'll hold it off a day or so in case someone knows what might be causing this.
We have an application that has to be flexible in how it displays it's main form to the user - depending on the user, the form should be slightly different, maybe an extra button here or there, or some other nuance. In order to stop writing code to explicitly remove or add controls etc, I turned to visual inheritance to solve the problem - in what I thought was a neat, clean and logical OO style - turns out that half the time inherited forms have a hard time rendering themeselves in VS for no good reason etc - and I get the feeling that developers and to some extent Microsoft have shunned the practice of Visual Inheritance - can you confirm this, am I missing something here?
Regards.
I thought they had more or less sorted the desktop designer issues in 2005.
Have you tried the usual culprits?
No abstract control types
No constructor arguments in any form
Initialisation moved to Form_Load as opposed to the Ctor
No controls in the same project as the usercontrol/form that they are put inside
Close all documents -> Clean -> Rebuild
Restart VS
I seemed to think that as long as you did all of the above it worked..... mostly.
I am studying towards the (admittedly soon-to-be-obsoleted) MCAD, and part of the WinForms element was Visual Inheritence.
I personally have had no major problems with it, however, there are considerations to take in to account.
For me, the main problem has always initialization.. You need to remember that the designer cannot/does not instantiate forms in the same way it does at run time (similarly, it cannot do this with web dev, which is why care is needed with custom control rendering).
Also, once a form is changed, a complete re-build of the project is required in order to propagate the changes to the form to the child forms that inherit from it.
I personally have seen no evidence to suggest that it has been "shunned". AFAIK, its still good practice to exercise code re-use where possible. Visual inheritance provides that.
May I suggest creating a new question with the actual problems you are having, with sample code? We can then look at it to see if we can get it working and explain why :)
I've seen some problems in VS2005 with this. They were mostly due to problems with construction of the forms-objects in the designer. There were issues with code that tried to access the database from the form-constructors etc.
You can debug issues like this by starting a second instance of visual studio and loading up the first instance in the debugger. If you set breakpoints in your code you can then debug what happens in the designers in the first instance.
Another problem I can remember was generics in form classes
public class MyForm<MyObject> : Form
this won't work
I often stumble upon such problems in Visual Studio. In many cases MSVS forms designer fails to render form correctly. Back in the days I worked with WinForms I had to do all kind of weird tricks to enable some complex scenarios. However I think that using visual inheritance is very beneficial and should not be thrown away regardless of MSVS designer bugs.
I think I've found a way how to avoid this problem.
Don't hook the Form_Load Event in your parent form, this will break the designer.
Also don't take the Default empty constructor away from Visual Studio in the Parent Form. If you want to have Dependency Injection, create another constructor.
Like this:
public ProductDetail()
{
InitializeComponent();
}
public ProductDetail(ISupplierController supplierController) : base()
{
InitializeComponent();
this.supplierController = supplierController;
}
You can then still do this from your inherited Form:
public NewProduct(ISupplierController supplierController)
: base(supplierController)
{
InitializeComponent();
}
This worked for me so far, and I had some weird designer issues too.
cheers, Daniel
Read this: http://cs.rthand.com/blogs/blog_with_righthand/archive/2005/11/10/186.aspx
AFAIK, there are still issues with Visual Inheritance and objects that rely on collections for the design elements, typically grid controls etc. I believe MS still have removed the possibility of changing f.ex. a GridView in an inherited form/usercontrol etc. But other controls like TextBox, Form, UserControl, Panel etc. should work as expected.
I've so far had no problem with VI using 3rd party grid controls myself, but you have to be careful, in particular, removing items from collections MUST be avoided.