.NET random assembly is modified on disk - c#

One of our applications is started suddenly terminate with error "Can't load file or assembly" . After some research I found that one of DLL files used by app is changed it's size by 1-2 bytes.
After playing more with it I realized that it's related to all dll files used by application and any of them can be corrupted. We have same copy of application on another box and it runs without issues. That makes me think it's related to environment.
How can I find what process and when modifies the file? What can be reason? Does this happened to any1?

If you have access to the computer where this is happening you can use FileMon to monitor the assembly files and find out which process is changing them.
This sounds suspiciously like some sort of virus or antivirus gone wild situation.

Related

C# dll I made sometimes gets "blocked" in the file properties when downloaded

I have a C# application that is available online for download. However, when customers download it, there is a one .dll that I created which SOMETIMES becomes "blocked" and needs to be "unblocked" by going to the file properties and clicking unblock. The.exe won't run because this. I cannot figure out why Windows decides to block it.
I know that I can programmatically unblock the file as well by using Unblock-File in PowerShell or Streams.exe. I also know that by editing the ZoneIdentifier of a file, I can MANUALLY block files in order to somewhat reproduce the issue. I cannot however reproduce the issue by download. I've tried downloading my program from the website in Win10 & Win7, and have even edited the "Do not preserve zone information in file attachments" in gpedit as well, all to no avail.
My question is, why is it that SOMETIMES my .dll gets blocked when downloaded from the internet? How can I prevent this block from happening, by digitally signing the dll?
Am I doing something wrong when I package my C# solution? Is there a way to reproduce a particular download from being blocked?
I don't know the reason. As far as I know, if you download any unknown dll or executable (specially in Chrome), it will be blocked and you can't use that binary file in your project until you unblock it.
Solution: Take dll and whatever you have in a zip or rar file. Then download and extract the zip file in the customer system.
Even some Microsoft binaries are delivered in zip format. Consider looking at Process Explorer.

System.UnauthorizedAccessException while deleting dll (C#)

Please read carefully: I know that dlls can be in use. I also know about NTFS permissions, and read-only flag.
I create a text file with content hello.
I rename it to .dll
I try to use File.Delete(...) method to delete it: I got
System.UnauthorizedAccessException
I try to open it with File.OpenWrite(...) I got the same exception.
I've turned out all virus checking software.
I am admin in my Windows 7 machine.
I am the owner of the .dll extension file
I can it delete without any warning from the UI.
Using VS 2012 C# program (.NET 4.5)
Any ideas?
Thanks
SOLVED: (partly): This was my firewall :-(. Somehow it cached and sandboxed my project output executable, and restricted to delete .dlls (not .txts). Although I turned off it, and I rebuild the .exe many times somehow the named exe sandboxed state remained active. I stress it was a many times rebuild and binary changed .exe. Congratulations to Commodo just 2 erratic behaviour in on issue. 1) Why the sandboxing is still active if antivirus has turned off? 2) Why not reevaluate the named .exe file and asking me about sandboxing if the binary has changed? How this is turned out? I renamed the project output to x.exe :-(
This was more the 45 minutes from my life and worktime...
For delete try
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);

Replacing a dll in a SilverLight application (xap) for the purpose of sniffing traffic

I'm trying to understand how a Silverlight app communicates with its server. Communication is encrypted. I would like to see how messages look like before encryption. I came up with this idea: when browser requests the .xap file, I serve a version containing a patched DLL that does not encrypt anything. I created this DLL by patching C# code with reflexil.
What tool should I use to deliver this patched .xap file? Fiddler? Only one file needs to be replaced, all other requests from the browser should go to the original server.
Is there a simpler way of doing this? For example, does anyone know, where exactly DLL files from .xap files are extracted? How are they loaded? Perhaps it's easier to find where they get extracted and patch the already unpacked version? I used process monitor, but IE seems to be unpacking XAPs in memory.
EDIT:
I did not create the application, that's the problem. I want trick IE into loading a patched version of a DLL from the original XAP.
Don't exactly understand what you are trying to achieve, but with regards to your last question on unpacking XAPs, you can access the downloaded xap files in the following location
C:\Documents and Settings[UserName]\Local Settings\Temporary Internet Files\
rename the package to .zip instead of .xap, unzip, and access your dll there?

