asp.net Images not loading after publishing - c#

My images won't load after I publish my application. They do load when I'm debugging. Any idea what can cause this problem?
<a class="navbar-brand" href="#Url.Action("SearchQuery", "Search")"><img id="logo" src="~/Images/Logo.png"/></a>

Steps to add images to be published:
1) Right click the images folder and select "Include In Project"
2) Now you should see Build Action: Content on the properties for the images.

Try Url.Content on your src attribute:
src="#Url.Content("~/Images/Logo.png")"

Are you sure you have set the Image folder to be deployed along with your other files (Folder --> Properties --> Build Action)?
For further information please take a look at:
https://msdn.microsoft.com/en-us/library/ee942158(v=vs.110).aspx#Anchor_1

Please check your publish code because of after your publish this image not appear in particular folder. may be issue of publish.

Maybe you do add image to your development folder (via explorer etc) but not to your project. If an image file is not included in project, this will happen.
If this is the case; please check if you can see logo.png under Images folder with an image icon in Visual Studio's solution explorer. If it's not there try checking "Show All Files" in solution explorer's toolbar. Then try right click -> Include In Project. After that, publish will copy the file to output folder.

THIS may help.
I had the same problem - image loading at debugging in VS/IIS, but not after deployment on another computer.
Did all that was advised here and elsewhere.
After hours of searching and not finding any answers, I came across the most fundamental solution.
Turned out, it was my fault, being too hasty with the windows features setup.
You need to turn on static content for WWW services, as it is described in the linked answer, and as was probably mentioned in every tutorial ever, which obviously I missed.
Hope that helps someone.

When a image wont load, always be sure to inspect the network tab within the dev tools.
I had a problem where images with a specific folder wouldn't load after upload. Turned out that I had adblock installed on my pc and the folder was named Adverts. duh!

Related

C# Couldn't process file xxx.resx due to its being in the Internet or Restricted zone or having the mark of the web on the file

