繁体   English   中英

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

[英]Why doesn't my ScriptReference find the 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参数更改为文件名,命名空间和文件名,命名空间,程序集和文件名......我没有任何运气。任何建议都表示赞赏。

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

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

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

您是否确保将Javascript文件的条目添加到AssemblyInfo.cs中? 就像是:

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

否则,程序集将不允许访问资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM