-1

I am new to Tridion back end coding. I have used the logger for the debug. But I didn't get much information from there. Can anyone please let me know the most common way to debug the code?

I am facing the issue while updating the existing controls which is c# code. The error I am getting is Object reference not set to an instance of an object.

public partial class YoutubeFeedControl : System.Web.UI.UserControl
    {
        //public string AccountName;
        private ILog _logger; 
        protected string baseUrl = "http://www.youtube.com/feeds/videos.xml?channel_id=UCBtqBoVCQ9JiNqyqYUpuejA";


        protected void Page_Load(object sender, EventArgs e)
        {
           // _logger.DebugFormat("Choose a Country Dropdown: Schema: {0}", baseUrl);

            try
            {
                WebClient c = new WebClient();
                c.Encoding = UTF8Encoding.UTF8;
                string output = c.DownloadString(baseUrl);
                YoutubeRequest request = JsonConvert.DeserializeObject<YoutubeRequest>(output);

                Repeater Rpt = base.FindControl("Rpt") as Repeater;
                Rpt.DataSource = request.Feed.Videos;
                Rpt.DataBind();
            }
            catch (Exception theException)
            {
                _logger.DebugFormat("An error occured: {0}\n{1}", theException.Message, theException.StackTrace);
            }

        }

        protected void SetItem(object sender, RepeaterItemEventArgs e)
        {
            Image image = e.Item.FindControl("Image") as Image;
            HyperLink link = e.Item.FindControl("Link") as HyperLink;
            Literal date = e.Item.FindControl("Date") as Literal;
            Literal views = e.Item.FindControl("Views") as Literal;

            Video video = e.Item.DataItem as Video;

            image.ImageUrl = video.Thumbnail;
            image.AlternateText = video.Title;
            link.NavigateUrl = video.Link;
            link.Text = video.Title;
            date.Text = video.Published.ToString("dd MMM yyyy");
            views.Text = video.Views;            
        }
    }  
| improve this question | | | | |
  • Please let us know if you are trying to debug Tridion Templates with TOM.NET or Core Service code. Also, code snippets are always appreciated. :) Also, if you have researched it on the Tridion Live Content Documentation or found other blog links you have looked at, pls also include them too. – robrtc Jul 6 '15 at 14:13
  • I have updated the question. Can you please help me what is the best way to debug this? – vids Jul 7 '15 at 7:01
  • Thanks for uploading the example code. Maybe the website is published from Tridion, but I don't see any Tridion API calls in the code. IT appears to be a Webforms web application. I'd suggest to use follow Web Forms best practices for debugging. Also, if you haven't tried Elmah, it's a great way to remotely view errors in apps. Just make sure to set remote=false for Prod. Good luck! – robrtc Jul 7 '15 at 8:30
1

It depends on what you are trying to debug.

For content management related extension debugging except core service: You will have to setup remote debugging to connect to your CM server / publisher server and attach different processes, refer: SDL Live documentation

For core service, you can directly debug your code from VS studio, no remote debugging required.

Update 1: To debug the code, there are two ways.

  1. If you can setup your application locally then you can directly debug it from Visual studio.
  2. If application is setup remotely and not possible to set it up locally then use remote debugging to debug the code. Steps to be followed: a. For the VS studio version copy the remote debugger folder from local system and copy it to remote server where application is hosted and double click on msvmon.exe which will open listener for remote debugger. From visual studio connect to remote server on the port listed. (Please note, click enter once you have entered remote server and port). It will display all the processes from the remote server, connect to the process you want to debug with and debug the code.
| improve this answer | | | | |
  • I have updated the question. Can you please help me what is the best way to debug this? – vids Jul 7 '15 at 7:02
  • I have added the update 1 to my answer. Can you please tag your question based on where this code is running like event system, TOM.Net, TBB, Content Delivery etc. – Hiren Kaku Jul 7 '15 at 7:17
1

One of the common things that I see is when people get back an object, in many cases an item field, and assume that it is populated. They then work with the data within that object.

Using the example of a text field in a component, if the field hasn't been populated then the data doesn't exist and it will return null. If you assume that it does exist, and do things like .ToString() with it, you will actually be running null.ToString(), which will throw the error that you've described here.

The very first check, in most cases, should be whether or not the returned object is null.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.