为什么我的ScriptReference找不到嵌入式资源?

Iro*_*fin 7 c# asp.net assemblies asp.net-ajax embedded-resource

我有一个AJAX控件项目,它有一个.js文件,配置为嵌入式资源.

我的主Web应用程序引用此项目,当我尝试加载控件时,我收到此错误:

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

这是我对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 };
}

我不太确定我错过了什么.我已经尝试将Name参数更改为文件名,命名空间和文件名,命名空间,程序集和文件名......我没有任何运气.任何建议都表示赞赏.

Bra*_*ery 9

您必须在包含嵌入资源的程序集的代码中定义Web资源.通常,您可以在AssemblyInfo.vb或.cs文件中执行此操作.

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

如果您需要更多帮助,请参阅此文章.