Visual studio 2010 empties the file on crash - c#

I got a really bad problem while working on visual studio 2010. Accidently the power plug switched off and when I started the computer again the file was completly empty. I tried out following things:
I opened it in notepad and other couple of editors and it was empty.
I then opened it in Hex Editor. Hex editor shows that all bytes are set to 0.
I programatically read the file and it also showd all bytes set to 0.
Checked "Documents\Visual Studio 2010\Backup Files\" for my project and it was empty.
The file size is still showing in KBs but the code is completly gone.
Is there any possible way by which I can recover my code?
If there is not, can anyone suggest me a setting/patch taht should be there so that it never happens again.
Note: I already have Autorecover option set for every 5 minutes in IDE.
Update:
As suggested by Henok, If you have compiled and built the code at least once, you can reverse engineer the binary through reflector.

Doesn't look like it, to stop in future though, save and save often. Also look at using subversion like svn, or Git.

IIS has DLLs cached under C:\Windows\Microsoft.NET\v4.0.xyz\Temporary ASP.NET Files. Look for the dll and use a reflector. I use ILSpy.

Save often and use source control. I use C.V.S., personally.
It sounds like the I.D.E. had the file(s) open for writing at byte 0 when the computer went down, clearing everything out.
Beyond your software problems, I suggest you manage your power plug in such a way that it won't be accidentally switched off.

Same thing happened to me and thought I would post it here for those who would come here for answers.
If you have compiled and built the code at least once, you can reverse engineer the binary. Reflector did the trick for me.

Visual Studio still makes source files empty on sudden crashes, so I think I should share my solution.
Use any cloud file syncing service that supports file versions (for deleted files, too). Dropbox and Google Drive is what I can name. I randomly preferred Google Drive, though Dropbox can do all the same things.
I simply put my source tree in Google Drive, because it has file versions. My builds happen in Google Drive too, so there's much of unwanted traffic for big projects, but you can exclude some subfolders from syncing.
The drawback is that sometimes (in rare cases) Google Drive locks files and Visual Studio pops up "Save As..." dialog or some messages. You can usually close it, then save again successfuly. In very rare cases I had "The file is used by process" errors, and I had to restart Google Drive.

Related

Programatic truncation of large file names (zipped) for different Windows editions

