87

I am running my application in VS2012 and I am getting a runtime error; enter image description here

When I look in the "Original Location" I see mscorlib.dll, but not mscorlib.pdb.

Why is this happening and how do I fix it?

arame3333
  • 9,887
  • 26
  • 122
  • 205
  • 2
    This is normal. You are not going to find the source, you don't have source code for the .NET Framework. Focus on fixing *your* bug, mscorlib.dll doesn't have a bug. Use Debug + Windows + Call Stack to find your code back. – Hans Passant Feb 24 '14 at 12:58
  • 2
    problem still exists in VS2015 – AXMIM Feb 26 '16 at 18:06

9 Answers9

174

Goto Tools, Options, Debugging, General, Enable Just My Code

This will prevent the debugger from trying to launch on a Internal .NET Framework Assembly.

Wallbasher
  • 1,886
  • 1
  • 12
  • 5
9

Goto Tools, Options, Debugging, Symbols and set a cache location. Then hit load in the above and it will fetch the necesary symbols for you and store them in the cache location you provide.

Microsoft's compiler tools create symbols in separate files with a .pdb extension (program database). This allows them to create detached symbols for release binaries. With a symbol server, your IDE can fetch the symbol file matching the specific version of the DLL during debugging. You can configure this system for your own product binaries as well which can be very useful for post-mortem debugging any crashes on end-user machines.

See Microsoft's documentation for more details about using their public symbols.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • I had a look and the cache location is already set; C:\Users\xxxxxx\AppData\Local\Temp\SymbolCache. When I have a look in that directory it is empty. Should I be using a different location? Clicking load doesn't make any difference. – arame3333 Feb 24 '14 at 10:48
  • I use a permanent location but that is just to avoid re-fetching pdb's all the time. It needs to use http to fetch the symbols files so make sure you can access http://msdl.microsoft.com/download/symbols without error. In a web browser that is a blank page, but not an error. – patthoyts Feb 24 '14 at 11:13
  • Yes I get a blank page. Where can I get the pdb from? – arame3333 Feb 24 '14 at 11:25
  • You read the suggested web page and try the symchk command with appropriate arguments to identify the file you are interested in and where you want the symbols cached. – patthoyts Feb 24 '14 at 11:54
  • I am getting lost with that page. I think I am meant to download Debugging Tools for Windows 7 (I do not have windows 8) but I cannot find it. – arame3333 Feb 24 '14 at 15:00
  • 1
    This answer seemed promising and better than Wallbasher's but I couldn't get it to work. It seem that arame3333 couldn't also. I did saw some "loading symbol" popup appear though but ended up with the same result. – AXMIM Feb 26 '16 at 16:46
  • Navigating to: Tools, Options, Debugging, Symbols, and clearing the 'Symbol Cache' seemed to be the magic incantation that got me past this error. – rfreytag Apr 27 '17 at 16:43
2

I had this issue when I was using a static variable, whose value is assigned off a static method.

So, whenever I ran the application, this line of code threw exception. If you place a debug point on this (like I did), you will notice the exception being thrown.

2

The best Solution to solve this error is:

1: Open App.config file.

2: Paste this useLegacyV2RuntimeActivationPolicy="true" code in the startup tag.

3: Save it.

Now the error would disappear. Moreover see this Image. I have done this for you.

Muhammad Abbas
  • 389
  • 6
  • 15
  • 3
    can you please add your configuration as text instead of a picture? It's easier to copy/paste – slfan Oct 30 '16 at 20:35
  • I have mentioned the line of code useLegacyV2RuntimeActivationPolicy="true" that is to be added in the startup tag. So its clear. The picture is given just for reference. – Muhammad Abbas Oct 31 '16 at 06:25
  • Why does this solve the problem and how does it do it? – TylerH Mar 10 '22 at 20:08
1

This happened to me for a different reason: I had referenced an old version of NLog (2.0) and needed to reference version 4.0, instead.

David
  • 41
  • 6
-1

In a VB console app, in my case it was none of the above.

Just doing a string calculation in the Dim declarations before my subs.

The offending code:

Dim FylPrefix$ = Fyl.Substring(0, Fyl.LastIndexOf("."))

Moving this calculation into the sub it was needed in fixed it! GERONIMO!!

  • 1
    Can you explain how/why this fixed it? – toonarmycaptain Nov 01 '17 at 20:35
  • Basically, VS didn't report this as a compile error as it should have. It allowed the app to build and run. But it was an error - two much calculation in the DIM declaratives area before procedures. – Runner66 Nov 13 '17 at 17:31
-1

In my case the exception began to appear after I changed the "Assembly name" in the "Application" tab of the properties window. If that's the case with you try reverting to the original name and see if the exception disappears. Perhaps the reason for this was that the new name did not match the AssemblyTitle in AssemblyInfo.cs.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
RoySeberg
  • 63
  • 5
-1

This can happen when you initialize a variable in your class declarations and that initialization throws an exception:

class Program
{
    static OracleConnection ora = getOracleConnection(); 

}
static void main(string[] args) 
{
    ora.Open();
}
static OracleConnection getOracleConnection()
{
   OracleConnection orax = new OracleConnection(description=(host=myHost)
    (port=1521)(protocol=tcp))(connect_data=(sid=mySid)));user id=user;password=pw;
}

If an exception is thrown by getOracleConnection() you can get this error. Move your assignment (but not necessarily your declaration) inside of main (where it belongs anyway), and you will get the actual exception that is causing the error instead of the mscorlib error.

Ainsworth
  • 69
  • 3
  • 8
-2

if you have this type of project runtime error in visualstudio Answer:Cntr+Alt+E open Exception window Uncheck All chechboxes Must and shoud its working written by B sriram Mca Giet College rajahmundry, east godavary ,2014 batch