C# Program Will Not Run On Clean Install of Windows 11

PassRusher

New member
Joined
Jul 23, 2024
Messages
4
Programming Experience
3-5
So first a little background...I am not a C# developer or a developer in general. But I am often needed to go over existing code to update and fix, mostly VBA or Visual Basic but sometimes C#. I have a C# problem / question I really need some direction on. I went to a popular website where a lot of experts hang out but immediately get downvoted and eventually the post is closed when all I need is a little nudge or eyes on my issue.

Back in 2017, a developer made a C# program for us that will populate a Word Document with information from a design program. We would first run a Setup program to install this functionality and then the program will run when they execute it from the design program (you can also run it standalone). All of these users were on Windows 10 and 2 of them did an in-place upgrade to Windows 11 and they can still run this program. So users with new, clean installs of Windows 11 cannot run this program. The setup will run and it acts like it installs.

I'd post more but first want to see if anyone knows what would cause this on clean installs. I was thinking .net versions and ASP updates but they seem to match between previous, working PC and the new one.

I can post links to the C# solution / code but only if requested...I am thinking this may simply be something missing to make it work.

Thanks in advance!
 
So users with new, clean installs of Windows 11 cannot run this program.

What error message is shown when the program runs?

If no error message, what is logged by the program it its error logs? (The programmer was following the best practice of logging, right?)
 
A clean install of Windows doesn't have Word installed. If that C# program does automation to interact with Word, then likely it will fail.
 
What error message is shown when the program runs?

If no error message, what is logged by the program it its error logs? (The programmer was following the best practice of logging, right?)

So the install program says installation complete but when you run the EXE on a new, Windows 11PC, it just does nothing...
A clean install of Windows doesn't have Word installed. If that C# program does automation to interact with Word, then likely it will fail.
The new PC(s) do have Word installed on them...when you execute the program, it just doesn't open Word, so not 100% sure the setup installed the needed files.

Let me put in part of the code of the main EXE...this is when it should be calling WORD to open and before it makes it edits to word.

LOC:
using System;
using System.Data.OleDb;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Office.Interop.Word;

string userName = Environment.UserName;
if (!((userName == "kkovar") | (userName == "ABC") | (userName == "GHF") | (userName == "ankunga") | (userName == "sowen") | (userName == "jpatoka") | (userName == "awilliams")))
{
    return;
}
string text = "0";
string currentDirectory = Directory.GetCurrentDirectory();
string path;
if (text == "1")
{
    path = "C:\\MBS_JOBS\\181062\\181062A\\LOC.OUT";
}
else
{
    path = currentDirectory + "\\LOC.out";
    if (File.Exists(path))
    {
        File.Delete(path);
    }
    Process.Start("cmd", "/c c:\\mbs\\exe2\\contract 1 LOC.frm LOC.out");
}
_Application application = (Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046")));
_Document document = (Document)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00020906-0000-0000-C000-000000000046")));
object Template = "C:\\MBS\\Rep\\2017LOC.docx";
object NewTemplate = Missing.Value;
object obj = null;
application.Visible = true;
document = application.Documents.Add(ref Template, ref NewTemplate, ref NewTemplate, ref NewTemplate);
obj = "EngCode";
document.FormFields[ref obj].Range.Text = Environment.UserName;
obj = "DATE";
document.FormFields[ref obj].Range.Text = DateTime.Today.ToShortDateString();
_ = CultureInfo.CurrentCulture.TextInfo;
int num = 12;
int num2 = 0;
string text2 = null;
string text3 = null;
StreamReader streamReader = new StreamReader(path);
string[] array = streamReader.ReadToEnd().Split('\n');
streamReader.Close();
streamReader.Dispose();
if (text == "0")
{
    File.Delete(path);
}
 
How do you know the code is not silently quitting simply because lines 10-14?

Also, a lot of modern antivirus will just quietly not execute applications that are not code signed. Did you configure your AV to grant exceptions to your application(s)?
 
How do you know the code is not silently quitting simply because lines 10-14?

Also, a lot of modern antivirus will just quietly not execute applications that are not code signed. Did you configure your AV to grant exceptions to your application(s)?

I actually don't know...I am about to run the debugger from VS on a PC where this is working and watch it step by step...

Well, the antivirus is a good question...no, this is not excluded currently but is working on those older PC's...but the folder in which this is called from is excluded.
 
You don't even need to install Visual Studio on those new machines. Just install the Visual Studio Remote Debugging Tool on them and debug remotely.

Anyway, line 11 should be easy enough to check. Just see what the user name on the machines are.
 
You don't even need to install Visual Studio on those new machines. Just install the Visual Studio Remote Debugging Tool on them and debug remotely.

Anyway, line 11 should be easy enough to check. Just see what the user name on the machines are.

So awilliams is the one with the new, clean PC with Windows 11 and it doesn't run on her PC.

I can't even debug this on my PC as it said it has build crashes
1722024798210.png

just don't know enough about C# to really fix this. And got some pressure put on me today for an update on it.
I tried a break point at or near line 11 but this is where it stops...

1722024946951.png
 
So awilliams is the one with the new, clean PC with Windows 11 and it doesn't run on her PC.

Okay so it isn't bailing out early on her... Assuming that her user name truly is set to "awilliams", and not set to something like "AWilliams", or "Awilliams", or "awilliamS". Basically that line 11 is a case sensitive check for a user name. If the username is not set with the exact case expected, then it will bail out on line 13.


I can't even debug this on my PC as it said it has build crashes
1722024798210.png

That is not a crash. That is simply telling you that you tried to debug the program, but the code failed to compile.

You should look at the Errors pane in Visual Studio to see what the error(s) were when trying to build the code.




I tried a break point at or near line 11 but this is where it stops...

1722024946951.png

Because your build failed, the no executable was created by the compiler.
 
C#:
_Application application = (Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046")));
_Document document = (Document)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00020906-0000-0000-C000-000000000046")));

This is problematic... Late binding from a COM GUID means this code will only work with specific versions of Office...

Just use the interop types directly... You might need an actual programmer to fix it though... Looks like VBA code that was converted to C# by someone who didn't know .NET in general...

Also it says there were build errors... What are they? Look in the Output tab in Visual Studio after a rebuild.
 
Back
Top Bottom