在我的c#项目中启动时未处理的异常

时间:2017-02-02 06:13:26

标签: c# exception-handling botframework unhandled-exception

我在输出窗口中启动chatbot应用程序时遇到了未处理的异常。

Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll
Exception thrown: 'System.Globalization.CultureNotFoundException' in mscorlib.dll
Exception thrown: 'System.Security.SecurityException' in mscorlib.dll
Exception thrown: 'System.BadImageFormatException' in mscorlib.dll
Exception thrown: 'System.ArgumentNullException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll

我的MessageController中有一些东西

public class MessagesController : ApiController
    {
        private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
        private static DocumentClient client;
        // Retrieve the desired database id (name) from the configuration file
        private static readonly string databaseId = ConfigurationManager.AppSettings["DatabaseId"];
        // Retrieve the desired collection id (name) from the configuration file
        private static readonly string collectionId = ConfigurationManager.AppSettings["CollectionId"];
        // Retrieve the DocumentDB URI from the configuration file
        private static readonly string endpointUrl = ConfigurationManager.AppSettings["EndpointUri"];
        // Retrieve the DocumentDB Authorization Key from the configuration file
        private static readonly string authorizationKey = ConfigurationManager.AppSettings["PrimaryKey"];

        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            Trace.TraceInformation($"Type={activity.Type} Text={activity.Text}");

            //disable the Application Insights and DocumentDb logging in local enviornment
            #if (LOCAL)            
                Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;
            #endif
            #if (!LOCAL)
                if (!String.IsNullOrEmpty(endpointUrl) &&  !String.IsNullOrEmpty(authorizationKey))
                { 
                    using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
                    {
                        await CaptureConversationData(activity);
                    }
                }
            #endif

            if (activity.Type == ActivityTypes.Message)
            {
                //await Microsoft.Bot.Builder.Dialogs.Conversation.SendAsync(activity, () => new ContactOneDialog());

                //Implementation of typing indication
                //ConnectorClient connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));
                //Activity isTypingReply = activity.CreateReply("Shuttlebot is typing...");
                //isTypingReply.Type = ActivityTypes.Typing;
                //await connector.Conversations.ReplyToActivityAsync(isTypingReply);

                logger.Debug("The User's local timeStamp is: " + activity.LocalTimestamp + "and service timeStamp is: " + activity.Timestamp);
                await Conversation.SendAsync(activity, () =>
                new ExceptionHandlerDialog<object>(new ShuttleBusDialog(), displayException: true));
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(System.Net.HttpStatusCode.OK);
            return response;
        }
}

它抛出第一行

private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

这里是快照Exceptioneexception2

如果我的项目从C:\ Users \\ chatbot \ Mybot运行,那么我们就会遇到一个问题。 然后,即使我在例外设置窗口中设置了break异常设置,也不会抛出这些异常。 但是,如果我将项目移动到c:\ Sandy \ MyStuff \ ChatbOt \ MyBot,它会开始抛出所有这些异常,因为我已将异常设置窗口中的中断异常设置。

我真的不明白是什么问题。

1 个答案:

答案 0 :(得分:0)

尝试以管理员身份运行visual studio或以管理员身份运行应用程序,并检查项目所依赖的所有Dll是否都在新路径中。