codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.92k stars 362 forks source link

Cleaning Up All Code option is corrupting png and jpg files in project references. #848

Open papashep opened 3 years ago

papashep commented 3 years ago

Environment

Description

I am fairly new to Visual Studio, CodeMaid and C#. The project I am using is from a Udemy Training Course and is not designed for production. The App.config is setup for encoding utf-8.

When I select the 'Cleanup all code' option of CodeMaid, when it reaches the image files in the Project References and my customer references I get the same error for each image file:

File Load

Some bytes have been replaced with Unicode substitutions character while loading file the file path followed by with Unicode(UTF-8) encoding. Saving the file will not preserve the original file contents.

This corrupts all .png and .jpg files in the References.

A rebuild of the project gives thousands of invalid token errors on the image files.

To recreate:

  1. Backup the project.
  2. Run CodeMaid Cleanup all code.
  3. Re-build the project.
  4. The attached zip file contains the project and a copy of the error message.

I do not understand why the Cleanup all code is touching image files repos.zip

codecadwallader commented 3 years ago

Thanks for reporting the issue and providing a code sample. I am unable to reproduce the issue (CodeMaid does not try to clean those files).

By default those files won't be recognized/open by CodeMaid. There is a configuration option that can be turned on to override that behavior which is intended for .txt and README files. Can you take a look at CodeMaid->Options->Cleaning->File Types and see if "Everything else" is selected?

image

Even with this selected I did not see the error message you saw, but it will cause CodeMaid to open those files during the cleanup process. I'm curious if just opening those files is causing that substitution to happen with or without CodeMaid.

If you open those image files in the editor without invoking CodeMaid do you see the same error message?