I have a base class, called Telegram, and I would like to translate a string into a list of such telegrams.
Therefore I have the following piece of code:
private IEnumerable<Telegram> ExtractTelegrams(string telegramString)
{
var telegramArray = telegramString.Split(new char[] { "\u0003", "\u0006" },
StringSplitOptions.RemoveEmptyEntries);
foreach (var currentTelegram in telegramArray)
{
... <=== here I set my breakpoint
I know this code mostly works (it's been thouroughly tested), but now I'm having an extra look and I'm trying to debug that piece of code, but that's not working: this is the message in my immediate window:
? telegramArray
error CS0103: The name 'telegramArray' does not exist in the current context
? currentTelegram
error CS0103: The name 'currentTelegram' does not exist in the current context
Why is this? I'm working with "Debug" build of my application, and that telegramArray and currentTelegram are used afterwards. I know from the runtime that it works but I can't see in the debugger WHY it works. Are there problems with the var keyword, the private keyword, ...
Related
I rarely get an ArrayTypeMismatchException in my program:
public Map(Map otherMap)
{
var cpyArr = new char[otherMap.PlayingField.GetLength(0), otherMap.PlayingField.GetLength(1)];
Array.Copy(otherMap.PlayingField, cpyArr, otherMap.PlayingField.Length);
PlayingField = cpyArr;
var cpyTrans = new List<Transition>();
foreach (var item in otherMap.Transitions)
{
cpyTrans.Add(new Transition(item.X1, item.Y1, item.D1, item.X2, item.Y2, item.D2));
}
Transitions = cpyTrans;
}
The PlayingField property is a twodimensional char array.
Here is the output:
Unhandled Exception: System.ArrayTypeMismatchException: (Types:
source=System.Char; target=System.Char)
The strange thing is that this doesn't happen all the time, just occasionally.
The exception gets thrown at Array.Copy, but the error clearly states that the types actually do match.
How do I fix this?
EDIT: I should also add that the program is being compiled using the current Mono version and run on Linux. But I couldn't reproduce the error on my testing systems. The program is supposed to run on a server system which I sadly have neither access to, nor do I have any information about except that it also runs linux.
The main Problem is completely different, please skip to the Edit
I have an exception of an unknown type which doesn't even get thrown properly. Following Code provides the Context:
MMDataAccess.InitDemoDB();
MMDataAccess.InitInternalDB();
MMDataAccess.InitMaintDB();
try
{
SQLiteToDBLib sqltdbl = new SQLiteToDBLib();
sqltdbl.WriteToSQLite();
}
catch(Exception ex)
{
string message = ex.Message;
}
These are the very first lines of my first Activity in my app. The first 3 lines belong to my very own implementation of an in-memory database and are behaving nicely. The problem rises with the next two lines inside the try-block. The declaration and initalistation of the sqltdbl variable never happens. The constructor of SQLiteToDBLib looks like this:
public SQLiteToDBLib()
{
msc = new MSConnection();
}
The MSConnection class doesn't even have a constructor (except for the default one of course).
As you can see i've tried to catch any exceptions, but without success. everything i can figure out is, that a exception is thrown because of the debugger going into the catch section while ignoring everything that has to do with "ex". Without breakpoints everything seems fine. Just without the call to WriteToSQLite which should create a .sqlite file on the external Memory.
What can I do to resolve this error? Is there anything i can catch except the default Exception?
Edit:
After some testing with commented code something interresting happened. I could step into commented code. Well not exactly the commented code, but the code that was there before my changes. Visual Studio somehow shows me the things, that are changed in the file, but is compiling the old code. Up to now i tried to rebuild, clean and build the project in various combinations, unload and reload the project, Restart Visual Studio and restart Windows. Nothing has changed so far. I Will now proceed to create a new .cs File With the exact same Code. I'm working with VS 2013 Community
add static constructor to your SQLiteToDBLib class and perform all static objects initialization in it:
static SQLiteToDBLib()
{
// initialize static members here
}
If this doesn't give you a clue, try enabling CLRE exceptions-break in visual-studio:
DEBUG
Exceptions
Check the 'Common Language Runtime Exceptions' option (under the 'Thrown' column)
Press OK
Restart your app and try again
When I try to build my WPF project I get the folowing error:Samotorcan.Client.WPF.Windows8\Views\MainWindow.xaml(1,17): error MC3074: The tag 'Window' does not exist in XML namespace 'clr-namespace:Samotorcan.Client.WPF.Windows8.Controls'. Line 1 Position 17.The problem only occurs when I try to use linq. If I have a line like this new List<object>().ToArray<object>(); somewhere in the MainWindow.xaml.csfile I get the above error and if I change it to new List<object>().ToArray(); the error disappears and the project builds successfully.I also checked the build log and it contains the same error at task MarkupCompilePass2.I am using .NET Framework 4.5 and Visual Studio 2012.EDITAfter playing with it a bit I managed to find out that it's not specificly related to linq an random changes like removing an unused file from a project or just removing parts of code like a simple string creating string s = new String(); fixes the error.At one point a simple change in a constructor from this
public LoggedEventArgs(string message)
{
Message = message;
}
to this
public LoggedEventArgs(string message)
{
// Message = message;
}
fixed the error.
Managed to find a workaround for the above error by moving all my controls from the project into a separate project just for controls.
Now there are no random errors on build because as it looks like it can always find the window and other controls that are now in a separate assembly.
I'm getting this error:
Could not copy the file "obj\x86\Debug\TitleGenerator.exe" because it was not found.
When I try to compile, but it doesn't make any sense. The only thing I changed was to add the following lines of code to help me debug an issue:
#if DEBUG
if( title.Culture == null || title.Religion == null )
{
}
#endif
If I remove those lines, it compiles with no issue. If I change the if statement to if ( true ) {} it compiles fine.
Restarting Visual Studio doesn't help. I've also tried restarting my PC. As far as I can tell, the .Net framework, and Visual Studio are both up to date.
I'm using Visual Studio 2012, a target framework of 3.5, with the Default language level, CSS version 3.0
[Edit] It's now started working again. All I did was to remove output of title.TitleID from the output to the log.
Meaning I changed things like Log( " --Title in Ignore List: " + title.TitleID ); to Log( " --Title in Ignore List" );
The contents of title are decided during runtime, and it's the object of a foreach loop over a list.
Even more strangely, if I add this class to the project:
public class DebugBreak
{
[Conditional("DEBUG")]
public static void TitleIDBreak( Title title, string id )
{
if ( title.TitleID == id )
System.Diagnostics.Debugger.Break();
}
}
But don't even do anything with it, then it works. I don't even have to call the method. Just changing the build action of the file from None to Compile makes it work.
This is commonly caused by Avast.
If you are running that antivirus, add an exclusion for your project folder.
I've searched for this several times in the past. Its a file access issue, so it may not be your code at all.
What type is title? Is it even defined? Statements are checked for semantics even if DEBUG is not defined.
I'm guessing your code is not compiling.
C# does not use a "pre-processor" like early C compilers where the file was changed before the compiler even saw it.
There's nothing wrong with the code you have written based purely on what you've posted.
One thing you can try is to use a Conditional attribute for your debugging. Something like:
[Conditional("DEBUG")]
static void TitleCheck(Title title)
{
if( title.Culture == null || title.Religion == null )
{
System.Diagnostics.Debugger.Break();
}
}
private void MyProductionFunction(Title title)
{
// Do some stuff
TitleCheck(title); //<< This function call will be omitted completely if 'debug' conditional isn't met.
// Do more stuff
}
due to an oversight on my part (still new to AppState and Session variables) I have to change all of my AppStates to Session variables. WebMatrix's replace has made that part easy, however I am now getting this error on the first of the two lines of code below:
Session["gActionMessage"] = "";
Session["gActionMessageDisplayed"] = "not";
Error:
Compiler Error Message: CS0103: The name 'Session' does not exist in the current context
If it matters, these lines of code are in my _AppStart.cshtml file.
Any suggestions? Do I have the syntax wrong?
Sessions are not available at the point that the _AppStart.cshtml file is executed. That happens too early in the pipeline. You can use _PageStart.cshtml to initialise session variables.