I have an issue while I try to build project in VS2012.
It cannot build due to the error:
Couldn't process file xxx.resx due to its being in the Internet or Restricted
zone or having the mark of the web on the file. Remove the mark of the web if
you want to process these files.
Here is a similar question.
but I tried that option and had no luck, because I did not download the file from the internet. That project was built from scratch. In project after selecting Properties, in Windows Explorer nothing happened. I do not have the "unblock" option, only the default three options (read only, hidden, and archived).
I have the same error and cannot build or rebuild the project. I have a theory that it is a recent error after updating Windows. Before the update, everything worked fine. Any ideas?
Go to xxx.resx file in Windows File Explorer. Right-click and select properties. At the bottom of the the dialog is an "unblock" option:
Check this and click Apply. Clean your solution and it will build.
In my case I had the same problem with many files.
My solution with VS Prof. 2017 V15.95 was:
Open powershell and execute dir -Path [directory path] -Recurse | Unblock-File
Rebuild all
On the solution folders locate abc.resx.
Open the file using any text editor, preferably Notepad++.
Locate and delete any node starting with <data
Example. This is what you should delete.
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAMAICAAAAEAIACoEAAANgAAAGBgAAABACAAqJQAAN4QAACAgAAAAQAgACgIAQCGpQAAKAAAACAA
AABAAAAAAQAgAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
///////////8AAB/////////
</value>
</data>
Reload or reopen your solution and build. You are ready to go.
Had the same problem after updating to VS 2017 v15.8.5, and none of the solutions above or on other forums worked for me.
So, since a .resx file is just XML, I just copied the content, deleted the original file and recreated it with the copied content.
That was the only thing that worked, and it worked first time.
A quick way to remove this mark of the web for multiple files and folders recursively for me was to
Zip them up.
Delete originals.
Unzip.
I'm not really sure either, I have the exact same issue.
But, what i did, was hit view in file explorer.
Then, i clicked show hidden items.
Finally, i went back to my folder and clicked on the .vs folder, my project/file name, v15, Server, sqlite3, and deleted DB.Lock.
I reopened the project, clicked build, and it worked perfectly.
This worked for me, it might/might not for you.
I also encountered this issue recently. The error began occurring after I set the icon of a Windows Form.
Researching for the cause and solution almost led me nowhere, because I did not download the icon from the internet, nor was I referencing a web-based icon file. It was stored entirely on my local machine.
After some more researching and digging around, I was able to figure out exactly what was causing the problem. I have Microsoft One-Drive installed on my machine. The directory in which the icon file was located is managed/synced by One-Drive. That fact was somehow tricking Visual Studio into believing the file was located or downloaded from the internet.
The solution proved to be very simple. I removed the icon from the form, as well as from the corresponding .resx file. Then I moved the icon file to another directory not associated with One-Drive. Finally, I was able to use that icon in my Windows Forms application without getting this error.
I understand there are other possible causes for this error. But if in your case, the issue happened after setting a form's icon--and if you have One-Drive (or perhaps another cloud-based storage solution) installed--then check to be sure that icon file is not in a directory managed by that service. If so, relocate it and change the form's icon property to point to the new location.
To fix this for multiple files within a project, Visual Studio -> Tools -> Options -> Trust Settings and add the project path as a trusted path.
Using VS 2019, and building against source stored on an Azure shared file system. I think I may have just tracked down a work-around, and it has to do with the Icon as referenced above by Jake above. If I add the icon to the form's resource file (that really long string), The error occurs.
However, if I add the Icon to the Project's resources, delete the Icon from the form's resource file, and change form to set the Icon manually...
this.Icon = MyProjectName.Properties.Resources.MyIcon;
The error goes away.
I found this solution on another forum. My project resided on a file share, so I had to enter file://[file share] for Step 4 below. I am running VS2019 on Windows 10.
Start Menu > type 'Internet Options'.
Select Local intranet zone on the Security tab then click the Sites button
Click Advanced button
Enter file://[computer name] or file://[file share]
Make sure 'Require server verification...' is unticked
I had the same issue in Windows 10 VS 2019 16.4.457 (previous version of VS 2019 had no problems).
The "marked for web" error shows only after I moved the project under One-Drive.
If I move the project back to a local drive the error doesn't show.
As Anthony Gingrich suggested, I tried to move the project images to a local directory without success.
The solution that works for me was, for each image, in the "Select Resource dialog" use "Project resource file" instead "Local resouce".
Please guys, I already fixed the issue, this is cause by OneDrive, please close your OneDrive with the use of task manager or close the icon OneDrive's Hidden Icons on the taskbar
I just ran into the same issue and also tried the Unblock option from explorer with no luck. I even restarted VS with no luck.
However, I'm not sure which combination did the trick but I opened the form as well as the resx file from within VS, just to see if I can open it, which opened fine. I then did a clean and rebuild and that appeared to do the trick. If it doesn't try restarting VS after the clean then rebuild.
I had a similar issue and the problem was an image that I had downloaded and added to my Resources. Not completely sure why that was the only image that gave me problems, however, I opened my abc.resx file giving me issues an a text editor, removed the node starting with " (it was the last and only node) just like Albert Alberto mentioned. Saved the changed, cleaned and rebuilt my solution and it all works! The image didn't render but it only took a second to go back and add the image. It wasn't removing the entire file, just the node that was causing the issue.
I had the same problem on Windows 10, VS 2017 (15.9.13). I sent myself a project from work through Dropbox so I could try a couple of things from home. But when I tried to build it VS gave me the 'marked for web' error.
After trying the solutions above without success I began experimenting. I was able to solve this by using the method listed above (right click -> properties -> unblock), but I had to do it for each of the images in the Resource folder--and I had to do EACH FILE individually since the 'unblock' option was not available on group-selects. I actually unblocked each source file in the project as well before trying to rebuild so I am not sure if both are required.
Its a bit of a pain--probably a huge pain for larger projects--but it absolutely got the project building again.
EDIT: I did find this article afterwards about unblocking entire folders--even recursively but have not tried it: https://www.winhelponline.com/blog/bulk-unblock-files-downloaded-internet/
None of these worked for me. I fixed it by converting the embedded base64 into a linked resource:
I found out the issue was with the embedded base64 image I had in the .resx (as the issue went away removing the data tag as explained in this question but that meant I removed the image) so I converted the embedded image into a .png file and made a link to that in the .resx.
To do that: open the .resx file in Visual Studio 2019 and double-click the image, and then click Ok and Yes in the following prompts that will appear so VS will convert the embedded image into a linked resource (sorry I can't upload pictures yet):
Hope it helps!
From my original comment.

Why images in drawable folder are not showing in my Android compilation of Xamarin.Forms?

I try to compile my Xamarin.Forms app and the images in the drawable folder can´t be loaded... The screen shows all the elements except images or icons.
I also get the error that says "obj/bin/debug/packaged_resources" doesn´t exist... It seems that this file is not being generated. I´m temporally avoiding this error by copy-pasting this file from another version of the app in my version control, but like I said before, images are not showing.
I have also checked the correct name of the image files to be compatible.
I have tried lots of purposes in Xamarin forums and cannot solve the problem. Any help would be appreciated. Thanks.
Please add the file with the help of "Add file" context not copying directly or dragging in to the resource folder..
Also rebuild the project after adding those image files..
I had the same issue. If you exclude image in one of the drawable folder and then include then it become visible in preview as well.

ASPNETCOMPILER(0,0): Error ASPRUNTIME: Object reference not set to an instance of an object

I'm Trying to publish a website, using Visual Studio 2013.
I'm getting an error:
ASPNETCOMPILER(0,0): Error ASPRUNTIME: Object reference not set to an instance of an object.
It happens also on Visual Studio 2010.
I tried to restart VS, and PC.
I removed *.dll.refresh from my bin directory.
I don't have <clear/> tags in my web.config.
I think it all started when I accidently removed my *.suo file.
Any ideas?
Update:
I just noticed it happens only when I try to precompile my site. If I publish without precompilation it works fine...
I also had this problem and it was not solved by any of the ideas mentioned previously. The problem was that somehow compresssion had been enabled on the subfolder of my drive containing the ASP.NET website. The solution is to right-click, choose properties and in the general tab, click Advanced and under the 'Compress or Encrypt attributes' section, make sure 'Compress contents to save disk space' is unchecked. Upon prompting do this for all files and subfolders (note it may take some time). Hope this helps someone.
OK.
After wasting so many hours I somehow got to this blog:
http://thesoftwarepractice.net/development-things/object-reference-not-set-to-an-instance-of-an-object
Turned off the McAfee Real Time Scanning and its works...
This is a hard to catch issues, which usually comes with webforms aspx pages.
If you are deploying the app with pre-compiled option and you have selected the "Do not merge, create a separate assembly for each page and control" here:
then you need to make sure that there are no compiled assemblies for any of the aspx pages in the bin folder of the project you are trying to compile. Go to your bin folder and delete any assemblies related to your web pages and try publishing again. This will fix this issue.
Have you tried creating a new website, adding all the files from old website to the new one and adding all the references used?
I also had this issue, and I fixed it by clearing and re-configuring all the dependencies and the dll's of the project.
I have deleted files from bin folder and then build solution and publish application.
It works for me.
In my case was only failing from commandline (msbuild), and from CI agents. The solution I've found is to disable the check "Allow precompiled site to be updatable in Project->Page Properties->MsBuild

Error while publishing an ASP.NET application

There is a web app I'm trying to make publish in order to upload it by CuteFtp Pro.
I usually being doing this with no problem. But this time, I'm facing crazy error! Actually, as I right-click the solution and click to Publish using File System option choosing an appropriate path for that, finally I got an Error:
Error
Copying file Images\512px-Icon_-_upload_photo_2.svg.png to obj\Debug\Package\PackageTmp\Images\512px-Icon_-_upload_photo_2.svg.png failed.
Could not find file 'Images\512px-Icon_-_upload_photo_2.svg.png'.
0 0 GiftShop
I really don't know and have no idea about this error since there is no file by the name of
512px-Icon_-_upload_photo_2.svg.png
In fact, I never had an image by that name through the project!! What could be the reason?
I'm really getting frustrated in challenging with that error.
Anybody could help me on this please?
Thank you so much
This basically happens whenever we delete the contents from the folder but forget to remove from Visual studio solutions.
To Resolve this follow below steps:-
Go to visual studio solution explorer and right click on the specific content
exclude(yellow marked files) from project.
right click and remove those files from visual studio solution explorer.
Hoping this will help you :)
Try removing the file from your project (right click and exclude).
search for the string name of file in all the files of the project. Remove the line and you are done.
Whats the best guess is that it must have been referenced in one of the CSS you are using especially if you are using Jquery or any of its plugin..
Do one thing exclude your obj folder from project.This is the best way for those kind of errors.
In your solution explorer there is one tab with tool tip "Show All Files".Click on it and it will show you all files.
There is one another way
Update: went into Project --> Package/Publish Settings, and clicked "Exclude generated debug symbols." The project began publishing with no issue.
one more solution for you
Are you seeing the file in the project? If so right click and tell it to remove the "ghost" file from the project. Once you do that I would try and publish again.
If its not showing the project, you might be able to create a fake file with the same name (just put some text in there so the size isn't 0kb) and in the same location as the other asp files. Make sure the "show hidden files is selected" and add it to the project and then promptly delete. This would essentially fix the corruption of VS thinking the file exist.
Hope it works.
Look into your solution and exclude this image file, but remember to click on Show All Files, and try to rebuild the solution.
Update 1
I ran yesterday with the same issue, it was an image not included in the project. Please go to Solution Explorer click on Show All Files and check 512px-Icon_-_upload_photo_2.svg.png image is included in the project or not, if it in gray color so it's not included in the project and if has a yellow icon please remove it from the project.

Images under "image/subfolder" cannot be found in the latest Razor Engine - MVC.NET

I am having a hard time in making images in my MVC.NET web application developed in Visual Studio 2012. To keep the story short, please take a look at the following two lines of code:
<img src=#Url.Content("~/Content/themes/construct/images/MyPic1.png") />
<img src=#Url.Content("~/Content/themes/construct/images/blog/MyPic2.png") />
Both MyPic1.png and MyPic2.png files do exist. However when rendering the page, the first picture which is MyPic1.png is shown but the second one which is found under "blog" subfolder does not show up. I used FireBug and it did not show any error messages!
What could be wrong and how to resolve it?
There is nothing wrong with your razor code, I did create the folder structure as you mentioned, both the images are loading as expected.
I suspect you might not have the correct file extension.
Explore the file, click Organize -> select Folder and search option -> select File (tab) -> uncheck 'Hide Extension for known file types' as given in below diagram and see the image extension.
Some time we save image with 'pic1.png.png' or 'pic1.png.jpg'.

Categories