locked
Getting - Value cannot be null. Parameter name: virtualPath on webmatrix page RRS feed

  • Question

  • User1459380094 posted

    I have been unable to find any explanation of why I would be getting this error, especially on a page that is a virtual duplicate of another page that works fine.

    Have been trying to find any direction on line for a week now with no luck.

    I setup a debug/db write of the information for the results of the "Details" query as well as the Genre query and both are working correctly and returning data. Set the same thing up within the failing foreach loop and the program is cycling through every value in the GetGenre query results - so none of the fields involved are null, all have data...

    FYI - I have tried commenting out the Select and foreach row lines. When I did so, I get the same error but on the line above that where I am prompting for the name (value = @Details.ArtName).

    I did add my "Debug" where I write values to a database to confirm that the query to retrieve the Details information is working and is returning the expected record - I used the Details.ArtName format on the naming of the values written to the data file and those did work and did not produce the error (error still shows up at the same spot). So, I know that the DB.QuerySingle is working and is returning values, I know that the db.Query of Genre is working and returning values. I also know that the foreach loop is getting processed and, with my debug/write to a table of values, that all of the records returned by the db.query on Gener are getting read and processed. So... Getting above error apparently after all of the html has been rendered/formatted and as it is being read and written to the screen with in the browser.

    I have tried this in multiple browsers (Firefox, chrome, IE) and still get the same result.

    Lost on this one.

    the Stack trace is:

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: virtualPath

    Source Error:

    Line 163:            <select name="Genre" size="1" style="width: 170px">
    Line 164:              <option value="0">None</option>
    Line 165:              @foreach(var row in GetGenre){
    Line 166:
    Line 167:               <option value="@row.GenreID" @if(@Details.ArtGenre == @row.GenreID){<text>selected="selected"</text>}>@row.Genre</option> }            


    Source File: c:\Users\JIM\Documents\My Web Sites\The Brew City Rockers\Admin\ArtistAdmin.cshtml    Line: 165

    Stack Trace:

    [ArgumentNullException: Value cannot be null.
    Parameter name: virtualPath]
       System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options) +9829865
       System.Web.VirtualPathUtility.Combine(String basePath, String relativePath) +30
       System.Web.WebPages.UrlUtil.Url(String basePath, String path, Object[] pathParts) +16
       System.Web.WebPages.WebPageExecutingBase.Href(String path, Object[] pathParts) +24
       ASP._Page_Admin_ArtistAdmin_cshtml.Execute() in c:\Users\JIM\Documents\My Web Sites\The Brew City Rockers\Admin\ArtistAdmin.cshtml:165
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
       System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
       System.Web.WebPages.WebPage.ExecutePageHierarchy() +151
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
       System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114
    


    The source code:

    {
        Layout = "~/Shared/Layout/_AdminLayout.cshtml";
        Page.Title = "Artist Administration";
        var roleName = Request["roleName"];
        string[] userRoles = Roles.GetRolesForUser();
        bool isInRequiredRole = false;
        if (!userRoles.Contains("Admin") && !userRoles.Contains("Band")){
          Response.Redirect("/") ; 
        } 
     
     
        // Open the database.
        var db = Database.Open("BCR");
     
        // Initialize general page variables.
        string editMode = "";
        int selectedId = -1;
        var AName = "";
        var AGenre = -1;
        var ALogo = -1;
        var PageVal = "";
        var SortVal = "";
        var PageURL = "";
        var imagePath = "";
        var debugdata = "";
        var GetGenre = db.Query("select * from Genre order by Genre");
     
        if (userRoles.Contains("Admin"))
        {
          isInRequiredRole = true;
          }
        
        // List to hold any error or update messages and error flag.
        List<string> statusMessages = new List<string>();
        bool errorOccurred = false;
     
        // Check for "page" or "sort" in QueryString so that if the visitor
        // clicked "Next" or "Previous" or a column header to sort the rows
        // you do not execute an edit process again.
        if (Request.QueryString["page"] == null && Request.QueryString["sort"] == null)
        {
            // Get the values from the REST-style URL parameters
            editMode = UrlData[0];
            selectedId = UrlData[1].AsInt(-1);
            if (editMode != "" && editMode != "Add" && editMode != "Post" && selectedId < 0)
            {
                editMode = "";
                errorOccurred = true;
                statusMessages.Add("ERROR: Invalid Artist ID specified");
            }
        }
     
        PageVal = Request.QueryString["page"];
        SortVal = Request.QueryString["sort"]; 
        if (PageVal != null){
            PageURL = PageURL.Trim() + "?page=" + PageVal;
        }
        if (SortVal != null && PageVal != null){
            PageURL = PageURL.Trim() + "&sort=" + SortVal;
        }   
        if(PageVal == null && SortVal != null){
            PageURL = PageURL.Trim() + "?sort=" + SortVal;
        } 
     
     
        if (editMode == "Update" && Request.Form["CancelUpdate"] == null)
        {
            // Update the selected member details in the UserProfile table.
            AName = Request.Form["Name"];
            AGenre = Request.Form["Genre"].AsInt();
                   
           // isApproved = Request.Form["isApproved"]=="No";
            // Validate the comment
            if (AName.IsEmpty())
            {
                errorOccurred = true;
                statusMessages.Add("ERROR: You must enter a Name");
            }
            
            if (! errorOccurred)
            {
                // Update the database.
                if (db.Execute("UPDATE Artists SET ArtName = @0, ArtGenreID = @1 WHERE songId = @2",
                    AName, AGenre, selectedId) > 0)
                {
                   
                    statusMessages.Add(String.Format("Updated Song ID {0}",
                                                    selectedId));
                }
                else
                {
                    errorOccurred = true;
                    statusMessages.Add(String.Format("ERROR: Could not update Artist "
                                    + "ID {0}", selectedId));
                }
            }
        } else
            if (editMode == "Post" && Request.Form["CancelUpdate"] == null)
        {
            // Update the selected member details in the UserProfile table.
            AName = Request.Form["Name"];
            AGenre = Request.Form["Genre"].AsInt();
                   
           // isApproved = Request.Form["isApproved"]=="No";
            // Validate the comment
            if (AName.IsEmpty())
            {
                errorOccurred = true;
                statusMessages.Add("ERROR: You must enter a Name");
            }
            
            if (! errorOccurred)
            {
                // Update the database.
                if (db.Execute("Insert into Artists (AName, ArtGenreID, ArtLogoID) Values(@0, @1, 0)", AName, AGenre) > 0)
                {
                   
                    statusMessages.Add(String.Format("Added Artist ID {0}",
                                                    selectedId));
                }
                else
                {
                    errorOccurred = true;
                    statusMessages.Add(String.Format("ERROR: Could not Add Artist {0}", AName));
                }
            }
        }
        
     
        // Set the color value and display style for the status or error messages.
        string errorColor = errorOccurred ? "color:#ff0000;" : "color:#000000;";
        string showStatus = statusMessages.Count() > 0
                            ? "display:block;" : "display:none;";
    }
     
    <div class="resultsDetail" style="@showStatus @errorColor">
        @foreach (string msg in statusMessages){ @(msg + ".")<br /> }
    </div>
     
    @if (editMode == "Edit")
    {
      // Display controls to edit the selected account.
      // Get existing user details.
     
       var Details = db.QuerySingle("SELECT * FROM Artists WHERE ArtID = @0", selectedId);
      <form id="EditArtist" action="@Href("~/Admin/ArtistAdmin/Update", selectedId)"
            method="post">
         <fieldset>
          <legend>Artist Details</legend>
          <table>
            <tr>
                <td>
                    <label for="Name" style="display:inline">Artist:</label>
                </td>
                <td>
                    <input type="text" maxlength="100" style="width: 200px; padding: 2px" id="Name" name="Name" title="Name" 
                    value ="@Details.ArtName" /> 
                </td>
            </tr>
            <tr>
                <td> <label for="Genre" style="display:inline">Genre:</label>  </td>
                <td>
                <select name="Genre" size="1" style="width: 170px">
                  <option value="0">None</option>
                  @foreach(var row in GetGenre){
     
                   <option value="@row.GenreID" @if(@Details.ArtGenre == @row.GenreID){<text>selected="selected"</text>}>@row.Genre</option> }            
                </select> 
            </td>
            </tr>            
       </table>
     
    <br/> 
       
          
          <p class="form-actions">
            <input type="submit" value="Update" title="Update" style="height: 30px; line-height: 30px; width: 115px;"/>
            <input type="submit" value="Back" onclick="javascript:window.history.go(-1);" style="height: 30px; line-height: 30px; width: 115px;" />
     
    <script type="text/javascript">
    document.forms['EditArtist'].elements['Name'].focus();
    </script>
     
     
          </p>
     </fieldset>
      </form>
    <div id="layer1" style="width:122px; height:122px; position:absolute; left:880px; top:90px; z-index:1;">
        <p><img src="@Href(@imagePath)" width="250" alt="Logo"></p> 
        <input type="submit" value="Upload Logo" onclick="location.replace('/Admin/Clubs/uploadLogo/@selectedId.ToString()/Artist');return false;" style="height: 30px; line-height: 30px; width: 115px;" />
     
    </div>  
     
    }
    else if(editMode == "Add"){
         // Display controls to edit the selected account.
      // Get existing user details.
     
      <form id="AddArtist" action="@Href("~/Admin/ArtistAdmin/Post")"
            method="post">
         <fieldset>
          <legend>Artist Details</legend>
          <table>
            <tr>
                <td>
                    <label for="Name" style="display:inline">Artist:</label>
                </td>
                <td>
                    <input type="text" maxlength="100" style="width: 200px; padding: 2px" id="Name" name="Name" title="Name" /> 
                </td>
            </tr>
            <tr>
                <td> <label for="Genre" style="display:inline">Genre:</label>  </td>
                <td>
                <select name="Genre" size="1" style="width: 170px">
                  <option value="0">None</option>
                  @foreach(var row in GetGenre){
                   <option value="@row.GenreID">@row.Genre</option> }                
                </select> 
            </td>
            </tr>            
                          
        </table>
      
          
          <p class="form-actions">
            <input type="submit" value="Update" title="Update" style="height: 30px; line-height: 30px; width: 115px;"/>
            <input type="submit" value="Back" onclick="javascript:window.history.go(-1);" style="height: 30px; line-height: 30px; width: 115px;" />
     
    <script type="text/javascript">
    document.forms['AddArtist'].elements['Name'].focus();
    </script>
     
          </p>
        </fieldset>
      </form> 
    } else {
      // Display a list of member accounts.
      // Create the Grid Helper object.
     
     
      var data = db.Query("SELECT * From Artists as a left outer join Genre as b on a.ArtGenre = b.GenreID");
      var grid = new WebGrid(source: data, rowsPerPage:8);
      <div>
           @grid.GetHtml(
          tableStyle: "grid",
          previousText: "Previous",
          mode: WebGridPagerModes.All,
          nextText: "Next",
          lastText: "Last",
          headerStyle: "gridheader",
          columns: grid.Columns(
            grid.Column(header:"",
            format:@<a href="@Href("~/Admin/UpdArtist", @item.ArtID, "D" + @PageURL)">Del</a>
          ),
            grid.Column(header:"",
            format:@<a href="@Href("~/Admin/ArtistAdmin/Edit",
                                   @item.ArtID)">Edit</a>),
            grid.Column("ArtName", header:"Artist"),
            grid.Column("Genre", header:"Genre"),
            grid.Column("Path", header:"Picture",
                format:@<text>
                @if(@item.ArtLogoID != null){
                @Html.Raw("<img src=\"/Images/Thumbs/" + @item.ArtLogoID.ToString() + "_Thumb.jpg" + "\" width=\"50\" />")}
                else {
                    @Html.Raw("<img src=\"~/Images/facebook.png width=\"50\">")
                }    
            </text>, canSort: false)
                )
          
          )
          <input type="submit" value="Add" onclick="location.href='/Admin/ArtistAdmin/Add';return false;" style="height: 30px; line-height: 30px; width:  115px;" />
          <input type="submit" value="Back" onclick="javascript:window.history.go(-1);" style="height: 30px; line-height: 30px; width: 115px;" />
          <input type="submit" value="Home" onclick="location.href='/';return false;" style="height: 30px; line-height: 30px; width: 115px;" />
     
     
      </div>
    }
     
    

    Friday, May 15, 2015 12:27 AM

Answers

  • User1459380094 posted

    Found the cause - the Div at the bottom of the form calling page for logo upload had the imagePath variable, which was not populated.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 17, 2015 11:39 AM