Why does my ScriptReference not find the embedded resource?

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

My main web application is referencing this project, and when I try to load 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 am missing. I tried changing the Name parameter to just be the file name, namespace and file name, namespace, assembly and file name ... and I was out of luck. Any suggestions are welcome.

+7
c # embedded-resource assemblies asp.net-ajax
source share
2 answers

You must define the web resource in the code on the assembly containing the embedded resource. You usually 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 more help.

+9
source share

Have you definitely added an entry for the Javascript file to your AssemblyInfo.cs? Something like:

 [assembly: WebResource("MyNamespace.MyFile.js", "text/javascript")] 

Otherwise, the assembly will not allow access to the resource.

+2
source share

All Articles