locked
"There is no source code available for the current location"

    Question

  • Hi,

    I was hoping someone could help me with the following problem.

    I have a user control in C# which is displaying the message "There is no source code available for the current location" (there is nothing else in the message) when I step through the validate function attached to a textbox control. I've isolated the problem and attached the source code below for this. I've had a look on the internet for postings regarding this issue and am doing everything that is recommended.

    It seems that there are four things required for this message to come up:
    1. The controls need to be bound to an underlying data source,
    2. The error provider (which is a multithreaded control) needs to have been added to the control (even if the errorprovider is removed, something seems to have changed to cause this to come up)
    3. This seems to happen after the user code for the validate method has finished executing, but before control is returned to the form (in debug mode)
    4. I need to have added a new empty row to the underlying data source (I'm doing this to enture that the combo boxes in the fullblown app where I first notioced this have a blank default value - if anyone can suggest another way of going about this in the front end without adding a blank row to the table in the database, then that would be great too).

    It seems that this is arising when there is multithreading - other postings indicate this happens during recursion or multithreading or when using certain timer controls.

    I'm not getting this message when the application runs - just in debug mode. The app's general functionality does not seem to be affected - everything is behaving as it should be. However, what makes me worried is that some of the internet postings indicate that this is happening because an error is being thrown somewhere else in my code and is being handled strangely. Am I doing something wrong / weird? 

    Any help would be appreciated. Please let me know if I've left anything out or have been unclear.

    Thank you
    Nicole

    **********************************
    // CODE FOLLOWS
    *********************************

    /* user control contains a textbox called txtInput and button to force validation when tabbing / clicking off the textbox control. It also contains an error provider called errorProvider1. This user control can be inserted into Form1 in a dummy app to reproduce the issue */

    using
    System;

    using System.Collections;

    using System.ComponentModel;

    using System.Drawing;

    using System.Data;

    using System.Windows.Forms;

     

    namespace WindowsApplication1

    {

    /// <summary>

    /// Contains the bug regarding "There is no source code available for the current location".

    /// </summary>

    public class UserControl1 : System.Windows.Forms.UserControl

    {
    private System.Windows.Forms.ErrorProvider errorProvider1;
    /// <summary>
    /// Required designer variable.
    /// </summary>

    private System.ComponentModel.Container components = null;
    private DataSet MyDataSet;
    private DataTable MyTable;
    private CurrencyManager MyCurrencyManager;
    private System.Windows.Forms.Button btnSave;
    private System.Windows.Forms.TextBox txtInput;

    // Default constructor.
    public UserControl1()
    {
    // This call is required by the Windows.Forms Form Designer.
    InitializeComponent();
    InitSelf();
    CreateNewRow();
    }

    private void CreateNewRow()
    {
    // add a new row to the table - do this because
    // we don't want drop-downs to display the first
    // value in the drop-down data list
    MyTable.Rows.Add( MyTable.NewRow() );
    }

    private void InitSelf()
    {
    MyDataSet =
    new DataSet();
    InitTables();
    InitControls();
    }

    private void InitControls()
    {
    txtInput.DataBindings.Add( "Text", MyDataSet, "Table.Input" );
    MyCurrencyManager = (CurrencyManager)
    this.BindingContext[MyDataSet, "Table" ];
    }

    private void InitTables()
    {
    // Input table
    DataColumn c;
    MyTable =
    new DataTable( "Table" );
    // columns
    c = new DataColumn( "InputID", System.Type.GetType( "System.Int32" ) );
    MyTable.Columns.Add(c);
    c =
    new DataColumn( "Input", System.Type.GetType( "System.String" ) );
    MyTable.Columns.Add(c);

    // primary key
    DataColumn pkColumn = MyTable.Columns["InputID"];
    pkColumn.AutoIncrement =
    true;
    pkColumn.AutoIncrementSeed = -1;
    pkColumn.AutoIncrementStep = -1;
    pkColumn.ReadOnly =
    true;
    MyTable.PrimaryKey =
    new DataColumn[] {pkColumn};
    MyDataSet.Tables.Add( MyTable );
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Component Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
    this.btnSave = new System.Windows.Forms.Button();
    this.txtInput = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    //
    // errorProvider1
    //
    this.errorProvider1.ContainerControl = this;
    //
    // btnSave
    //
    this.btnSave.Location = new System.Drawing.Point(320, 160);
    this.btnSave.Name = "btnSave";
    this.btnSave.TabIndex = 0;
    this.btnSave.Text = "Save";
    //
    // txtInput
    //
    this.txtInput.Location = new System.Drawing.Point(88, 152);
    this.txtInput.Name = "txtInput";
    this.txtInput.TabIndex = 1;
    this.txtInput.Text = "textBox1";
    this.txtInput.Validating += new System.ComponentModel.CancelEventHandler(this.txtInput_Validating);
    //
    // UserControl1
    //
    this.Controls.Add(this.txtInput);
    this.Controls.Add(this.btnSave);
    this.Name = "UserControl1";
    this.Size = new System.Drawing.Size(528, 464);
    this.ResumeLayout(false);
    }
    #endregion

    private void txtInput_Validating(object sender, System.ComponentModel.CancelEventArgs e)
    {
    // put a breakpoint here
    // exiting this function in debug mode raises the error message:
    //"There is no source code available for the current location".
    }

    }
    }

    Thursday, April 28, 2005 2:20 PM

Answers

  • Erase all the .pdb files that you have in your debug folders.
    It will work then. Wink

    Thursday, November 15, 2007 10:24 PM
  • In your case, the method txtInput_Validating was called by the framework and so, when you exit the method, the debugger is unwinding the stack and is looking for the caller that called your method.  And since you (for that matter, anyone) don't have access to the Framework Source code, the debugger shows that message.

    vJ
    Thursday, June 23, 2005 8:13 PM

All replies

  • This may be totaly unrelated, but I had the same error when I had references to assemblies that had changed.  As soon as I updated the references I was able to step through the code in debug mode.

    dave
    Sunday, May 08, 2005 6:57 PM
  • Hi. I have dealt with the same problem in many many situations, and I always rebuild and blow away and rebuild again, etc.

    But I finally figured out how to get around it. If your code starts giving you that error while debugging, then do this:

    - Add this line to the spot where you want to start debugging:
    System.Diagnostics.Debugger.Break();

    - compile your program. Then run it withOUT debugging, or by running the executable outside of VS. I don't know if by just having VS installed, or if you need to have VS running, but there will be a debugger listening to debugger calls.

    - When that code hits that line, it will pop up a dialog asking you what you want to do, usually with these options:
    New instance of Microsoft CLR Debugger
    New instance of VS.Net
    Exsting instance of VS.Net

    - pick Microsoft CLR Debugger
    Now you will be jumped to your code and can step through and everything.

    NOTE: If you pick either of the VS.Net instances, you will still sometimes get the "source code not available" error!
    This method is what you'd have to do for debugging Windows Services since you can run them from the VS IDE.


    Thursday, June 23, 2005 2:29 PM
  • In your case, the method txtInput_Validating was called by the framework and so, when you exit the method, the debugger is unwinding the stack and is looking for the caller that called your method.  And since you (for that matter, anyone) don't have access to the Framework Source code, the debugger shows that message.

    vJ
    Thursday, June 23, 2005 8:13 PM
  • THank you Vijaye, that helps explain it.
    Thursday, June 30, 2005 10:21 PM
  • Hi coewar,

    Thanks for your help regarding this. I'm afraid I'm still getting the message - however, the dialog you mentioned only came up when I ran the executable, not in the development environment.

    When the dialog popped up (in running the executable), I still got the message. I suppose what I'm missing is - what configuration setting are you using? Also, in the dialog should I select the debugger as the default debugger? Does it make a difference?

    Nicole
    Thursday, June 30, 2005 10:25 PM
  • HI David,

    Sorry for taking so long to reply - I'd given up checking for responses after a while!

    I'm afraid resetting the references in my case didn't help.

    Thanks nevertheless.

    Nicole
    Thursday, June 30, 2005 10:27 PM
  • was getting the same error..
    possible when u get the compiled code over from one machine to another and then try to debug it. the compiled dll has reference to the old code, so it is unable to find on the new machine.
    try deleting the pdb and dll file of the project and compile again.
    worked for me.
    Thursday, July 28, 2005 2:43 PM
  • I have the same problem when I changed the Assembly References to latest version. When debugging it pop-up a window. If I select Disassembly the control get into assembly file and does not return back. Do any one have a solution for this.
    Friday, March 24, 2006 6:08 AM
  • Your post has been a tremendous help to me. I am struggling with this debug probelm since a week.

    Thanks a bunch Buddy.....Smile

     

     

    Monday, October 29, 2007 9:01 PM
  • Erase all the .pdb files that you have in your debug folders.
    It will work then. Wink

    Thursday, November 15, 2007 10:24 PM
  • I think that this error message and the line at which it is thrown sometimes is misleading.

    For example, I have following code, which uses an external .dll-library without corrsponding .pdb file:

     

    class ErrorDemonstration

    {

     

    void Method_A()

    {

    // ...some code...

    ExternalObject myObject;  // A reference to an object form INVALID external .dll-library;

    myObject.Size = 0;           // or operation on (an instance == null) from VALID external

                                           // .dll-library i.e. (myObject == null)

    // ...some code...

    }


    void  main()

    {

    Method_A();     // If the external .dll-library is corrupted/updated_with_newer_version/deleted,

       // then the debugger stops HERE, saying “There is no source code available for the current

       // location”, and does not go into Method_A, which makes me think: "Something

       // wrong with the debugger! Method_A is right there in the same class, how comes it

       // cannot find it?!"

       // The same error occurs when the external .dll-library is VALID, but an object created

       // from this library was not initialized i.e. is NULL, and we try to perform an operation on it,

       // then Visual Studio's debugger instead of throwing NullPointerException shows

       // "There is no source code available..." error message. Once again, it does not allow to step

       // into Method_A.

    }

    }


    It would be much easier for a programmer, if the debugger was able to step into Method_A and shows an error right on the line where this error occurs. Unfortunately, such error handling is preserved even in Visual Studio 2008.


    Saturday, November 17, 2007 6:16 PM
  • Note the comments and links at the bottom of this page.

    http://www.codeproject.com/dotnet/DemystifyGAC.asp

     

    Create a policy file.

     

    Sunday, November 18, 2007 5:06 PM
    Moderator
  • I was actually able to cure this problem by using Build>Clean then Build>Rebuild.  Worth a shot if someone ever runs into this again and no other solutions above works.

    Wednesday, December 12, 2007 2:47 PM
  • I am no Hi fi programmer . But most of these probs are solved just goin to

    Build > Clean Solutions

    Build > Rebuild Solution

    Then Run your Application
    Worked like a charm for me

    Tuesday, May 13, 2008 6:26 AM
  • In applications this can happen when your build types are out of sync. This is more evident on x64 systems (mine was on Vista Buisness x64).

    My main application is an ASP.Net website configured to run in x86 compatiblity mode, in order to be able to use COM based components. I created a couple assemblies in VS2005 .Net 2.0 to encapsulate some of my logic. Most of the assemblies were initially created using the x86 build type, but I added a couple that had the 'Any CPU' build type. When I added a new project it took the 'Any CPU' build type.

    When debugging an x86 application it couldn't descend into the 'Any CPU' code because it had been JITed for x64.

    Short and sweet ... check your build types if you are on x64.

    -R
    Thursday, June 12, 2008 3:38 PM
  •  If you search on this error, you see it has stumped literally thousands of people. 
    Friday, August 01, 2008 12:53 AM
  • After days of looking through forumns, I found that I had a breakpoint in the wrong location. After Debug -> Delete All Breakpoints the error went away. I nearly threw my chair through the monitor.

    Wednesday, June 17, 2009 7:49 PM
  • I had the same problem, but was fixed when i deleted the .pdb files.
    Thanks CoderMind!!!!!!!!
    Tuesday, July 07, 2009 7:04 PM
  • The same problem has bothered me for a long time and I've tried all the methods I could found through Google.

    At last, I've found the root cause of my problem. I've assigned the "this" to a member variable in an object, and this will lead to endless evaluation and at last stack overflow if you try to see the value when you are debugging and stop at a break point.

    So in my opinion, this is a bug of Visual Studio, that we can avoid.

    Tuesday, September 01, 2009 6:15 AM
  • WOW.  What sort of hoops did you jump through to uncover that trap?

    Rudedog  =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, September 01, 2009 7:40 PM
    Moderator
  • I was actually trying to resolve the following problem:

    Modal popup disappears after a postback.

    Then i noticed this "no source code find" error  popup while debugging and thought this might be causing it.
    I only saw the error when iterating through debugging by pressing F11, didnt use to see the error when pressing F5 to go to next breakpoint.

    Following has resolve the problem with "no source code" error.

    1. deleting .pdb files
    2. doing Build --> Clean Solution
    3. and then Build --> Rebuild Solution

    I was still having trouble with modal popup disappearing after postback but resolving this was a relief and an education.

    And then also resolved the issue of modal popup disappearing by putting the modal popup content inside an updatepanel control.

    hope it help others.

    Monday, October 12, 2009 3:36 PM
  • I encountered the same ptroblem but I was knowing what changes I have made, so i just undo those changes.
    I will share you what i did...
    My project name was ePMO. I upgraded to the higher version of .net framework and renamed it to ePMOL5Ver2 and at the same time I also changed my assemblly name to ePMOL5Ver2 in the project properties which was the actual cause of the issue.
    I renamed it my assemblly name to ePMO and it starts working fine.

    Cheers!!!!
    Raj
    Friday, February 05, 2010 6:28 AM
  • aman bedi is right read his advice and do it
    worked dam good for me
    boaz levinson
    Saturday, February 06, 2010 8:39 AM
  • I was facing the same problem.I just cleaned the solution and then rebuild the solution and it worked like a charm....

    Hope this helps

    Friday, May 14, 2010 6:27 AM
  • I am no Hi fi programmer . But most of these probs are solved just goin to

    Build > Clean Solutions

    Build > Rebuild Solution

    Then Run your Application
    Worked like a charm for me


    I've got the same problem, Thanks for your reply! Finally solved it.
    Saturday, September 04, 2010 4:07 AM
  • Thank you so much! This was exactly the solution I needed for my issue.
    Tuesday, October 05, 2010 9:43 AM
  • I am also getting the same problem.

    How to set the path for the reference to the dll on the new machine.I have igrated the sorce code to the new position.Now, how would I set the path of the dll to make it reference it to new location .

      

    Wednesday, March 30, 2011 7:06 AM