将项目从Visual Studio 2005移动到2012 - System.ArgumentNullException,多个错误

时间:2015-05-26 09:32:12

标签: c# c++ visual-studio visual-studio-2012 visual-studio-2005

我目前正在尝试将现有项目从VS 2005迁移到VS 2012.该项目是用C#编写的,包含一些更老的C ++代码,用作某些特定科学计算的核心。这些部分通过C ++中的包装层连接。

我在VS 2012中打开了现有的主项目,并让它做了导入旧项目文件的事情。然后我尝试逐个编译每个项目。我更换了一些较旧的库(例如boost),现在卡住了。

我收到此错误,我无法解决,因为VS不会告诉我错误发生在哪一行。我尝试过Resharper,但它似乎没有在这个特定的项目中找到错误(虽然我第一次使用Resharper并且它在其他项目中发现了数百个错误和警告)。

1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018: The "NativeCodeAnalysis" task failed unexpectedly.
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018: Microsoft.VisualStudio.CodeAnalysis.AnalysisResults.AnalysisResultException:       CA0001 : An unknown error occurred while running Code Analysis. ---> System.ArgumentNullException: Value cannot be null.
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018: Parameter name: path2
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    at System.IO.Path.Combine(String path1, String path2)
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    at Microsoft.Build.Tasks.TaskCommon.GetRuleSetFullPath(String ruleSet, String projectDirectory, String[] ruleSetDirectories)
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    at Microsoft.Build.Tasks.NativeCodeAnalysis.Execute()
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    --- End of inner exception stack trace ---
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    at Microsoft.Build.Tasks.NativeCodeAnalysis.Execute()
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(342,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()


I spent hours trying to find a solution to my problem. So if my question is badly asked - please try to help nonetheless and tell me what information is needed.

这是项目的.cpp文件的代码:

namespace Trace 
{
  CTraceWrapper::CTraceWrapper(const char *LibName) : CBaseWrapper(LibName), m_GetTraceTextProc(NULL)
  {
    if (m_hModInstance != NULL)
    {
      m_GetTraceTextProc = (tGetTraceText)GetProcAddress(m_hModInstance, "getTraceText");
    }
  }
  int CTraceWrapper::getTraceText(t_TraceTextMap& traceTextMap, bool bDelete)
  {
#ifdef _TRACE_ACTIVE
    if (m_GetTraceTextProc == NULL)
    {
      return RESULT_ERR_INVALID_FUNCTION_HANDLE;
    }
    m_GetTraceTextProc(traceTextMap, bDelete);
#endif

    return RESULT_OK;
  }

  CTraceWrapper Wrapper("trace.dll");

  int TraceWrapper::GetTraceList(array<TraceData^> ^%traceMap, bool bDelete)
  {
    t_TraceTextMap traceTextMap;

    int nRet = Wrapper.getTraceText(traceTextMap, bDelete);

    if (nRet != 0)
    {
      return nRet;
    }

    TraceData^ Data;

    String^ Tmp;

    array<String^> ^Split;

    int Length = 0;

    if (nRet == RESULT_OK)
    {
      traceMap = gcnew array<TraceData^>(traceTextMap.size());

      int i = 0;

      for (t_TraceTextMap::const_iterator cit = traceTextMap.begin(); cit != traceTextMap.end(); cit++)
      {
        Data = gcnew TraceData();

        Data->Time = cit->first;

        Tmp = gcnew String(cit->second.chars());

        Split = Tmp->Trim()->Split('|');

        Data->Type = Convert::ToInt16(Split[0], CultureInfo::CurrentCulture);

        Data->Module = Convert::ToInt16(Split[1], CultureInfo::CurrentCulture);

        Data->ProcessId = Convert::ToInt32(Split[2], CultureInfo::CurrentCulture);

        Data->ThreadId = Convert::ToInt32(Split[3], CultureInfo::CurrentCulture);

        Length = Split->GetLength(0);

        Data->FunctionName = ((Length > 5) ? Split[5] : String::Empty);

        Data->FileName = ((Length > 4) ? Split[4] : String::Empty);

        Data->Line = ((Length > 6) ? Convert::ToInt32(Split[6], CultureInfo::CurrentCulture) : 0);

        Data->Text = ((Length > 7) ? Split[7] : String::Empty);

        if ((Data->Type == TRACE_TYPE_TIMING_END) && (Length > 8))
        {
          Data->Interval = Convert::ToDouble(Split[8], CultureInfo::InvariantCulture);
        }

        traceMap[i++] = Data;
      }
    }

    return RESULT_OK;
  }
}

1 个答案:

答案 0 :(得分:0)

尝试打开失败的项目的csproj文件并检查它。在VS2015中,csproj文件是msbuild文件。这是我能想到的一个选项,另一个是尝试关闭代码分析。