File.Copy fails when copying a DLL that is not in use

I've built a winforms app (C#) that will take a list of file paths, and copy those files (from a different VS solution) to a new location (In a folder the user specifies) in the same directory structure they currently exist on local file system.
I use the Path class, Directory class etc and everything works wonderfully...except when it reaches a file path that points to a DLL.
The DLLs I am trying to copy are a part of the other solution, and that solution is not currently open.
I have tried restarting computer to make sure visual studio isn't somehow hooking into that DLL even after the solution is closed.
The DLL in question can be copied by regular manual means (i.e. copy and paste shortcut).
So short of creating a batch file in the program, and running xcopy on that DLL path, I don't know of a way to get this to work.
From what I have found from google searches (which isn't much on this particular situation), File.Copy() should work..
Any help would be wonderful, even if it is a link to a duplicate question I may have over looked.
Thanks!
-The error message is: The process cannot access the file [insert file path] because it is being used by another process (The path is definitely correct also)
-Just downloaded and tried to search for the DLL name with Process Explorer.. I also ran a similar exe from command prompt to no avail. It claims nothing is using it. That's why I am utterly baffled by this. Also, I just checked the permissions and everything looks great (i.e. Full Control, owner effective permissions)
-It does not handle open files. It basically build the correct src and dest paths and does a File.Copy() on those. How would I go about handling open files? I'm sure I could figure out if it was open, but what would I do it it were open?
It is not complaining about the file you're trying to copy, it is complaining about the file that you're trying to overwrite with the copy. Lots of candidates for that, virus scanners always get very excited about new DLLs, for example. Or it is loaded into a process, the typical failure mode for trying to implement your own auto-updater.
You can rename the target file to make your copy succeed.
Are you in vista or win7? If so, Check your 'User Account Control Settings'. Sometimes this can interfere with .NET security options and prevent file operations that would otherwise work.
As well as Process Explorer, I would use Process Monitor also from Microsoft so you can see what is happening at the point of failure and allows you to see if anything else is accessing the dll.
Possible culprits are
the program you are running,
your antivirus package
a virus.
If the path it is complaining about is the destination path, then is is possible that the path is too long?
Also, when using Process Explorer, make sure you have enabled the option to show details for all processes and not just your own.
I just ran into this issue as well. I tried copying a .DLL from an FTP server to a local directory (replacing the existing one) and for the life of me I could not get it to work. Keeps giving me an 'Access Denied code: 5' Error.
I then realized that the .DLL on the FTP server was not marked as hidden while the .DLL I was trying to replace was marked as hidden.
Once I changed the local one to also be visible. I had no more issues.
So my solution is:
Make sure both files are visible.
Hope this helps someone

.resx File Size Issue

I am working in Visual Studio 2010, on a fairly beefy machine. I have a solution with a few different projects under it like so
Solution
Activations
DatabaseManager
Library
VideoResources
WindowsNewUI <--- start up project
In video Resources I have one .resx file in which I have placed about 700mb of compressed videos. When I build this project by itself, the build succeeds. Then I hit f5 to run my new UI and I am given this error.
Error 1 Unexpected error writing metadata to file VideoResources.dll -- 'Not enough storage is available to complete this operation.
I have done some digging and it seems to be a ram issue. I have tried the /3gb fix by editing the .ini file, but this does not solve the problem.
My question is what the heck am I doing wrong here, I know that 700mb is a lot of video, but there is no reason that that specif project should build, but then fail the rest of my project, is something else going on here? Does the access modifier of that projects resource file mater? How can I resolve this issue?
Also if I place about half of my video files in the .resx then everything works just fine.
My suggestion would be to not store the video in any type of embedded resource. Thats going to cause your app to us a ton of memory while it is running. I would suggest that you instead just leave the files on disk and load them from there. This would also fix your problem.
The resource file infrastructure is probably not designed to scale to these file sizes. Remember that every operation in a resx file happens in memory, and you're using a garbage-collected language.
Why not just store the video(s) in the filesystem and read them as needed?

Categories

Resources