Posted: 5 years ago

Filed under: ASP.NET, Server controls

Tagged with: debugging webresource

Follow comments

The resource cannot be found.

I was playing around with embedded web resources and was having a problem loading some javascript files. When I cut and paste the script link from the source of my page into the browser’s address bar I got the following error message:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /SampleSite/WebResource.axd

I wasn’t sure if the error message was that WebResource.axd wasn’t being resolved or if the actual file wasn’t being found. It turned out that this is the error message you get if the WebResource.axd can’t find a resource and that it was the actual javascript file that wasn’t being referenced properly.

My actual problem turned out to be that I was referencing the resource wrongly where I was declaring it in AssemblyInfo.cs.

Comments

  1. mehdi Says:

    Hi,
    I’ve got the exactly same problem, using the embeded web resources. Would you please provide me what was wrong exactly in your case?

    Any help would be highly appreciated,

    Cheers,
    Mehdi

    P.S.:
    Here’s my contact ifo: (mehdi_mousavi@hotmail.com)

  2. Helen Says:

    In my case it turned out that I wasn’t referencing the resource properly when I was trying to access the file in the GetWebResourceUrl method.

    So I was doing this:

    this.ImgSrc = Page.ClientScript.GetWebResourceUrl(this.GetType(), “Elephant.jpg”);

    When I should have been doing this:

    this.ImgSrc = Page.ClientScript.GetWebResourceUrl(this.GetType(), “Examples.WebResource.Images.Elephant.jpg”);

    You can find out the exact names of your resources by iterating through the resources in your assembly and then you can cut and paste them into the GetWebResourceUrl() method:

    string[] resources = this.GetType().Assembly.GetManifestResourceNames();
    foreach (string resourceName in resources)
    {
    Debug.WriteLine(resourceName);
    }

  3. Jeroen Says:

    Hi Helen,

    I have tried your code to iterate through the assembly, but no resources seem to be available. How do I add a resource to an assembly?

  4. Helen Says:

    You need to add the resource to your project and then set it’s Build Action property to Embedded Resource.

    I’ve actually written out some step by step instructions about what you need to do on this page:
    http://webdev.helephant.com/blog/asp.net/webresourceattribute

Leave a Reply