So I'm bugfixing on a program that allows a user to create an Excel document, which it first zip compresses before serving to the customer. One of the client complaints is that, while the zip file can always be downloaded, sometimes the user must copy the Excel file out of the archive (or extract it) before opening it, using the standard Windows compressed tools. Standard "File name too long" error.
The algorithm is, of course, setting the .zip archive name to the same as the report - which can be 100+ character long strings.
The solution I'm implementing is to check the length of the potential report to see it if it violate MAX_PATH, naturally, and truncate the .zip name as needed.
Testing it on Windows 7, this works perfectly. But something odd happens when testing it under 8.1
It still throws an error trying to open from the archive - but this error is a bit more enigmatic.
"Sorry, we couldn't find C:\Users{My user name}\AppData\Local\Temp\Temp1_{Rest of the truncated archive name}.zip{Full file name}.xlsx. Is it possible it was moved, renamed or deleted?"
This error keeps popping up, regardless of whether the file is "Open"ed or "Save"d from the browser.
Normally, I'd just try further tweaking, but testing on the Windows 8.1 platform involves a lot of overhead at the moment, and it doesn't look like the problem is the path name length.
What is going on? Does Windows 8 have problem with the length of names within archives, or...?
Also, the reason I am posting this here, and not, say, User Experience, is because I feel like the solution will be programmatic - something in the code of the program. I readily concede that "allow the end user to skip hitting the Extract button" is about providing an easy user experience, but truncating the length of the entire path solved the problem on Windows 7.
Just not 8.1, and googling/searching the SO site family provides no help - ironically, because of the keyword Excel.
So, as I found in the link above (http://answers.microsoft.com/en-us/office/forum/office_2013_release-excel/sorry-unable-to-find/595333d0-1463-499f-967e-4da8ac2e2047?auth=1) the crux seems to be that, although MAX_PATH is 260 characters, Excel 2013 can't handle anything over 212.
I still haven't been able to give this the rigorous testing it deserves, but if anyone else encounters this problem, and finds this page in their quest for a fix, just truncate until the entire path is under 212 and you should be good.

visual c# button opens file without specifying drive

I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.

anksvn checkin file

I am using the most recent version of anksvn for a visual studio 2008 project file. I now
want to check this code into anksvn, but I am having a problem.
The situtation is, I checked in the most current version of code into anksvn. That is fine.
However I have another version of this code that I did not check out from subversion initially. This other copy of the code was for a 'demo' only. However now this code needs to become the production code. Thus I am trying to determine how to check this code into anksvn.
What I know I can do is to 'remove' the most curent code folder that is in anksvn. I could then place this project folder into that location. since the origianl 'demo' code also includes the current production code.
However I am trying to see if there is a better method to accomplish this goal. Could I possibly use the branch/switch option?
Is the demo code checked out of Subversion at all? I know you didn't check it out, but was it checked out? If it was, you could commit this code back into Subversion, then update your working directory.
It his code has nothing to do with Subversion, you will have to take a more complex route: You will have to copy the changes manually to your code.
Since you're using Windows, you should take a look at Beyond Compare, This is commercial code, but you can download a limited time demo for free -- more than enough time to handle your situation. I use Beyond Compare all the time to compare two different directories or Java jar files or zip archives, etc. It not only can quickly show you the differences, but makes it each to copy those differences from one to the other.
I have no relationship with Scooter software, the makers of Beyond Compare except as a customer.

How to turn off encrypting of .sln files in Visual Studio on removable drive?

Problem description:
(occurs at least in VS2005 and VS2008, not tested in VS 2010)
If project (e.g. .csproj) or solution file (.sln) is opened from removable drive, and something happens ... seems like if drive is disconnected without safe removing, or if computer crashes or if VS crashes, then project and/or solution files got encrypted. It seems like Visual Studio encrypts project files when opened and only decrypts them when Visual Studio or project is correctly closed. If something unexpected happens, files remain encrypted.
It is Toshiba hard-disk in these cases, but occurred to me also on other removable hard drives or USB keys.
This is not a problem, until disk is connected to the same computer (files are encrypted, so they can be opened only by Win user that encrypted them). But when disk is connected to another computer, or even worse ... when Windows installation gets corrupted, then the project files are no more accesible.
Is there some way to turn this functionality off? Or is it a bug and needs to be solved just by "not using removable drives"?
I am not aware of any inbuilt encryption for either solution or project files, and I quite often move projects around on USB stick. It is possible that this is being provided by some service on your computer, or by the disk itself - but I wonder if a more likely explanation is simply file corruption or a damaged disk.
I know this is an older post, but just to add to this...
I'm running a machine with Windows 7 Professional x64. Last night Windows lost communication with my RAID Controller out of nowhere (can't tell if the RAID controller or Windows was the cause, not enough in Event Viewer to deduce). Once this occurred, the Volume vanished from Windows Explorer (makes sense).
Windows then popped up a message in the System Tray informing me I should backup my personal certificates (PFX file) somewhere since I haven't done so in a while. I ignored this step, since I never use anything that would require personal certificates (no EFS or anything like that), so I shut down since everything was screwed at this point (Page file is on the volume that went bye bye)
Upon a reboot, my RAID array checked out fine, so I booted into Windows starting it normally and not going into Safe Mode. Voila, everything is back to normal again, or so I thought...I'm experiencing the same issue similar to here and that posted at http://www.dreamincode.net/forums/topic/277832-projects-became-encrypted-when-i-used-ext-drive-on-laptop-now-what/ as well.
So between these posts, we can deduce (possibly) that Windows does not fair very well with Removable Media, or Volumes that go-away all of a sudden without a clean dismounting.
I'm not sure why this would cause our files to start having the Encrypted attribute applied to them though, that's still the mystery...Unfortunately I think we're just going to be left wondering since this is probably way under the hood of Windows in WinFS, HAL, or one of those untouchable abstraction layers.
Hopefully this additional insight might help others out there figure out WTF is going on with this.

C# application detected as a virus

Regarding the same program as my question a few minutes ago... I added a setup project and built an MSI for the program (just to see if I could figure it out) and it works great except for one thing. When I tried to install it on my parent's laptop, their antivirus (the free Avast Home Edition) set off an alarm and accused my setup.exe of being a Trojan.
Does anyone have any idea why this would be happening and how I can fix it?
Indeed, boot from a clean CD (use a known good machine to build BartPE or something similar) and scan your machine thoroughly. Another good thing to check, though, would be exactly which virus Avast! thinks your program is. Once you know that, you should be able to look it up in one of the virus databases and insure that your software can't contain it.
The odds are that Avast! is just getting a false positive for some reason, and I don't know that there's much you can do about that other than contacting Avast! and hoping for a reply.
I would do what jsight suggested and make sure that your machine did not have a virus. I would also submit the .msi file to Avast's online scanner and see what they identified as being in your package. If that reports your file as containing a trojan, contact Avast and ask them to verify that your .msi package does contain a trojan.
If it doesn't contain a trojan, find out from Avast what triggered their scanner. There may be something in your code that matches a pattern that Avast looks for, They may be able to adjust their pattern to ignore your file or you could tweak your code so that it doesn't trigger their scanner.
I don’t know “Avast”, but in Kaspersky if the configuration is set to high almost every installer fires an alarm (iTunes, Windows Update, everything) especially if the installer modify some registry key or open a port.
If avast checks for behavior and your program open a port probably that’s be the cause.
Rebuild the setup file, check the exact file size.
Check the exact file size of the "suspected" setup file.
If the source code hasn't changed and the two file sizes are different, there's a pretty good chance it got contaminated in transit.
I'd do that as a bit of a sanity check first.
The very first thing to do would be to scan your build PC for viruses.

Categories