0

How would you know if a decompiled assembly was written in C# or VB.net?

anouar.bagari
  • 2,084
  • 19
  • 30
  • 1
    In what context would it matter? – Marc Gravell May 07 '13 at 11:45
  • @MarcGravell a new .net project i'm going to be working on, I have some assemblies but not the source code. – anouar.bagari May 07 '13 at 12:09
  • that doesn't answer the question of why it would matter... – Marc Gravell May 07 '13 at 12:16
  • 2
    Just look at the assembly references in the manifest. Anything built from vb.net code will always have a reference to Microsoft.VisualBasic.dll. It is not a 100% reliable, a C# program can of course also reference it. A big hint that you should never care about this. – Hans Passant May 07 '13 at 12:23
  • Thanks Hans that's the assembly I was looking for. – Eli Algranti May 07 '13 at 12:25
  • @MarcGravell it does matter in the way that I've no knowledge in VB.NET, so knowing that's VB.net will give me enough time to learn some. – anouar.bagari May 07 '13 at 12:49
  • @anouar.bag how so? once it is IL it really doesn't matter where it came from. If you don't have the VB.NET source, how would learning VB.NET be useful? – Marc Gravell May 07 '13 at 13:21
  • @MarcGravell I'll get the source code shortly, I'm just anticipating (if it's C# I would concentrate on other things instead of learning VB.NET which I don't like that much) – anouar.bagari May 07 '13 at 13:44

2 Answers2

1

I am not aware of any explicit "I was compiled with..." information in the manifest / attributes. You could perhaps use feature detection (in particular, things like how anonymous types are implemented, and module-level methods), but:

  • in most cases it shouldn't matter
  • compilers you don't know about could appear similar, giving you false answers
  • not all IL comes from a compiler; it could be assembled from raw IL, either with IL as the source-language, or via meta-programming techniques

Personally, I would strongly advise avoiding any dependency on source language

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
1

I vaguely remember there being a utility assembly which was referenced automatically in VB projects, but not C# projects. I'm talking .net 1.1 era (Visual Studio 2003). It made accessing parts of the Explorer shell very easy. I've been looking but have not been able to find it (will edit if I can remember what it was). It may have been obsoleted/dropped in later Visual Studios, but that would be a very strong indicator for original VB (thought C# assemblies could also reference it).

Edit: As Hans noted in his comment the assembly is Microsoft.VisualBasic.

Other than that, it is probably doable by finding patterns of IL used by the different versions of C# vs VB compilers to compile different common language constructs.

If all you want is to see an approximation of the source code for compiled assemblies. .Net decompilers such as ILSpy, .Net Reflector or dotPeek do a pretty good job if the original assembly was not obfuscated.

Eli Algranti
  • 8,707
  • 2
  • 42
  • 50
  • Minor gotcha: any assembly can reference that assembly (there are actually a few handy things in there, if you can get past the language-snobbery barrier of referencing something with VisualBasic in the name) – Marc Gravell May 07 '13 at 13:23
  • Yeap, I wrote that in my response. In fact I've never used vb but have used that assembly in my C# programs. – Eli Algranti May 07 '13 at 21:45