C# A 32 bit processes cannot access modules of 64 bit process


This Content is from Stack Overflow. Question asked by JuanDYB

At my application starting I’m checking if same application is running and if it’s true I kill previous process.

I’m doing it with the following code. I have to check companyName and copyrigth to ensure that I’ll kill only process of my company and not other processes that can have same name as my process.

var currentProcess = Process.GetCurrentProcess();

var foundProcess = Process.GetProcessesByName(currentProcess.ProcessName).ToList();
    foundProcess = foundProcess.Where(p => p.Id != currentProcess.Id);
    foundProcess = foundProcess.Where(p => p.MainModule.FileVersionInfo.CompanyName.Contains("CompanyName") || p.MainModule.FileVersionInfo.LegalCopyrigth.Contains("CompanyName"));

    foundProcess.ForEach(p => p.Kill());

My problem is that I have exception A 32 bit processes cannot access modules of 64 bit process when a process running with the name that I’m searching for is found runnig at 64 bits.

It’s neccesary to compile my application at 64 bits or there is another way to achive this?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?