Skip to content

Unexpected error when refencing an F# project from a C# project #16359

Closed
@francotiveron

Description

Version Used:

Microsoft Visual Studio Professional 2022
Version 17.8.2
VisualStudio.17.Release/17.8.2+34322.80
Microsoft .NET Framework
Version 4.8.09037

Installed Version: Professional

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.8.358.6298
ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.8.358.6298
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.8.358.6298
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.23262.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

File Differ 3.0.49
The easiest way to diff two files directly in Solution Explorer

ILSpy.AddIn 1.0
Integration of the ILSpy Decompiler into Visual Studio.

Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.8.17 (957fbed)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Office Developer Tools for Visual Studio 17.6.34024.01
Microsoft Office Developer Tools for Visual Studio

Python - Django support 17.0.23262.1
Provides templates and integration for the Django web framework.

Python - Profiling support 17.0.23262.1
Profiling support for Python projects.

Python with Pylance 17.0.23262.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.8.3.2353105+f0a326f3e15b2370371693a76fd379635387c74d
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.8.119.0
Microsoft SQL Server Data Tools

Text Macros for Visual Studio 2012-2022 1.18
Brings back text-editing macro support in Visual Studio 2012-2022

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0
Information about my package

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info

Workflow Manager Tools 1.0 1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin 17.8.0.155 (d17-8@7042beb)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.8.3.6 (remotes/origin/d17-8@eccf46a291)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.8.16 (830b56a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: d9a6e87
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

Xamarin.iOS and Xamarin.Mac SDK 16.4.0.23 (9defd91b3)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Steps to Reproduce:
1.
Create solution with 3 projects

P2.fsproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
      <TargetFramework>net4.8</TargetFramework>
      <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Class2.fs" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="NinjaTrader.Core">
        <HintPath>..\..\..\..\..\Program Files\NinjaTrader 8\bin\NinjaTrader.Core.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Update="FSharp.Core" Version="7.0.400-beta.23251.2" />
  </ItemGroup>

</Project>

P3.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
	  <Platforms>x64</Platforms>
	  <TargetFramework>net4.8</TargetFramework>
	  <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
	  <UseWPF>true</UseWPF>
	  <LangVersion>Latest</LangVersion>
	  <RootNamespace>HF</RootNamespace>
  </PropertyGroup>
	<ItemGroup>
    <Reference Include="NinjaTrader.Core">
	    <HintPath>..\..\..\..\..\Program Files\NinjaTrader 8\bin\NinjaTrader.Core.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

P1.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <Platforms>x64</Platforms>
    <TargetFramework>net4.8</TargetFramework>
  </PropertyGroup>
	<ItemGroup>
    <Reference Include="NinjaTrader.Core">
	    <HintPath>..\..\..\..\..\Program Files\NinjaTrader 8\bin\NinjaTrader.Core.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\P2\P2.fsproj" />
    <ProjectReference Include="..\P3\P3.csproj" />
  </ItemGroup>
</Project>
  1. Add the single source code file, respectively

Class2.fs

namespace P2

open NinjaTrader.NinjaScript

type Class2(host: IndicatorBase) = class end

Class3.cs

using NinjaTrader.NinjaScript;

namespace P3 {
    public class Class3 {
        IndicatorBase _host;

        public Class3(IndicatorBase host)
        {
            _host = host;
        }
    }
}

Class1.cs

using NinjaTrader.NinjaScript;

namespace P1 {
    internal class Class1 : IndicatorBase {
        P2.Class2 _c2;
        P3.Class3 _c3;

        public Class1()
        {
            _c2 = new P2.Class2(this);
            _c3 = new P3.Class3(this);
        }
    }
}

Note:

  • All the 3 projects reference a local DLL NinjaTrader.Core.dll (where the type IndicatorBase is defined)
  • That DLL is installed as part of the application NinjaTrader, not sure if this occurs with others DLLs
  • P2 and P3 both define a single class with identical shape (different names and language)
  • P1 references both P2 and P3

Expected Behavior:
Code should compile without errors

Actual Behavior:
Visual studio complains on the instantiation of Class2 in Class1, but not on Class3; the error is

Error CS0012 The type 'IndicatorBase' is defined in an assembly that
is not referenced. You must add a reference to assembly
'NinjaTrader.Core, Version=8.1.2.0, Culture=neutral,
PublicKeyToken=0907d8af90186095'. P1 C:\Temp\Ninja\Test1\Solution1\P1\Class1.cs

image

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions