我在尝试初始化对象时遇到异常。这是例外:
A first chance exception of type 'System.TypeInitializationException' occurred in GeneticProcessorGUI.exe
这是对函数的调用,似乎抛出错误:
ModelingAutomation.MR.Fitness.SSAS.FitnessAurocCv fitnessCalc =
new ModelingAutomation.MR.Fitness.SSAS.FitnessAurocCv("localhost", "CP20141118", "CP20141118", "dbo_DataSourceFraud", 10, 5);
我尝试在函数中添加一些日志,但它没有打印任何日志,所以我认为在执行任何代码之前它在调用中失败了。
这是构造函数代码:
public FitnessAurocCv(string asServerConnectionString, string asDatabaseName, string dataSourceView, string tableName, int numberOfFolds, int foldsToTest)
{
_dataSourceView = dataSourceView;
_tableName = tableName;
_numberOfFolds = numberOfFolds;
_foldsToTest = foldsToTest;
_dataBaseName = asDatabaseName;
_availableVars = CreateVariablesList();
_asServer = new Server();
_log.Debug("Connecting to " + asServerConnectionString);
_asServer.Connect(asServerConnectionString);
_asDatabase = _asServer.Databases[asDatabaseName];
_log.Debug("Connected OK.");
}
可能导致这种情况的原因是什么?我在另一个应用程序中使用完全相同的调用,它工作正常,我没有在网上找到任何有用的东西,并且可以真正使用你的帮助。
以防万一,以下是导致问题的整个类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModelingAutomation.MR.Fitness.SSAS;
namespace GeneticProcessorGUI
{
public class Controller
{
private GeneticProcessorGUI gpgui;
public void startGUI(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
gpgui = new GeneticProcessorGUI(this);
Application.Run(gpgui);
}
public void ProcessPosibleVariables(string server, string database, string datasourceview, string tablename)
{
//MessageBox.Show("PPV");
try
{
//ModelingAutomation.MR.Fitness.SSAS.FitnessAurocCv fitnessCalc =
//new ModelingAutomation.MR.Fitness.SSAS.FitnessAurocCv(server, database, datasourceview, tablename, 10, 5);
ModelingAutomation.MR.Fitness.SSAS.FitnessAurocCv fitnessCalc =
new ModelingAutomation.MR.Fitness.SSAS.FitnessAurocCv("localhost", "CP20141118", "CP20141118", "dbo_DataSourceFraud", 10, 5);
MessageBox.Show("before call");
Dictionary<string, string> vars = fitnessCalc.CreateVariablesListFromSource();
MessageBox.Show("" + vars.ToArray().Length);
foreach (KeyValuePair<string, string> entry in vars)
{
// do something with entry.Value or entry.Key
MessageBox.Show(entry.Value + " , " + entry.Key);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}