异常访问第三方dll时调用目标引发的异常

时间:2017-04-19 20:34:59

标签: c# .net-3.5 console-application nullreferenceexception dll-reference

我一直在研究一个C#控制台应用程序,它使用了项目中引用的许多第三方dll。

一切都运行正常,但有一天我的Windows 7操作系统因为自动更新Windows而更新,之后这个应用程序代码开始崩溃,代码调用实际访问数据库的第三方dll。

我将系统恢复到以前的状态,应用程序再次正常运行,但Windows更新再次运行,应用程序再次在同一位置开始崩溃。

我不能停止Windows更新,因为它的公司提供笔记本电脑,我无法更改设置,以便不再发生Windows更新。我没有这个第三方dll的代码。

我可以在这里为你提供app.config ...

                <?xml version="1.0" encoding="utf-8"?>
            <configuration>
              <configSections>
                <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
                <section name="databaseSection" type="Cognizant.CAFE.FoundationServices.Data.Configuration.DatabaseSection,Cognizant.CAFE.FoundationServices.Data"/>
                <section name="cafe.frameworks.foundationAbstraction" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.Configuration.FoundationAbstractionSectionHandler, Cognizant.CAFE.Frameworks.FoundationAbstraction.AdapterFactory"/>
                <section name="loggingConfiguration" type="Cognizant.CAFE.FoundationServices.Logging.Configuration.LoggingConfigurationSection, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                <section name="exceptionManagement" type="Cognizant.CAFE.FoundationServices.ExceptionManagement.Configuration.ExceptionManagementSection, Cognizant.CAFE.FoundationServices.ExceptionManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>

              </configSections>

              <!--<databaseSection performanceCountersEnabled="false" />
              <exceptionManagement performanceCountersEnabled="false" />-->

              <databaseSection defaultDatabase="Sql" dbCommandTimeOut="3000">
                <databases>
                  <add name="Sql" type="Cognizant.CAFE.FoundationServices.Data.SqlHelper,Cognizant.CAFE.FoundationServices.Data" connectionStringName="Sql"/>
                </databases>
              </databaseSection>


              <log4net>
                <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
                  <file value="C:\ApplicationLogs\BGTs\AA\v1.0\AABackgroundTask\Files\Log\AABLog.txt"/>
                  <appendToFile value="true"/>
                  <maximumFileSize value="1500KB"/>
                  <maxSizeRollBackups value="20"/>
                  <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%d [%t] %-5p %c - %m%n"/>
                  </layout>
                </appender>
                <root>
                  <level value="DEBUG"/>
                  <appender-ref ref="RollingFile"/>
                </root>
              </log4net>


              <connectionStrings>
                     -----deleted
              </connectionStrings>

              <appSettings>
                <!--Production-->
                <!-- PROCESS DELAY SECTION -->
                <add key="ProcessDelay" value="0"/>

                <!-- INBOUND -->
                <add key="IB_GlobalVarCreation" value="GlobalVarCreation"/>
                <add key="IB_RoutingScript_In" value="RoutingScript_In"/>

                <!-- OUTBOUND -->
                <add key="OB_CampaignCreation" value="CampaignCreation"/>
                <add key="OB_RoutingScript_Out" value="RoutingScript_Out"/>
                <add key="OB_AdminScript_Agent" value="AdminScript_Agent"/>
                <add key="OB_DisableCampaign" value=" DisableCampaign"/>

                <!-- INBOUND & OUTBOUND -->
                <add key="IB_OB_EnterpriseSkillGroup" value="EnterpriseSkillGroup"/>
                <add key="IB_OB_SkillGroupCreation" value="SkillGroupCreation"/>
                <add key="IB_OB_EnterpriseSkillGroupMap" value="EnterpriseSkillGroupMap"/>
                <add key="IB_OB_CallType" value="CallType"/>
                <add key="IB_OB_DialNumberMapping" value="DialNumberMapping"/>

                <!--NORAML OPERATIONS-->
                <add key="OPS_UserCreation" value="UserCreation"/>
                <add key="OPS_AgentSupervisor" value="AgentSupervisor"/>
                <add key="OPS_Rehire" value="Rehire"/>

                <add key="OPS_AgentTeamCreation" value="AgentTeamCreation"/>

                <add key="OPS_AgentSkillGroup" value="AgentSkillGroup"/>

                <add key="OPS_AgentTeam" value="AgentTeam"/>
                <add key="OPS_SupervisorTeam" value="SupervisorTeam"/>
                <add key="OPS_AgentTeamUpdate" value="AgentTeamUpdate"/>

                <!--Active Directory INFORMATION -->
                <add key="adURL" value="IQOR.QOR.COM"/>
                <add key="adUser" value="IQOR\ERP.IQ.QATCH"/>
                <add key="adPassword" value="+loS96bB8jNKv1JWXVLb0w=="/>

                <!--Others-->
                <add key="OTH_TeamUpdateEnable" value="true"/>
                <add key="OTH_ProgarmPoolIndEnable" value="false"/>

              </appSettings>

              <cafe.frameworks.foundationAbstraction>
                <authorization>
                  <adapters>
                    <add name="CafeProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE.AuthorizationAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" default="True"/>
                    <add name="EnterpriseLibraryProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary.AuthorizationAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                  </adapters>
                </authorization>
                <caching>
                  <adapters>
                    <add name="EnterpriseLibraryProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary.CacheAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" default="True"/>
                  </adapters>
                </caching>
                <dataAccess>
                  <adapters>
                    <add name="CafeProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE.DataAccessAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" default="True"/>
                  </adapters>
                </dataAccess>
                <exceptionManagement>
                  <adapters>
                    <add name="CafeProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE.ExceptionManagerAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" default="True"/>
                    <add name="EnterpriseLibraryProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary.ExceptionManagerAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                  </adapters>
                </exceptionManagement>
                <logging>
                  <adapters>
                    <add name="CafeProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE.LoggingAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" default="True"/>
                    <add name="EnterpriseLibraryProvider" type="Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary.LoggingAdapter, Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.EnterpriseLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                  </adapters>
                </logging>
              </cafe.frameworks.foundationAbstraction>


              <loggingConfiguration>
                <commonSettings loggingEnabled="true" logToTrace="true" useAdditionalParameters="true">
                  <loggingMode asynchronous="False"/>
                  <filters>
                    <allowedLogLevels>
                      <add name="Error"/>
                      <add name="Fatal"/>
                      <add name="Information"/>
                      <add name="Trace"/>
                      <add name="Warning"/>
                    </allowedLogLevels>
                    <allowedLogCategories>
                      <add name="Category"/>
                    </allowedLogCategories>
                  </filters>
                  <publishers>
                    <add name="DBLog" type="Cognizant.CAFE.FoundationServices.Logging.DBPublisher, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                    <add name="EventLog" type="Cognizant.CAFE.FoundationServices.Logging.EventLogPublisher, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                    <add name="MSMQLog" type="Cognizant.CAFE.FoundationServices.Logging.MSMQPublisher, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                    <add name="TextLog" type="Cognizant.CAFE.FoundationServices.Logging.TextFilePublisher, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                    <add name="XMLLog" type="Cognizant.CAFE.FoundationServices.Logging.XMLFilePublisher, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                  </publishers>
                  <formatters defaultFormatter="Text">
                    <add name="Text" type="Cognizant.CAFE.FoundationServices.Logging.TextFormatter, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                    <add name="Xml" type="Cognizant.CAFE.FoundationServices.Logging.XMLFormatter, Cognizant.CAFE.FoundationServices.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                  </formatters>
                </commonSettings>
                <logSettings defaultCategory="Category">
                  <categories>
                    <add categoryName="Category">
                      <categorySettings>
                        <add levelName="Error">
                          <sinks>
                            <add publisherName="TextLog" formatterName="Text" fileName="AABLog.txt" maxFileSize="1MB"/>
                          </sinks>
                        </add>
                      </categorySettings>
                    </add>
                  </categories>
                </logSettings>
              </loggingConfiguration>


              <exceptionManagement>
                <policies defaultPolicy="UI Policy">
                  <add name="UI Policy" type="">
                    <exceptions>
                      <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
                        <handlers>
                          <add name="Log Handler" type="Cognizant.CAFE.FoundationServices.ExceptionManagement.LogHandler, Cognizant.CAFE.FoundationServices.ExceptionManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                        </handlers>
                      </add>
                    </exceptions>
                  </add>
                </policies>
                <messageSources defaultSource="Xml">
                  <add name="Xml" type="Cognizant.CAFE.FoundationServices.ExceptionManagement.XmlMessageSource, Cognizant.CAFE.FoundationServices.ExceptionManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" source="D:\Cognizant\CAFE.NET 2.0\Foundation Services\QuickStart\Web\ExceptionMessages.xml"/>
                </messageSources>
              </exceptionManagement>


              <system.web>
                <membership defaultProvider="ClientAuthenticationMembershipProvider">
                  <providers>
                    <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
                  </providers>
                </membership>
                <roleManager defaultProvider="ClientRoleProvider" enabled="true">
                  <providers>
                    <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
                  </providers>
                </roleManager>
              </system.web>
            <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

