Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have the following code:
var test = _myDictionary.ContainsKey(myKey);
if (!test)
{
Logger.Error("My log message");
throw new ApplicationException("My exception message");
}
The dictionary contains the key. When debugging, the value of test is true
What happens, is that the code jumps directly to the throw statement, skipping the call to Logger, while it really shouldn't do neither - it should just skip the whole block and continue execution.
I've replaced the source completely from repository, I've cleaned and rebuilt numerous times, to no avail.
However, when I changed my code to
if (test)
{
// my code
}
else
{
Logger.Error("My log message");
throw new ApplicationException("My exception message");
}
everything works as expected.
Any ideas what might be going on here? It works as it currently is, but I won't rest easy unless I know what might be cause this.
UPDATE: I deleted my .suo file and some binaries in the output folder which were not deleted even if I cleaned the solution. After this, it seems to work fine
This can happen sometimes when the assembly and its PDB gets out of sync. When you're debugging, the debugger actually reads the relevant information from the PDB file, and not directly from your source file.
You should simply try and rebuild the project (or manually Clean then Build), then try again.
EDIT I misread your question, where you said you already tried rebuilding. In this case, during Debugging, go to Debug → Windows → Modules window, and make sure the symbol file that is loaded is in fact the correct one (e.g. loaded from the same bin\Debug location):
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have a bunch of tests which execute basically a file being moved around.
At the end I check if the file exists in the target directory.
I have 8 such tests which all look the same except for some minor differences.
One of the tests fails when run together with one specific other test (we call it: fTest). I found the culprit codeline and it is this simple assert running in a suceeding test (sTest). When I comment the Assert line, fTest does no longer fail.
var exists = File.Exists(#"\\?\" + destFullPath);
Assert.AreEqual(true, exists);
Even when I remove the first line and change the second line to Assert.AreEqual(true, true) the fTest still fails. Only commenting it out works.
This is some really weird behavior and I have absolutely no clue what is going on. How can one test affect the other?
EDIT: I just copied the sTest, deleted the original and renamed the copy to "TEST()" and now fTest works. What the f*?
I fixed it. Since these are integration tests there was one test which needed to run first. I added the order:1 attribute and now it works.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm working on a program which requires the lookup of files in user defined directories. If the files don't exist, it must continue to use it's own resources. The problem is, even though some files don't exist, the function File.Exists returns true for them.
Here is an image of the error:
Here is the code that looks for the file and produces the error:
string[] vmtLines = null;
if (File.Exists(vmtFile))
{
try { vmtLines = File.ReadAllLines(vmtFile); }
catch (Exception e) { Debug.Log(vmtFile + " Exists: " + File.Exists(vmtFile) + ", " + e.Message); }
}
It turns out the problem is not in C#, Unity, or my programming. It seems there's a problem with files that are called con. I was testing out in the cmd to see if I could open the file con.vmt with notepad, here's what happened:
Then I tried to see if the same thing happens with other files in the same directory:
It opened just fine. Then I tried to see if it were just 3 letter file names which was the problem by opening a file with the name com:
It didn't have some weird problem, then I tried to see if it was something with the extension vmt and the file name con:
It had the same problem. I tried the same thing in the parent directory, and the same problem occurred with the file name con. So I assume this happens anywhere.
Thank you #Programmer, #CharlesMager, #AlexK, #Quantic, #ScottChamberlain, and #LarsTech for trying to help. This was one strange problem
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I've recently started working on an established MVC application using VS2013.
For some reason, HttpContext.Current is null only when running in debug mode - If I remove breakpoints it seems to work, but I don't understand why this should happen running locally.
This isnt just on Chrome - so far, it also happens when debugging through IE11.
If it helps, the solution is using IIS Express as dev web server.
public UserSessionData GetSession()
{
HttpSessionStateBase httpSession = new HttpSessionStateWrapper(HttpContext.Current.Session);
}
Do not keep the Debugger in this line -- > HttpSessionStateBase httpSession = new HttpSessionStateWrapper(HttpContext.Current.Session);
After executing this line, then only the value will be assigned to this variable httpSession.
So, Keep the Debugger in this line --> }. Then check the httpSession in QuickWatch or Mouse Hover.
The value should be there. No its not a Generic Issue. Its Human Error / Mistake.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am getting the following error on a project of mine when I try to build... Error CS2001: Source file '.cs' could not be found. I took the two files that are causing this error out on purpose because they conflict with other files and cannot be in there. How can I resolve this error without putting the 2 files back in the solution?
They are likely still referenced by the project file. Make sure they are deleted using the Solution Explorer in Visual Studio - it should show them as being missing (with an exclamation mark).
I open the project,.csproj, using a notepad and delete that missing file reference.
I had this problem, too.
Possible causes in my case: I had deleted a duplicated view twice and a view model.
I reverted one of the deletes and then the InitializeComponent error appeared.
I took these steps.
I checked all of the solutions mentioned on this question. The class
name and build action were correct.
I Cleaned my Solution and rebuilt. Another error appeared. "Error CS2001: Source file '.cs' could not be found"
I found this answer and followed the steps.
I reloaded the project and cleaned/rebuilt again.
My solution builds without errors and my application works now.
In my case, I add file as Link from another project and then rename file in source project that cause problem in destination project. I delete linked file in destination and add again with new name.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi all am working with Directories and Files Counting Software..
Here, When I get or search Files from C:\ or D:\ it throws UnAuthorizedAccessException
I want to Enumerate Files Ignoring the file/Directory which is Inaccessible
How to ?? C# Visual Studio 2008 Exactly .NET Framework 3.5 only.
My code
var files = FastDirectoryEnumerator.EnumerateFiles(path, "*.reg.zip",
SearchOption.AllDirectories)
.GroupBy(f => f.Name).Select(g => g.First());
Here Am Taking files which ends with .reg.zip
I want to search it on my Whole Computer.. But the Exception..
VS 2008 Default User.. I Tried app.manifest with
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
but even though Exception.. while Searching in SystemVolumeInformation Directory..
I will start by saying this is not the best advice. However, it is a place to start.
My answer is two fold:
Firstly, I think you have prematurely optimised by using the FastDirectoryEnumerator before understanding the filing system level security issues you will face with your project. As such, if time permits, I would recommend a simpler solution as recommended in the post linked to by #phillip in the comments (UnauthorizedAccessException while getting files). For a remotely modern machine 120k files shouldn't be a problem.
Secondly, looking at the speed stats of the FastDirectoryEnumerator I can see the appeal of using it. Digging into the code a little, I can see that it doesn't protect you in any way from permissions exceptions when used as you have done. It is essentially procedural code wrapped inside an IEnumerable MoveNext method. The MoveNext method itself, has been made recursive for sub-directory processing.
I am not able to test this next bit, so you will have to experiment. If you want to hack around with the FastDirectoryEnumerator the first thing you might want to try is a try catch block around the creation of the new FileData object.
public FileData Current
{
get { return new FileData(m_path, m_win_find_data); }
}
If that doesn't work, you would have to work through the GetNext() method to trap the exception in the right place. You might need to go as far as implementing a NullObject pattern for FileData.
I hope that helps in some way.