Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my ScriptReference find the Embedded Resource?

I have an AJAX control project that has a .js file which is configured as an embedded resource.

My main web application references this project, and when I try to load up the control I get this error:

Assembly does not contain a Web resource with name 'MyFile.js'.

Here is my implementation of getScriptReferences:

public IEnumerable GetScriptReferences()
{
    // create reference to the JS
    ScriptReference jsReference = new ScriptReference();
    jsReference.Assembly = "MyNamespace";
    jsReference.Name = "MyNamespace.MyFile.js";

    return new ScriptReference[] { jsReference };
}

I'm not quite sure what I'm missing. I've tried changing the Name parameter to be just the file name, the namespace and file name, the namespace, assembly, and file name...and I"m not having any luck. Any suggestions are appreciated.

like image 283
IronicMuffin Avatar asked Jan 26 '10 23:01

IronicMuffin


1 Answers

You have to define the web resource in code on the assembly that contains your embedded resource. Typically you would do this in an AssemblyInfo.vb or .cs file.

[assembly: System.Web.UI.WebResource(
      "MyNamespace.MyFile.js", 
      "text/javascript", PerformSubstitution = true)]

See this article if you need some more help.

like image 175
Brandon Montgomery Avatar answered Oct 21 '22 05:10

Brandon Montgomery