我的应用程序崩溃或发出异常的代码如下:

public DataSet GetData(string statementId, string parameter)
    {
        object[] param = null;
        DataSet ds = null;
        try
        {
            if (parameter != null)
            {
                param = new object[1];
                param[0] = parameter;
                ds = DataAccessFaçadeAdapter.ExecuteStatementForDataSet(statementId, param);
            }
            else
            {
                ds = ExecuteStoredProcedure(statementId);
            }
        }
        catch (Exception ex)
        {
            Tracer.Trace(TraceLevel.Error, "GetData() Exception is" + ex.Message);
        }
        return ds;
    }

这里以下行是我得到异常的地方,因为这个方法写在第三方dll中,我没有任何代码

ds = DataAccessFaçadeAdapter.ExecuteStatementForDataSet(statementId, param);

例外情况详情如下:

-       InnerException  {"Object reference not set to an instance of an object."}   System.Exception {System.NullReferenceException}

        Message "Object reference not set to an instance of an object." string

Stack Trace如下:

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Cognizant.CAFE.Frameworks.FoundationAbstraction.AdapterFactory.GetAdapter[T]()
at IQOR.QATCH.IntegrationServices.DataAccessFaçadeAdapter.ExecuteStatementForDataSet(String StatementID, Object[] parameters)
at IQOR.AA.BackgroundTask.Exporter.GetData(String statementId, String parameter) in C:\\AutomationAnywhere_OLD_CODE\\AutomationAnywhere_OLD\\IQOR.AA.BackgroundTask - Copy\\IQOR.AA.BackgroundTask\\Exporter.cs:line 433

第三方dll的堆栈跟踪如下:

at Cognizant.CAFE.FoundationServices.Data.AdoHelperFactory.GetConnectionString(String providerName)
at Cognizant.CAFE.FoundationServices.Data.AdoHelperFactory.CreateHelper(String providerName)
at Cognizant.CAFE.FoundationServices.Data.AdoHelperFactory.CreateHelper()
at Cognizant.CAFE.Frameworks.FoundationAbstraction.Adapters.CAFE.DataAccessAdapter..ctor()

请告知如何解决。

1 个答案:

答案 0 :(得分:0)

确定第三方DLL是否有更新。通常系统更新针对发现的安全漏洞,而这个目标dll 可能存在一些与相关的问题。

否则,您可能希望实现不同的数据访问方法,甚至将应用程序移动到可能具有最新方法的.Net 4。