none
Error to create a View - This operation would create an incorrectly structured document RRS feed

  • Question

  • Hello.

    I have the error below when I was try to create a new view in a existing project.

    This operation would create an incorrectly structured document

    System.InvalidOperationException: This operation would create an incorrectly structured document.
       at System.Xml.Linq.XDocument.ValidateDocument(XNode previous, XmlNodeType allowBefore, XmlNodeType allowAfter)
       at System.Xml.Linq.XDocument.ValidateNode(XNode node, XNode previous)
       at System.Xml.Linq.XContainer.AddNodeSkipNotify(XNode n)
       at System.Xml.Linq.XContainer.AddContentSkipNotify(Object content)
       at System.Xml.Linq.XContainer.Add(Object content)
       at System.Data.Entity.Migrations.Extensions.XContainerExtensions.GetOrCreateElement(XContainer container, String elementName, XAttribute[] attributes)
       at System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.AddOrUpdateConfigSection(XDocument config, Version entityFrameworkVersion)
       at System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand.<>c__DisplayClass3.<Execute>b__1(XDocument c)
       at System.Data.Entity.ConnectionFactoryConfig.ConfigFileProcessor.ProcessConfigFile(ProjectItem configItem, IEnumerable`1 manipulators)
       at System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand.<>c__DisplayClass3.<Execute>b__0(ProjectItem i)
       at System.Data.Entity.ConnectionFactoryConfig.ConfigFileFinder.FindConfigFiles(ProjectItems items, Action`1 action)
       at System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand.Execute()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

    The system does not have in the Web.config the line xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"

    After to try to create the view and saw the error, the referente to the Entity Framework desapear from the project. This is very strange.

    Someone has any ideia how to solve this?

    Thanks a lot! :)

    Thursday, January 24, 2019 5:12 PM

All replies

  • I have the error below when I was try to create a new view in a existing project.

    This operation would create an incorrectly structured document

    The system does not have in the Web.config the line xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"

    After to try to create the view and saw the error, the referente to the Entity Framework desapear from the project. This is very strange.

    View? What view are you talking about? What kind of .NET program is this? What version of .NET Framework are you using? Why do you think that this is an Entity Framework issue, which is the forum you have posted to the EF forum?

    Thursday, January 24, 2019 6:00 PM
  • ASP Net Web Application - ASP NET MVC 5. 

    .NET Framework 4.6.1

    View for an ActionResult method.

    I´m not sure if this error is from Entity. I'm trying to discover because I never seen this before.

    Trying to create a view using the Scaffolding method in the Visual Studio and see this error.

    After the error the reference to the Entity disappear from the project.

    Thursday, January 24, 2019 6:16 PM
  • Trying to create a view using the Scaffolding method in the Visual Studio and see this error.

    Oh, it is the wizard.

    Why can't you do the scaffolding yourself? Why can't you create a view yourself? Why can't you use EF to load a viewmodel that has scaffolding you did manually that the view uses?

    After the error the reference to the Entity disappear from the project.

    It's more like the wizard blew up and EF  somehow was dropped. It's one of the drawbacks of using a wizard, and the wizard blows up.  

    Friday, January 25, 2019 12:02 AM
  • Hi João Sarno,

    Based on your error message, it seems that it is a XML issue, in addition, the issue is very strange, could you please provide related steps to reproduce the issue. 

    In addition, since the issue is more related to asp.net, I would suggest that you could post your issue on asp.net forum for suitable support.

    https://forums.asp.net/15.aspx/1?Getting+Started

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 28, 2019 1:48 AM
    Moderator
  • Hello Zhanglong.

    I just tried to create a View using the Scaffolding of the Visual Studio. I selected the parameters, like View Name, Template, Model Class and Data Context Class. I Check Reference Scripts Libraries and Use a Layout Page.

    Visual Studio starts to create the View but the process is aborted and the error above appears.

    I never see that before, I tried to reinstall the Entity through the Nuget, but the error persist.

    Monday, January 28, 2019 2:02 PM
  • Hello Zhanglong.

    I just tried to create a View using the Scaffolding of the Visual Studio. I selected the parameters, like View Name, Template, Model Class and Data Context Class. I Check Reference Scripts Libraries and Use a Layout Page.

    Visual Studio starts to create the View but the process is aborted and the error above appears.

    I never see that before, I tried to reinstall the Entity through the Nuget, but the error persist.

    Stop using the wizard, learn how to use a viewmodel, put the scaffolding on the VM, load the VM using EF and pass the VM into the view from the controller.

    https://www.tutlane.com/tutorial/aspnet-mvc/how-to-use-viewmodel-in-asp-net-mvc-with-example

    I added the scaffolding  manually myself to the VM.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc.Rendering;
    
    namespace ProgMgmntCore2UserIdentity.Models
    {
        public class ProjectViewModels
        {
            public class Project
            {
                public int ProjectId { get; set; }
    
                [Required(ErrorMessage = "Client Name is required")]
                [StringLength(50)]
                public string ClientName { get; set; }
    
                [Required(ErrorMessage = "Project Name is required")]
                [StringLength(50)]
                public string ProjectName { get; set; }
    
                [Required(ErrorMessage = "Technology is required")]
                [StringLength(50)]
                public string Technology { get; set; }
    
                [Required(ErrorMessage = "Project Type is required")]
                public string ProjectType { get; set; }
    
                [Required(ErrorMessage = "Start Date is required")]
                [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM-dd-yyyy}")]
                public DateTime? StartDate { get; set; }
    
                [Required(ErrorMessage = "End Date is required")]
                [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM-dd-yyyy}")]
                public DateTime? EndDate { get; set; }
    
                [Required(ErrorMessage = "Cost is required")]
                public decimal? Cost { get; set; }
    
                public List<SelectListItem> ProjectTypes { get; set; }
            }
           
            public List<Project> Projects { get; set; }
            
        }
    }

    Monday, January 28, 2019 8:19 PM