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

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".
}

}
}



Answer this question

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

  • Martin R

    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

  • JamesPane

    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.


  • Feng2000

    Your post has been a tremendous help to me. I am struggling with this debug probelm since a week.

    Thanks a bunch Buddy.....Smile


  • ZeeGee

    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

  • Rod A.

    THank you Vijaye, that helps explain it.
  • Madhu B.A

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


  • StRoNg-WiLLeD

    Note the comments and links at the bottom of this page.

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

    Create a policy file.



  • Henk vd Geld

    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

  • confused_adp

    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.



  • geeky

    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

  • DNA Dashboards

    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.

  • afung

    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.



  • Rob S

    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.



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