简体   繁体   中英

How do I fix EmbeddedRessources in a ASP.NET web site?

I am trying to reference a js file in a class in an ASP.NET and I receive this error:

Assembly 'XXX' contains a Web resource with name 'XXX' but does not contain an embedded resource with name 'XXX'

Searching the web tell me I must have a Path referencing problem, but I can't figure what is it.

Here is the hierarchy

<Root>
   <App_Code>
      <Application>
          <MyClass.cs NameSpace="None" />
      </Application>
   </App_Code>
   <JS>
      <MyJSFile.js NameSpace="MyControls" Name="MyJSFile">
   </JS>
</Root>

So in MyClass.cs I have :

[assembly: WebResource("MyControls.JS.MyJSFile.js", "text/javascript")]

[ClientScriptResource("MyControls.JS.MyJSFile", "MyControls.JS.MyJSFile.js")]
public class MyClass : ExtenderControlBase
{}

So I guess there is something I didn't get with the referencing : (RootNampeSpace).(Path).(FileName).(Extension)

My project is a ASP.NET WEB Site so I don't have properties for Build Action to set at Embedded Resources.

Also in the folder App_Code I get an error if I put my JS file saying that the language is not the same as other file in App_Code.

You would think this is possible, but honestly I can't find how. I may be just missing something really simple...

You always have one other option, which is to create a separate Class Library project, embed your resources there, and reference it from your web site project.

My project is a ASP.NET WEB Site so I don't have properties for Build Action to set at Embedded Resources.

I think that's your problem, that you can't really embed the resource, since there's no build step. What happens if you leave out the assembly attribute?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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