0

I'm trying do some debugging in the Immediate Window, how do you execute things such as Assembly.Get...()? The only thing I get is The name 'Assembly' does not exist in the current context. I do have using System.Reflection at the stack that I'm looking at, I even have code such as

Assembly ass = Assembly.GetCurrentExecutingAssembly();

But running Assembly.GetEntryAssembly() again trying to poke around in the Immediate Window still doesn't work.

One thing though, is that the code I am trying to debug is from my other dll that I compiled. Does it change anything? It has using System.Reflection; on the file that I'm trying to debug.

error CS0103: The name 'Assembly' does not exist in the current context

Update:

Actually, is weird, it looks like I lost access to the Assembly when the code is in another dll. See below, at the stacks where you see Hello.exe I can access Assembly just fine, however, as soon as it tries to execute code that are from my other dll, I can't grab the Assembly.

MyProgram.Assembly.dll!MyProgram.Xml.XAdESBuilder.AddTimeStampNode() Line 195   C#  Symbols loaded.
Hello.exe!MyProgram.Crate.EDSCrateXMLBuilder.BuildRootNode() Line 458   C#  Symbols loaded.
Hello.exe!MyProgram.Crate.EDSCrateXMLBuilder.Build(MyProgram.Logger provided) Line 140  C#  Symbols loaded.
Hello.exe!MyProgram.Crate.CrateSigner.Crate() Line 82   C#  Symbols loaded.
Hello.exe!MyProgram.GUI.SignCrate() Line 463    C#  Symbols loaded.
Hello.exe!MyProgram.GUI.BtnSignCrate_Click.AnonymousMethod__28_0() Line 320 C#  Symbols loaded.
[External Code]     Annotated Frame

Update2:

In reply to Wendy's comment, here is the hierarchy. I have 2 VS solutions, one is to build a giant merged Assembly that will be use by other program. So in MyProgram.Assembly solution, i has several projects, each project would build their own dll, then I have my Assembly project, this one would merge all other dlls together generating my MyProgram.Assembly.dll.

Then MyOtherProgram would add a Reference towards MyProgram.Assembly.dll and use it just like any other dll.

enter image description here

I'd also like to point out that, the code itself have access to Assembly, just not the Immediate Window, for example:

Assembly assembly = Assembly.GetExecutingAssembly();
assembly.GetType(); // set break point here

If I set my breakpoint at the above mentioned code, then type Assembly in Immediate Window it would still say Assembly not found, but I can see in Autos that the visible is being set properly.

Please note that, there is nothing wrong with my programs, everything runs as expected, but to get there, I had to write code and re-run the program many times just to know what values I was getting from Assembly until I finally got what i wanted... it just that it was very frustrating and annoying not be able to debug it using Immediate Window as I think it should.

codenamezero
  • 2,724
  • 29
  • 64

1 Answers1

0

I get the same error message when there has two projects in a solution and I don't selected any of them in Solution Explorer.

So please make sure you have selected one of project in Solution Explorer and then type command in Immediate Window.

Weiwei
  • 3,674
  • 1
  • 10
  • 13
  • I am debugging the project and the project is definitely being selected before i click `Start`. I even put the breakpoint right in the first line of the Program and it gives the same error. – codenamezero Sep 15 '17 at 13:03
  • @codenamezero According to your update information in your original post, the Assembly is not in current project. Please share the project hierarchy about how your project reference the dll and where the dll stored in. – Weiwei Sep 18 '17 at 02:57
  • @codenamezero, Only one solution per instance, it seems that you just use the solution folder in your side: https://msdn.microsoft.com/en-us/library/haytww03(v=vs.100).aspx, am I right? Since System.Reflection Namespace has the class Assembly, but it seems that you also have one project which also called Assembly, whether there is certain conflict between them? Maybe you could change the project name, view the result. Before you debug your app, could you really compile and run them without debugging like "build/start without debugging"? Do you get any error in your output or error list window? – Jack Zhai Sep 19 '17 at 10:15
  • I thought in VS2017 you can only open 1 solution per VS instance anyway no? I had 2 VS instances opened, one opened `MyProgram.Assembly` solution and the other opened `MyOtherProgram`. My `Assembly` project is a **dummy project** anyway, is just there to merge all my other dlls together, there is **no** `.cs` files in there, there is **no** namespace `Assembly` either. I don't see how a project name would affect debugging? Are you suggesting I rename `Assembly` project name? If yes, then is it the actual folder name or only the project name inside VS? – codenamezero Sep 19 '17 at 14:45
  • @codenamezero, Not get your solutions/projects, but if possible, you could take a backup for your two solutions, and then edit your project name or any class file which called "Assembly" or include it like MyProgram.Assembly, at least, we could make sure that whether it was related to the class file name or any project/solution name. Or just remove the dll reference from solution MyOtherProgram, and then input the command line in Immediate Window, view the result. Also create a simple console app and build it after you add namespace System.Reflection, input the command line, does it work? – Jack Zhai Sep 20 '17 at 09:34
  • You said that "If I set my breakpoint at the above mentioned code, then type Assembly in Immediate Window it would still say Assembly not found, but I can see in Autos that the visible is being set properly.", do you get the FileNotFoundException was unhandled messages? If so, please right click that reference assembly for your MyOtherProgram in solution explorer window, and set copy local=true for it, and then test it again. – Jack Zhai Sep 20 '17 at 09:51