7

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.

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Excellent! I figured that Assembly.cs file was good for something. Turns out it was in there, but I renamed the file, which didn't propagate through to here, so I just had to fix the naming and was good to go.
What does PerformSubstitution do?
2

Did you make sure to add an entry for the Javascript file into your AssemblyInfo.cs? Something like:

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

Otherwise, the assembly won't allow access to the resource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.