WinForm DPI issue - c#

There was this issue:
WinForm looks different than in VS designer
I thought I solved with this one:
https://stackoverflow.com/a/13228495/1806838
I used the app.manifest one.
<dpiAware>true</dpiAware>
After that all seemed to be OK. It looks perfect if I debug or if I run the application from the folder where I build it. (app\app\bin\Release\app.exe). But if I copy the executable outside that folder (for e.g. to my Desktop, and I run it then it looks like this (the right one obviously):
It's like the app.manifest is not embedded, but I checked the settings and it seems to be OK. Also, I made sure that in the app properties the correct manifest file is being selected.
Any ideas?
EDIT: So, it seems if the app.exe.manifest is in the same folder then it looks good, otherwise it's not.
EDIT2: I found that I have 2 app.mainfest files. One is app\app\app.manifest and the other one is app\app\Properties\app.manifest. So I deleted both and added a very new one having the DPI setting in it. I still have the same issue. Checked the app.manifest properties and the Build Action is set to None. Shall I change it?
EDIT3: I addedd app.manifest to the Resources and set app -> Properties -> Manifest to be Resources\app.manifest. Still the same.

So, after trying to compile the app.manifest for 3 days, I added another setting to see whether it's going to be applied. This was the run as admin:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
And when I tried to build with that I got an error message stating that it's not compatible with ClickOnce. And this was the point when I realized what a moron I am. After disabling ClickOnce via app -> Properties -> Security -> uncheck Enable ClickOnce security settings everything is just working perfectly. It seems that if it's enabled then it ignores the manifest.
I'm really sorry for the time of people tried to help wasted.

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.

"Error while trying to run project: Unable to start program". Can run program only once. Then VS needs restart

I'm running my .NET 4.0 (C#) project in debug mode after I start VS2013. It runs just fine.
The second time I start it from VS, I get the Dialog box that says "Error while trying to run project: Unable to start program C:\path\to\file.exe"
The process is still alive in the Taskmanager when I dismiss the dialog box.
From Windows Explorer, I can run the program just fine. And after closing it, the process is gone too from the Task Manager.
A rebuild doesn't help.
Is this a common problem with a known solution?
I had an issue similar to this and I had to clear the component cache instruction can be found Here.
Hope this helps.
For my case, it cause by Platform target, you could force choose it to x86 or x64 which your project is:
Each Project's Properties > Build > Platform target
As I pointed out also here, the only solution that worked for me was to disable the ConEmu integration:
ConEmu &rightarrow; Settings &rightarrow; Integration &rightarrow; Default term &rightarrow; disable Force ConEmu as default terminal for console applications
Some users reported that it was enough for them to disable the Aggressive mode in that same settings tab; that wasn't the case for me though.
The topic is old, but this might help someone else.
So in my case I made a file in Visual Studio with .cp extension (accidentally deleted the last 'p') this made visual studio just "include" the the file and not mark it as a compilation unit, thus not compiling it, I looked the *.vcxproj file in a text editor and found out about this, so if you open the project file in a notepad or something just find your file at the bottom usually and change from <Item .../> to <ClCompile .../>
I was getting similar errors. I just had to restart visual studio. Sometime couple times a day.
I had a similar error and resolved it by cleaning the solution. Right-click the solution name in Solution Explorer and choose Clean Solution.
I found a solution here:
Please check "Use Managed Compatibility Mode" under Tools|->Options->Debugging->General.
I'm Brazilian, I don't speak English very well. I did this translation on google translator.
I know the topic is old, but it can still help someone.
I had this same problem in the following situation, I have a dual boot computer (linux debian 11 and windows 10). Inside debian, on my NTFS D disk, I created a folder to perform programming tests. After accessing that same folder with windows, I created a new project in visual studio inside that same folder that I had created in linux. The creation of the project went without problems, however when I tried to run the project (F5), I received the same error from this topic. I tried all the solutions I found on the internet, and nothing worked. I gave all permissions to my admin user and it still didn't work. Then I realized that even going straight to the folder where the application's executable was and clicking directly on it, I still received the access denied error message. So, I took the project out of the folder I had created in linux, and it worked. So, what I could conclude, is that because the folder where my project was was created in linux, for some reason, my windows didn't trust this folder, so it didn't allow running executables from inside that folder, even this one executable having been created by visual studio from within windows.
Just simply create a folder name as "projects" in c drive and copy paste the newly created project in it. Run the project by doing clean & Build or Rebuild method . It will work
open the folder which contains the solution in visual studio.
again, open your *.sln file by double clicking it inside the solution explore once opened try running the solution or rebuild the solution. once rebuild gets completed, it will open without error from next time.
My way of solving the error : error while trying to load project : Unable to start program and c:\Path\to\file.exe was simply by
First restart Visual Studio
Click the build icon
Select the rebuild option
Run the Program or Debug the Program
This was a weird one. Going to put what happened to me here because it might happen to someone else. Everything was fine with the app until suddenly after some fairly insignificant code changes I suddenly started getting this error. Visual Studio was compiling the executable just fine. But, the moment I tried to run it (either from Visual Studio or directly) the executable file would be automatically deleted right out of the Debug folder. Super odd--never seen anything like it. I began to get suspicious that perhaps an anti-virus or the OS was somehow identifying a checksum or some signature in the executable as "dangerous". Or perhaps some obscure compilation bug was corrupting the executable. So on a hunch I made another innocuous change (added a couple of lines of code to color code some text in a rich text box) and the problem went away.

Why is VS2015 generating old/incorrect app.exe.config file?

I'm working on a windows service and using SlowCheetah to manage the transforms. I added some settings and therefore updated the app.config file for the first time in months, and for some reason when I build the Debug configuration it generates an old version of app.config with a modify date from six weeks ago (Jan 3rd.)
To make matters worse, looking through the source control history it doesn't look like the file was ever checked in with the changes that are showing up when I build. That is, one setting is set to a different url for me to test something... but that was never checked in.
If I build in Release or Test configurations it works perfectly.
I've tried:
cleaning/rebuilding the solution
Deleting/recreating the the app.config file (It generated the 1/3 version even - when I build with file deleted!)
Restarting Visual Studio
Rebooting my computer
Nothing works and none of the changes I make in the config file are reflected when I build Debug.
Any ideas why or how to fix it?
Did you try looking at the post build section? Sounds like something there is overriding the built version with a previous one.

ASP.Net 5/MVC6 Razor views not updating with changes in browser unless I restart IIS Express

I currently have an MVC6/ASP.Net 5 project. I "start without debugging" and the app loads in the browser. I can make changes to .cs files and recompile and they show in the app.
However, when I make any changes to razor files (*.cshtml) they don't show at all. I have to kill IIS express and re-launch in order to get the change to show. The rest of my team is working on the same code base/solution and it is working fine for them.
I have updated to VS SP1, and re-installed the tooling. No luck.
Please help!
Most probably you have the .csproj MvcBuildViews property set to true. To check, unload the project (right-click it) and then edit it with the text editor.
The property gets rid of the "lag on first visit of view", but increases build times (and startup times) as well as introducing situations like this.
If you have it enabled, only enabling the property on Release (and not Debug) configurations might help:
Replace the <MvcBuildViews>true</MvcBuildViews> with the following:
<MvcBuildViews Condition="'$(Configuration)'=='Debug'">false</MvcBuildViews>
<MvcBuildViews Condition="'$(Configuration)'=='Release'">true</MvcBuildViews>
---------- EDIT ---------
Actually, sometimes this is not enough. Most probably (after the one above), you have the optimizeCompilations="true" attribute set on the <compilation> element inside <system.web> in your web.config.
If you don't want to remove that, you can periodically remove all the contents of this folder: %localappdata%\Temp\Temporary ASP.NET Files\vs (yes, you can enter that directly into the file explorer address bar)
Also, try the suggestion in my OP-comment:
A temporary rescue is to add a cache-buster to the browsed URL
(?nocache=1, 2 etc) and at the same time introduce a Razor c# syntax
error. Then, after reloading, remove the syntax error and the page
will be reloaded...
I had the same issue.
Closing Visual Studio and deleting .vs folder in the solution directory worked for me.
I think my IIS Express's configuration was corrupted. This may be why it worked for me.
It's a bug, and I found an answer to this that solves it here on StyackOverflow.
Other Stack article here
Try clearing out your IISExpress cache / application space:
https://gyorgybalassy.wordpress.com/2013/12/02/cleaning-up-iis-express-configuration/
It's worked wonders for me before.

Can I set the properties of an exe file via C#?

I am using Unity to build my game. I need the application to always run as administrator.
When I build my game, I right click on the exe that is produced and set 'Run this program as an administrator' on in the Compatibility > Settings section of the exe properties.
I can write an editor script (C#) that'll execute after a build has completed. So I was wondering if I could automate this step so that I do not forget to do it every time I build?
I'm not sure if this solves your issue.
But you could add an "Application Manifest File" and configure:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
With this configuration the user gets always a UAC promt.
Do not have a ready made solution but i can give you an idea:
Have a look at this, using this way you can check if your application is running as an administrator, if no, it starts another process with administrative privilege and you can later call:
Application.Quit();
to terminate the current instance.
Other than this you must have to wrap this code under platform dependent compilation.
I know it is not a best solution, but can fix this issue.
Hope it helps!

Categories