Мой exe разъем внезапно перестал работать на windows машине. (Сборка с c# в визуальной студии) - PullRequest
0 голосов
/ 14 февраля 2020

Я создал сервисное приложение в visual studio, используя c#, и отлично работал на windows машине, но внезапно однажды он перестает работать. когда я смотрю в средство просмотра событий, я получаю оттуда этот журнал

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name=".NET Runtime" /> 
<EventID Qualifiers="0">1026</EventID> 
<Level>2</Level> 
<Task>0</Task> 
<Keywords>0x80000000000000</Keywords> 
<TimeCreated SystemTime="2020-02-13T15:09:51.945244700Z" /> 
<EventRecordID>32886</EventRecordID> 
<Channel>Application</Channel> 
<Computer>asus</Computer> 
<Security /> 
</System>
<EventData>
<Data>Application: sage50-uk-2019-v25.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidCastException at sage50_uk_2019_v25.Service1..cctor() Exception Info: System.TypeInitializationException at sage50_uk_2019_v25.Service1..ctor() at sage50_uk_2019_v25.Program.Main(System.String[])</Data> 

Я прошел через многие разрешения в Интернете, но ничего полезного для моей ситуации. Примечание: на других машинах все еще работает. Итак, я думаю, что-то случилось на машине или windows ОС.

Код для моей основной функции на program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace sage50_UK_v26_2_136_0
{
    static class Program
    {
        static void Main()
        {
            Service1 myService = new Service1();
            myService.OnDebug();
            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
        }
    }
}

Конструктор для класса обслуживания:

public partial class Service1 : ServiceBase
{
    public void OnDebug()
    {
        OnStart(null);
    }
    protected override void OnStart(string[] args)
    {
        EventHandler handler = initApp;
        handler?.Invoke(this, null);
    }

    public void initApp(object sender, EventArgs e)
    {
        do
        {
            try
            {
                // adding application into startup program
                Microsoft.Win32.RegistryKey rkApp = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                rkApp.SetValue(applicationName, "\"" + Application.ExecutablePath.ToString() + "\"");
                deQueue(sender, e);
                addTimer();

            }
            catch (Exception ex)
            {
                WriteToLogFile("SDO Generated the Following Error: \n\n" + ex.Message);
                System.Threading.Thread.Sleep(pauseThreadInMilliSeconds);
                initApp(sender, e);
            }

            // loop while we're pending and the user is retrying
        } while (companyName == "" || apiKey == "");
    }
}
...