Skary
Skary

Reputation: 1362

Prevent Assembly Name to changes every run

As stated in the title i have that strange behaviour with the subsequent call

Assembly.GetExecutingAssembly().GetName().Name

My exe name is CoreService.exe, with the call above i get different response every time i call it eg :

  1. Coreservice.exe
  2. CoreService.exe
  3. CoreService.Exe
  4. Coreservice.Exe
  5. Coreservice.EXE
  6. CoreService.EXE

I get this behaviour working on Windows Server 2012 and only when i start my CoreService as windows service instead of windows process, anybody can explain why of that strange thing ?

Upvotes: 3

Views: 76

Answers (1)

Mikko Viitala
Mikko Viitala

Reputation: 8404

Actually Assembly.GetExecutingAssembly().GetName().Name does not include the extension.

AssemblyName.Name Property

Gets or sets the simple name of the assembly. This is usually, but not necessarily, the file name of the manifest file of the assembly, minus its extension.

Or then you have actually hit the "but not necessarily" part of it... which would be the first I have ever heard of.

If this is the case, and you need to do something about it besides being curious, then you could ensure consistent result.

Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().GetName().Name);

Upvotes: 1

Related Questions