简体   繁体   English

CLR名称空间不存在

[英]CLR namespace does not exist

I have a C# project with 2 function 我有一个带有2个功能的C#项目

namespace LibiqCommonStructures 
{
  public class BlackLevelData : List<BlackLevelLookupTable>
  {
      public BlackLevelData()
      {
      }

       public BlackLevelData(BlackLevelData original)
          : base(original.DeepCopy())
      {
      }

       public void AddLookupTable(double gain, double exposure, double[] levels)
      {
          var table = new BlackLevelLookupTable
          {
              AnalogGain = gain,
              ExposureTime = exposure,
             ChannelLevels = levels
          };

          Add(table);
      }
  }
}

same for SaturationLevelData 对于SaturationLevelData相同

I created a c++\\CLI project and I want to give the two class into a function as parameters 我创建了一个c ++ \\ CLI项目,我想将两个类作为参数提供给函数

#pragma once
#include "Preprocessor.h"


using namespace LibiqCommonStructures;

namespace ToolBox {

    public ref class PreprocessorWrapper
    {
    public:        
        PreprocessorWrapper();        
        void Function1(BlackLevelData^ blackLevelData, SaturationLevelData^ saturationLevelData);
    private:
        Preprocessor* _preprocessor;
    };
}

header 标头

 #include "PreprocessorWrapper.h"


void ToolBox::PreprocessorWrapper::Function1(BlackLevelData^ blackLevelData, SaturationLevelData^ saturationLevelData)
{    
    _preprocessor->Function1();
}

ToolBox::PreprocessorWrapper::PreprocessorWrapper()
{
    _preprocessor = new Preprocessor();
}

here are the errors I get 这是我得到的错误

Error   2   error C2871: 'LibiqCommonStructures' : a namespace with this name does not exist    g:\iqtool2\src\libiqtool\preprocessor_interop\PreprocessorWrapper.h 5   1   Preprocessor_interop
Error   8   error C2448: 'ToolBox::PreprocessorWrapper::Function1' : function-style initializer appears to be a function definition G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   5   1   Preprocessor_interop
Error   6   error C2065: 'SaturationLevelData' : undeclared identifier  G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   7   error C2065: 'saturationLevelData' : undeclared identifier  G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   4   error C2065: 'BlackLevelData' : undeclared identifier   G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   5   error C2065: 'blackLevelData' : undeclared identifier   G:\IQTool2\src\libiqtool\Preprocessor_interop\PreprocessorWrapper.cpp   4   1   Preprocessor_interop
Error   3   error C2061: syntax error : identifier 'BlackLevelData' g:\iqtool2\src\libiqtool\preprocessor_interop\PreprocessorWrapper.h 13  1   Preprocessor_interop

Can you see what I did wrong here? 你能看到我在这里做错了吗?

yes I have added the C# project as reference 是的,我已经添加了C#项目作为参考 在此处输入图片说明

First, make sure you are building your C++ project with the /clr switch. 首先,请确保使用/ clr开关构建C ++项目。 It is strange you are not referencing at least the System assembly. 奇怪的是,您至少没有引用系统程序集。

Second, the screenshot you provided seems to indicate that your C++/CLI project is using the .NET Framework v4.0. 其次,您提供的屏幕快照似乎表明您的C ++ / CLI项目正在使用.NET Framework v4.0。 Assuming your C# project is using the .NET Framework v4.5, try updating your C++/CLI project to match. 假设您的C#项目正在使用.NET Framework v4.5,请尝试更新您的C ++ / CLI项目以使其匹配。 You can hand-edit the project file (.vcxproj) as follows: 您可以按如下方式手动编辑项目文件(.vcxproj):

<PropertyGroup Label="Globals">
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

I reproduced your issue by changing the version to v4.0 with Visual Studio 2013. 我通过将Visual Studio 2013版本更改为v4.0来重现您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 名称 &lt;...&gt; 不存在于命名空间 clr-namespace &lt;...&gt; - the name <...> does not exist in the namespace clr-namespace <...> 是否在clr-namespace中不存在UIRoot? - UIRoot does not exist in the clr-namespace? XML命名空间clr-namespace:XXX中不存在标记'ViewModelLocator' - The tag 'ViewModelLocator' does not exist in XML namespace clr-namespace:XXX 名称“XYZ”在名称空间“clr-namespace:ABC”中不存在 - The name “XYZ” does not exist in the namespace “clr-namespace:ABC” XML命名空间&#39;clr-namespace:XXX&#39;中不存在标记&#39;XXX&#39; - The tag 'XXX' does not exist in XML namespace 'clr-namespace:XXX' C#WPF-名称“…”在命名空间“ clr-namespace:…”中不存在 - C# WPF - The name “…” does not exist in the namespace “clr-namespace:…” XML名称空间“ clr-namespace:MultiResSnippet”中不存在标签“ MultiResImageChooser” - The tag 'MultiResImageChooser' does not exist in XML namespace 'clr-namespace:MultiResSnippet' 很奇怪XML命名空间“ clr-namespace:”中不存在标记“”。 错误 - weird The tag '' does not exist in XML namespace 'clr-namespace:'. error C# WPF 在命名空间“clr-namespace=local”中不存在 - C# WPF does not exist in the namespace “clr-namespace=local” 名称“ X”在名称空间“ clr-namespace:Y”中不存在 - The name “X” does not exist in the namespace “clr-namespace:Y”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM