How to determine if code is C# or VB.Net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

If done some research and did not found a way to do this.

Is there an attribute in the assemblies that would give this value?
Is there a tool that you can run and extract the language used to generate
the MSIL?

Any help would be appreciated

Marc
 
By definition, the IL is language neutral, that is, it could be produced by
any .NET language. That means that any IL disassembler/decompiler should
offer you several language options (C#, VB.NET, etc.) for the output.

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Once compiled, the original source becomes MSIL (Intermediate Language), so
it can be decompiled to any language. There is nothing to tell what the
original source was written in, as it is completely unimportant.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Thank you for the responses; however, to answer my question, is there a way
to figure out the originial source language?

A need to know basis to enforce development groups to use a language rather
than the other.. Can this be done via Reflection or MS tool?
 
No, there is no way to know on a compiled assembly.

One of the major benefits of .NET is it does not matter what language you
start with. This is not 100% true, as each compiler is better at certain
things, but the concept is overall valid.

The major reasons for choosing one language over another in .NET:

1. The majority of resources (developers) in the market are skilled in a
particular language
2. The majority of resources (developers) in your organization are skilled
in a particular language
3. You need a particular feature of a particular language: ie, late binding
in VB.NET or unsafe code in C#.

For #3, you can create a library that can be used in the other language.

I would not attempt to examine compiled assemblies to determine which
language you should use, however.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Errr... I think if you see the code using Microsoft.VisualBasic namespace
things, there's good chance it's origionally written in VB.NET.

However, the namespace is never anything essential to be used if you want to
write something in VB.NET. So if you can't find it, you still can't conclude
it's not written in VB.NET...
 
if it's to check that a company police is enforced, you could try to guess
the development language use from the sources.
what about that?
 
If done some research and did not found a way to do this.
Is there an attribute in the assemblies that would give this value?
Is there a tool that you can run and extract the language used to generate
the MSIL?

Any help would be appreciated

there are few subtle differences between c# and vb.net compilers known. it
is however hard to say that these differences are obvious enough to track
them and then decide which compiler was used to compile the source code.

take a look for example here:
http://tinyurl.com/brvbs

with a bit of luck you may be able to use this knowledge - if you spot such
consecutive struct initializations in il then
- if a temporary variable is used: a vb.net code
- if no temporary variable used: c# code
(assuming that no other language could be involved).

I wonder if any other such issue could be handy here. I also wonder if this
different behaviour of these compilers will be unifed in the future.

Wiktor Zychla
 
Back
Top