Bug 19239 - Code behaving incorrectly
Summary: Code behaving incorrectly
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-04-23 05:18 UTC by Kyle
Modified: 2014-04-23 08:02 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

VS Debugger (20.40 KB, image/png)
2014-04-23 06:24 UTC, Kyle

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Kyle 2014-04-23 05:18:06 UTC
I'm currently encountering an odd problem where code is either executed once, or not at all. I am using a PCL (VB.net) with my iOS application. This piece of code works perfectly on our test desktop application (via the same PCL) yet whilst running this on the mobile device I encounter the following error.

 Public Sub New(ByVal ApplicationLogPath As String, _
 ByVal ApplicationFileName As String, _
 ByVal ApplicationLogType As LogType, _
 ByVal MaxApplicationLogSize As Long)
 Dim sb As StringBuilder
 ' Hold the path and the file name for use throughout the rest of the class. These
 ' must be passed in rather than using the settings class from within the class 
m_filePath = ApplicationLogPath
m_fileName = ApplicationFileName
m_logType = ApplicationLogType
m_maxLogFileSize = MaxApplicationLogSize
 ' Ensure the application log path has a trailing backslash
 'If m_filePath.EndsWith(“\”) = False Then
 ' m_filePath += "\"
 'End If

The line of code m_filePath += “\” is executing twice as the variable is seen as “Logs\\” when it is passed in as “Logs”. 
If I move the check to above the lines of code where I set the member variables for m_filePath… (etc) to the passed in variable (ApplicationLogPath). While debugging through It steps into the line m_filePath += “\” yet the “\” character is not appended.
This is in the constructor of an Application Log object in the PCL, It is only created once and I cannot see how It can be executing this line more than once.
Comment 1 Kyle 2014-04-23 06:14:14 UTC
Removing the If m_filePath.EndsWith(“\”) = False Then makes no difference, the code m_filePath += "\" still executes twice.
Comment 2 Kyle 2014-04-23 06:24:47 UTC
Created attachment 6636 [details]
VS Debugger
Comment 3 Sebastien Pouliot 2014-04-23 08:02:30 UTC
I do not use VS but (in general) the `\` character needs to be escaped since it represent special characters, e.g. `\n` (newline) or `\t` (tab). Both are (in memory) single characters.

To represent a singe '\' character you need to escape it like `\\` - but, in reality (memory), there's only one. 

You can confirm this by looking at your string's Length property.

Also note that this represent Windows path and will likely not work on mobile device (where a different separator is used `/`). Your code should be used `Path.Combine` to be cross-platform.