2

I have a created a simple user control and dynamically added that control to a new custom field in Sitecore. When viewing the item having that custom field in content editor, it works just fine. If I click on any other item or even try to save that item I get a popup error saying:

Could not load file or assembly'file:///G:\SitecoreInetpub\wwwroot\SitecoreInstance\Website\bin\App_Web_test.ascx.cdcab7d2.z3kp1dyl.dll' or one of its dependencies. The system cannot find the file specified.

DLL name changes every time I clean build the solution. Also dynamically adding a control creates a temp dll (App_Web_test.ascx.cdcab7d2.z3kp1dyl.dll) in "C:\windows\Framework64\v4.0.30319\Temporary ASP.NET Files" folder however it is looking for the same in inetpub which it couldn't find.

I am not sure what is causing this. This is the Custom field class:

    public class XMLField : Sitecore.Shell.Applications.ContentEditor.File, Sitecore.Shell.Applications.ContentEditor.IContentField
    {
        protected override void OnLoad(EventArgs e)
        {
            if (!Sitecore.Context.ClientPage.IsEvent)
            {
                    Test test = (Test)Page.LoadControl("/Test.ascx");
                    test.ID = "TEST_ID";
                    test.Visible = true;
                    Controls.Add(test);
            }
            base.OnLoad(e);
        }


        public new string GetValue()
        {
            return Value;
        }

        public new void SetValue(string value)
        {
            Value = value;
        }

        protected override void Render(HtmlTextWriter output)
        {
            base.Render(output);
        }

        public override void HandleMessage(Message message)
        {
            base.HandleMessage(message);
        }

    }

User control Test.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="SitecoreWebsite.Test" %>
<div id="testdiv">
    Test Div
</div>

User control backend Test.ascx.cs

    public partial class Test : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
7
  • You should try to add "everyone" permission on your website folder(it´s not recommended on CM and CD servers) but for a developer machine, it can be a way to test (just to make sure if it´s not a lack of permissions). – Jose Neto Jun 3 '17 at 19:24
  • Tried it, still the same error. – Rishabh Kumar Jun 3 '17 at 19:54
  • Can you please elaborate what are you trying to accomplish here? Looking from your code you have created a new custom field in Sitecore and you are loading a control on it's load? The reason why I ask this is that depending on what you are trying to do the approach to take may differ from what you are taking and get rid of the problem altogether – Diego Jun 4 '17 at 1:13
  • @Diego I am trying to create a custom field where one can set a media library path of a file and then view all its content via that user control I have added. I have tried that via Render method and it works fine but just for the sake of modularity and clarity I am creating a separate control to render the html. Hope the purpose is clear now. – Rishabh Kumar Jun 4 '17 at 7:46
  • Well, You can also change your implementation, maybe a Simple ASP NET Repeater,would do the job without errors . – Jose Neto Jun 6 '17 at 14:07

Your Answer

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

Browse other questions tagged or ask your own question.