Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • setkeh 2 posts 72 karma points
    Jul 03, 2016 @ 16:45
    setkeh
    0

    Error loading Partial View Exception: System.Web.HttpCompileException

    Hi guys and Gals,

    I'm having an Issue with Umbraco 7.4.3 trying to develop a Macro i have been googling for the last few hours trying to find an answer to the issue.

    2016-07-04 02:27:40,599 [P26400/D2/T80] WARN  umbraco.macro - Error loading Partial View (file: ~/Views/MacroPartials/Github.cshtml). Exception: System.Web.HttpCompileException (0x80004005): c:\Users\jadag\AppData\Local\Temp\Temporary ASP.NET Files\vs\55765d8e\102aaef5\App_Web_github.cshtml.d673bf47.kw3ul6bs.0.cs(141): error CS1002: ; expected
       at System.Web.Compilation.AssemblyBuilder.Compile()
       at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
       at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
       at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
       at System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath virtualPath)
       at System.Web.Compilation.BuildManager.GetCompiledType(String virtualPath)
       at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetCompiledType(String virtualPath)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode node)
       at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    

    I have Also inserted some Breakpoints in the Relevant view/Code and noticed that they are never hit.

    The Github code is a class Library i wrote a little while back its code is.

    using Octokit;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    namespace SetWebGithub
    {
        public class Repos
        {
            internal static GitHubClient Connect()
            {
                GitHubClient client = new GitHubClient(new ProductHeaderValue("My_AppName"));
                Credentials tokenAuth = new Credentials("My_OAuthToken");
                client.Credentials = tokenAuth;
                return client;
            }
    
            public static async Task<IReadOnlyList<Repository>> ListRepos()
            {
                GitHubClient client = Connect();
    
                User user = await client.User.Current();
    
                IReadOnlyList<Repository> repos = await client.Repository.GetAllForUser(user.Name);
    
                return repos;
            }
    
            public static async Task<Dictionary<string, string>> Stats()
            {
                try
                {
                    Dictionary<string, string> stats = new Dictionary<string, string>();
                    GitHubClient client = Connect();
    
                    User user = await client.User.Current();
    
                    stats.Add("CakeDay", user.CreatedAt.ToString("dd-MM-yyy"));
                    stats.Add("Gists", user.PublicGists.ToString());
                    stats.Add("Repos", user.PublicRepos.ToString());
                    stats.Add("Followers", user.Followers.ToString());
                    stats.Add("Following", user.Following.ToString());
                    stats.Add("Hireable", user.Hireable.ToString());
    
                    return stats;
                }
                catch (Exception ex)
                {
                    throw new Exception("Bad Things Happened", ex);
                }
    
            }
        }
    }
    

    And the Macro view Partial is

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
        @using umbraco.MacroEngines;
        @using System;
        @using SetWebGithub;
        @using Octokit;
    
    @{
        System.Threading.Tasks.Task.Run(async () =>
        {
        IReadOnlyList<Repository> msg = await Repos.ListRepos();
    
        foreach (Repository _Repo in msg)
        {
            @:<p> @String.Format("{0}: {1}", _Repo.Name, _Repo.Url); </p>
        };
        });
    };
    

    And the code file that its throwing the exception (This is auto generated every time the page is refreshed from what i can tell.

    #pragma checksum "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "43640B97D3F5A0A0A471E8D7EAD766880BDBB345"
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.42000
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    namespace ASP {
    
        #line 3 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
        using System;
    
        #line default
        #line hidden
        using System.Collections.Generic;
        using System.IO;
        using System.Linq;
        using System.Net;
        using System.Web;
        using System.Web.Helpers;
        using System.Web.Security;
        using System.Web.UI;
        using System.Web.WebPages;
        using System.Web.Mvc;
        using System.Web.Mvc.Ajax;
        using System.Web.Mvc.Html;
        using System.Web.Routing;
        using Umbraco.Web;
        using Umbraco.Core;
        using Umbraco.Core.Models;
        using Umbraco.Web.Mvc;
        using umbraco;
        using Examine;
        using Umbraco.Web.PublishedContentModels;
    
        #line 2 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
        using umbraco.MacroEngines;
    
        #line default
        #line hidden
    
        #line 4 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
        using SetWebGithub;
    
        #line default
        #line hidden
    
        #line 5 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
        using Octokit;
    
        #line default
        #line hidden
    
    
        public class _Page_Views_MacroPartials_Github_cshtml : Umbraco.Web.Macros.PartialViewMacroPage {
    
    #line hidden
    
            public _Page_Views_MacroPartials_Github_cshtml() {
            }
    
            protected ASP.global_asax ApplicationInstance {
                get {
                    return ((ASP.global_asax)(Context.ApplicationInstance));
                }
            }
    
            public override void Execute() {
    BeginContext("~/Views/MacroPartials/Github.cshtml", 50, 1, true);
    
    WriteLiteral("\t");
    
    EndContext("~/Views/MacroPartials/Github.cshtml", 50, 1, true);
    
    BeginContext("~/Views/MacroPartials/Github.cshtml", 80, 1, true);
    
    WriteLiteral("\t");
    
    EndContext("~/Views/MacroPartials/Github.cshtml", 80, 1, true);
    
    BeginContext("~/Views/MacroPartials/Github.cshtml", 96, 4, true);
    
    WriteLiteral("    ");
    
    EndContext("~/Views/MacroPartials/Github.cshtml", 96, 4, true);
    
    BeginContext("~/Views/MacroPartials/Github.cshtml", 121, 4, true);
    
    WriteLiteral("    ");
    
    EndContext("~/Views/MacroPartials/Github.cshtml", 121, 4, true);
    
    BeginContext("~/Views/MacroPartials/Github.cshtml", 141, 1, true);
    
    WriteLiteral("\n");
    
    EndContext("~/Views/MacroPartials/Github.cshtml", 141, 1, true);
    
    
                #line 7 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
    
        System.Threading.Tasks.Task.Run(async () =>
        {
        IReadOnlyList<Repository> msg = await Repos.ListRepos();
    
        foreach (Repository _Repo in msg)
        {
    
    
                #line default
                #line hidden
    item => new System.Web.WebPages.HelperResult(__razor_template_writer => {
    
    BeginContext(__razor_template_writer, "~/Views/MacroPartials/Github.cshtml", 312, 4, true);
    
    WriteLiteralTo(__razor_template_writer, "<p> ");
    
    EndContext(__razor_template_writer, "~/Views/MacroPartials/Github.cshtml", 312, 4, true);
    
    BeginContext(__razor_template_writer, "~/Views/MacroPartials/Github.cshtml", 317, 48, false);
    
    
                #line 14 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
    WriteTo(__razor_template_writer, String.Format("{0}: {1}", _Repo.Name, _Repo.Url));
    
    
                #line default
                #line hidden
    EndContext(__razor_template_writer, "~/Views/MacroPartials/Github.cshtml", 317, 48, false);
    
    BeginContext(__razor_template_writer, "~/Views/MacroPartials/Github.cshtml", 365, 7, true);
    
    WriteLiteralTo(__razor_template_writer, "; </p>\n");
    
    EndContext(__razor_template_writer, "~/Views/MacroPartials/Github.cshtml", 365, 7, true);
    
    })
    
                #line 15 "h:\jadag\documents\visual studio 2015\Projects\SetWeb\SetWeb\Views\MacroPartials\Github.cshtml"
        };
        });
    
    
                #line default
                #line hidden
    BeginContext("~/Views/MacroPartials/Github.cshtml", 388, 2, true);
    
    WriteLiteral(";\n");
    
    EndContext("~/Views/MacroPartials/Github.cshtml", 388, 2, true);
    
            }
        }
    }
    

    If i have Missed anything please let me know but i appreciate any help you can provide as i'm stumped at this point.

    Thanks :D

  • setkeh 2 posts 72 karma points
    Jul 04, 2016 @ 13:56
    setkeh
    0

    Hi guys and gals,

    An Update :)

    I have Modified the code now to look like so

    Repos.cs

    using Octokit;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    namespace SetWebGithub
    {
        public class Repos
        {
            internal static GitHubClient Connect()
            {
                GitHubClient client = new GitHubClient(new ProductHeaderValue("My_App"));
                Credentials tokenAuth = new Credentials("My_Token");
                client.Credentials = tokenAuth;
                return client;
            }
    
            public static Dictionary<string, string> ListRepos()
            {
                Dictionary<string, string> result = new Dictionary<string, string>();
    
                var task = ListReposAsync();
                task.Wait();
    
                IReadOnlyList<Repository> msg = task.Result;
    
                foreach (Repository _Repo in msg)
                {
                    result.Add(_Repo.Name, _Repo.Url);
                };
                return result;
            }
    
            private static async Task<IReadOnlyList<Repository>> ListReposAsync()
            {
                GitHubClient client = Connect();
    
                User user = await client.User.Current();
    
                IReadOnlyList<Repository> repos = await client.Repository.GetAllForUser(user.Name);
    
                return repos;
            }
    
            public static async Task<Dictionary<string, string>> Stats()
            {
                try
                {
                    Dictionary<string, string> stats = new Dictionary<string, string>();
                    GitHubClient client = Connect();
    
                    User user = await client.User.Current();
    
                    stats.Add("CakeDay", user.CreatedAt.ToString("dd-MM-yyy"));
                    stats.Add("Gists", user.PublicGists.ToString());
                    stats.Add("Repos", user.PublicRepos.ToString());
                    stats.Add("Followers", user.Followers.ToString());
                    stats.Add("Following", user.Following.ToString());
                    stats.Add("Hireable", user.Hireable.ToString());
    
                    return stats;
                }
                catch (Exception ex)
                {
                    throw new Exception("Bad Things Happened", ex);
                }
    
            }
        }
    }
    

    and the macro cshtml to

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
        @using SetWebGithub;
    
    @{ 
        Dictionary<string, string> result = Repos.ListRepos();
    }
    
    @foreach (KeyValuePair<string, string> Repo in result)
    {
        <p>@Repo.Key @Repo.Value</p>
    }
    

    This now throws no errors at all but now the async task now just runs forever and never returns the data,

    The part now causing issue is

    User user = await client.User.Current();
    

    in Repos.cs

    I have tested the Async method with the following console application to verify it is working

    Dictionary<string, string> results = Repos.ListRepos();
    
    foreach (KeyValuePair<string, string> _Repo in results)
    {
        Console.WriteLine(_Repo.Key + ": " + _Repo.Value);
    }
    

    And it returns all 75 Repo's in the search in just a handful of milliseconds so im unsure what could be causing the hanging/looping or what ever is occurring in umbraco.

    Im still open to any help or insight that could be provided here thanks :)

Please Sign in or register to post replies

Write your reply to:

Draft