1

I have inherited a project from a previous developer. After opening and rebuilding it in my copy of VS, a couple of the lines below somehow swapped positions which caused major problems in the release build.

When I traced back the cause I noticed the original developer had tried to force these lines to stay in a fixed order by adding a comment line (see below).

Is there a better way of ensuring these lines always remain in this order?

[assembly: System.Web.UI.WebResource("BS.Web.Controls.AjaxFileUpload.XMLHttpExecutor.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("BS.Web.Controls.AjaxFileUpload.XMLHttpExecutor.debug.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("BS.Web.Controls.AjaxFileUpload.AjaxFileUpload.debug.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("BS.Web.Controls.AjaxFileUpload.AjaxFileUpload.js", "application/x-javascript")]
[assembly: WebResource("BS.Web.Controls.AjaxFileUpload.AjaxFileUpload.css", "text/css", PerformSubstitution = true)]

namespace BS.Web.Controls
{

    public delegate void EventAjaxFileUploadOnComplete(object sender, HttpPostedFile file);
    public delegate void EventAjaxFileUploadOnAllComplete(object sender);

    [RequiredScript(typeof(CommonToolkitScripts))]
    [Designer("BS.Web.Controls.AjaxFileUploadDesigner, BS.Web.Controls")]
    [ClientCssResource("BS.Web.Controls.AjaxFileUpload.AjaxFileUpload.css")]
    [ClientScriptResource("AjaxControlToolkit.AjaxFileUpload", "BS.Web.Controls.AjaxFileUpload.AjaxFileUpload.js")]
    // Just a throwaway comment to try and prevent the following reference being swapped with the preceding
    [ClientScriptResource("Sys.Net.XMLHttpExecutor", "BS.Web.Controls.AjaxFileUpload.XMLHttpExecutor.js")]


    public class AjaxFileUpload : ScriptControlBase
    {
userSteve
  • 1,554
  • 1
  • 22
  • 34
  • 1
    You should not rely on this kind of order. I don't know what problems are related to this in your project but please check this: http://stackoverflow.com/questions/480007/does-getcustomattributes-preserve-the-attribute-order-in-net – Peter Porfy Jan 06 '16 at 10:38
  • So Webforms? Or WPF? Or MVC? I think it's web forms but I suppose it could be WPF (not something I know a great deal about) – Liam Jan 06 '16 at 10:50
  • Yes, the problem is, even if you manage to maintain this order, your C# code is interpreted into CIL ([Common Intermediate Language](https://en.wikipedia.org/wiki/Common_Intermediate_Language)) which is then compiled into native. [The ordering of attributes is not guaranteed in any of these processes](http://stackoverflow.com/a/480079/542251). – Liam Jan 06 '16 at 10:53
  • 2
    Ultimately this is an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The issue isn't the ordering of the attributes, it's the fact you need them ordered in the first place. another solution is just to embed the scripts in the standard fashion (i.e. a ` – Liam Jan 06 '16 at 10:54

0 Answers0