Copied to clipboard

Flag this post as spam?

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


  • Tim C 161 posts 528 karma points
    Jun 12, 2020 @ 11:10
    Tim C
    0

    App_Code code not being recognised

    I am using Umbraco 7 on a hosting service and on one instance have some code in file owCore.cshtml file in App_Code.

    ...
    public static string getMediaUrl(int mediaId){
                    umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);      
                    return umbracoHelper.TypedMedia(mediaId).Url.ToString();
        }
    
    ...
    

    In this instance, I have a partial view which uses this code...

    @functions{
     ...
    pValue = owCore.getMediaUrl(mediaId);
    ...
    }
    

    and it works fine.

    I have created a new Umbraco instance on the host and copied across the App_Code folder and the partial view.

    However, when I run this, I get

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'owCore' does not exist in the current context
    
    Source Error:
    
    
    Line 640:                   if(rtn=="mediaUrl"){
    Line 641:                       int mediaId = Int32.Parse(pValue);
    Line 642:                       pValue = owCore.getMediaUrl(mediaId);
    

    I thought APP_code would be automatically compiled and included in any sites.

    Am I missing something, do I need to reference App_code in the config somewhere?

    (I may have done this in the original instance, but this was created 3 years ago and I can't recall!

  • Tim C 161 posts 528 karma points
    Jun 12, 2020 @ 22:00
    Tim C
    0

    How many hours have I stared at the code, and debugged it ... before finally spotting I had copied the App_Code folder to the wrong install.

    Aaagh!!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies