none
FirstChance Exception only on release version RRS feed

  • Question

  • Hello.

    I am receiving the following firstchance exception

    System.ArgumentOutOfRangeException: Length cannot be less than zero.
    Parameter name: length
     at System.String.Substring(Int32 startIndex, Int32 length)

    No stacktrace at all and I am only getting these when I build the service using Release config and run it.

    On VS and debugging I dont get this. 

    Anyone knows how can I further troubleshoot it?

    Thanks in advance

    Wednesday, March 8, 2017 8:41 AM

All replies

  • This means that the parameters that are being passed to the SubString method one of them contains a negative value and that is not expected to be passed to SubString method, before passing the index variable to the method make sure you are checking that they are non-negative indexes using an if block, or if it is encapsulated in a method, you ca consider using code contracts for this.

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, March 8, 2017 3:17 PM
  • I know what it means and why it is caused. I dont have any substring call in my code.

    What I dont understand is why am I getting it only in release mode. And why no stacktrace.

    Thanks

    Wednesday, March 8, 2017 5:30 PM
  • I know what it means and why it is caused. I dont have any substring call in my code.

    What I dont understand is why am I getting it only in release mode. And why no stacktrace.

    Thanks

    @pantonis

    Per my understanding, there may be some built-in functions that call the substring() method.

    You could try to debug on your develop machine. And now .Net framework is OpenSoure. https://referencesource.microsoft.com/

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 9, 2017 1:39 AM
  • As I mention in the previous 2 comments I dont get this exception while debugging. When I build using Release and deploy the service starts giving me the error. And the worst part is that there is not stack trace at all.
    Thursday, March 9, 2017 7:27 AM
  • Instead of debugging directly, consider create a special build in Release but with System.Diagnostics.Debugger.Break() added in generic error handler (i.e.: AppDomain.CurrentDomain.UnhandledException). As long as you keep the PDB file in the same folder, the IDE may be able to tell you more about where the exception is thrown.

    P.S.: I don't know why I lose the toolbar on the reply box. So have to post the link separately.

    P.P.S: Seems the toolbar appears again after I posted that and edit it.


    Friday, March 10, 2017 1:29 AM
    Answerer
  • Hehe. Dont worry happens to me all the time.

    I have tried what you sugggested but still the same result. Cannot attach to service process.

    Saturday, March 11, 2017 4:29 PM
  • Hi pantonis,

    If you're receiving an exception but no corresponding stack trace then at some point an exception handler is probably evaluating the exception and re-throwing it incorrectly. For example, if you're doing a throw ex; you'll eat the stack trace that led to that point. To preserve the existing call stack you want to simply throw; Throwing exceptions best practices

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 22, 2017 6:14 AM
    Moderator
  • Hi pantonis,

    If you're receiving an exception but no corresponding stack trace then at some point an exception handler is probably evaluating the exception and re-throwing it incorrectly. For example, if you're doing a throw ex; you'll eat the stack trace that led to that point. To preserve the existing call stack you want to simply throw; Throwing exceptions best practices

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I know how exceptions work. My code does not have the code that throws the exception "SubString". Suppose it is some third party library but I dont know which one and why it happens only on release.

    Thursday, March 23, 2017 7:22 AM