从MSI运行时TypeInitializationException [英] TypeInitializationException when running from the MSI

查看:83
本文介绍了从MSI运行时TypeInitializationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好, 

经过几天不成功的研究后,我来找你。我在Visual Studio 2017和Windows 10下在.NET 4.5中开发了一个WPF应用程序。我在发布模式下生成了我的应用程序,它运行良好。什么时候创建MSI?我的应用程序启动
并在几秒后关闭,在事件日志中我有以下例外:

I come to you after a few days of unsuccessful research. I developed a WPF application in .NET 4.5 under visual studio 2017 and windows 10. I generated my application in Release mode and it works very well. when creating the MSI? my application launches and closes after a few seconds, in the event log I had the following exceptions :

应用程序:Application.exe

版本du框架:v4.0.30319
$
描述:le processusaétéarrétéenraison d'une exceptionnongérée。

信息异常:System.Configuration.ConfigurationErrorsException

   àSystem.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(布尔)

   àSystem.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)

   àSystem.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object,System.Configuration.Internal.InternalConfigEventArgs)



信息异常:System.Configuration.ConfigurationErrorsException

   àSystem.Configuration.ConfigurationManager.PrepareConfigSystem()

   àSystem.Configuration.ConfigurationManager.GetSection(System.String)

   àSystem.Configuration.PrivilegedConfigurationManager.GetSection(System.String)

   àSystem.Net.Configuration.SettingsSectionInternal.get_Section()

   àSystem.Net.Sockets.Socket.InitializeSockets()

   àSystem.Net.NetworkInformation.NetworkChange+ AddressChangeListener.StartHelper(System.Net.NetworkInformation.NetworkAddressChangedEventHandler,Boolean,System.Net.NetworkInformation.StartIPOptions)

   àSystem.Runtime.Remoting.Channels.CoreChannel..cctor()



信息异常:System.TypeInitializationException

   àApplication.MainWindow..ctor()

   àApplication.App..ctor()

   àApplication.App..cctor()



信息异常:System.TypeInitializationException

   àApplication.App.Main(System.String [])

Application : Application.exe
Version du Framework : v4.0.30319
Description : le processus a été arrêté en raison d'une exception non gérée.
Informations sur l'exception : System.Configuration.ConfigurationErrorsException
   à System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean)
   à System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)
   à System.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object, System.Configuration.Internal.InternalConfigEventArgs)

Informations sur l'exception : System.Configuration.ConfigurationErrorsException
   à System.Configuration.ConfigurationManager.PrepareConfigSystem()
   à System.Configuration.ConfigurationManager.GetSection(System.String)
   à System.Configuration.PrivilegedConfigurationManager.GetSection(System.String)
   à System.Net.Configuration.SettingsSectionInternal.get_Section()
   à System.Net.Sockets.Socket.InitializeSockets()
   à System.Net.NetworkInformation.NetworkChange+AddressChangeListener.StartHelper(System.Net.NetworkInformation.NetworkAddressChangedEventHandler, Boolean, System.Net.NetworkInformation.StartIPOptions)
   à System.Runtime.Remoting.Channels.CoreChannel..cctor()

Informations sur l'exception : System.TypeInitializationException
   à Application.MainWindow..ctor()
   à Application.App..ctor()
   à Application.App..cctor()

Informations sur l'exception : System.TypeInitializationException
   à Application.App.Main(System.String[])

在我的App.cs主页中:

In my the Main of my App.cs :

 App()
        {
            InitializeComponent();
            /*
             * Use a timer that start "timer_callback" when launching the application, and tries to re-connect evry 1mn 
             */
            timer = new System.Threading.Timer(timer_callback, null, 0, 60000);
        }
       
        private void timer_callback(object timer_state) 
        {
            //connect_application methode to connect websocket
            view_model.connect_application();
        }
        

        
        // the application starts from the Lync context menu
        [STAThread]
        public static void Main(string[] args)
        {
            string args_param = "Contacts=";
            
            try
            {
                if (args.Length > 1)
                {
                    if (args[2].Contains(args_param))
                    {
                        var contacts_sip_uri = args[2].Split('<', '>')[1];
                        ContactParams.contacts = contacts_sip_uri;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Reading Startup Arguments Error - " + ex.Message);
            }
            if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
            {
                if (application != null)
                {
                    application.Run();
                }
                /*
                 * Allow single instance code to perform cleanup operations
                 */ 
                SingleInstance<App>.Cleanup();
            }
        }

推荐答案

您好J-Go,

Hi J-Go,

您的应用程序启动时它在做什么?如果只检查异常消息,似乎配置中有一些错误,但我不确定。既然你说它在发布模式下运行良好,我建议你可以尝试以管理员模式启动
你的应用程序。因为一般情况下,您的应用程序将在发布模式下以管理员身份运行。

What’s it doing when your application is launching? If just checking the exception message, it seemed that there’re some errors in the configuration, but I’m not sure. Since you said it worked well in release mode, I suggested that you could try to start your application in administrator mode. Because in general, your application would run as administrator in release mode.

最好的问候,

Xavier Xie

Xavier Xie


这篇关于从MSI运行时TypeInitializationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