Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums are being flag as an error #462

Open
kwcoffee1 opened this issue Mar 25, 2023 · 1 comment
Open

Enums are being flag as an error #462

kwcoffee1 opened this issue Mar 25, 2023 · 1 comment

Comments

@kwcoffee1
Copy link

kwcoffee1 commented Mar 25, 2023

Describe the bug

A sample code snippet:

`Hi,

I'm trying to reference a Enum created in the dll test.dll.

The Enum "EDKPivotType" was created in the file "PathToMyCompiledScript\test.cs".
The file "test.cs" compile and create the test.dll file OK.

In the code sntppet below (which consumes file test.dll) intellisense recognize the enum "EDKPivotType" and it shows all the enum selections associated with it. However, the default editor used to demonstrate RoslynPad 17 (4.4.0) underlines the enum variable EDKPivotType in RED. The error is: CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. Nevertheless, intellisence paints this enum with a foreground color of green. I do reference System.Private.CoreLib.

RoslynPad 17, Version 4.4.0

`
#r "PathToMyCompiledScript\test.dll"

using System;
using ...

class Program
{
static void Main()
{
EDKPivotType testenum = EDKPivotType.HLURD; // This line is flagged as an error
string name = testenum ?.ToString() ?? "Error";
}
}
`

To Reproduce

Create a CS file with an Enum. Create a second file to consume the enum as above.

Expected behavior

The sample script above should compile error free.

Version

RoslynPad 17, 4.4.0
Windows 11
VS 2022 17.5.3

Thank you for your time and effort.

@kwcoffee1
Copy link
Author

kwcoffee1 commented Jun 23, 2023

How can I get RoslynPad 17 to load NetCoreApp references?

I am invoking the apis from the RoslynPad 17 (4.4.0) editor. Using the following code snippet:

`
private static string AppPath
{
get //** This is how I find the bin folder in the main project to load supporting modules.
{
string main = "CoffeeBot_DeskTop";
string dir = Directory.GetCurrentDirectory();
int i = dir.IndexOf(main) + main.Length;

#if DEBUG
return Path.Combine(dir.Substring(0, i),
"CoffeeBot_DeskTop\bin\Debug\net7.0-windows\");
#else
return Path.Combine(dir.Substring(0, i),
"CoffeeBot_DeskTop\bin\Release\net7.0-windows\");
#endif
}
}

private static IEnumerable DefaultReferences()
{
// Find the Directory root by one of it's objects.
var corePath = Path.GetDirectoryName(typeof(object).Assembly.Location) +
Path.DirectorySeparatorChar;
var deskPath = Path.GetDirectoryName(typeof(MessageBox).Assembly.Location) +
Path.DirectorySeparatorChar;

IEnumerable<string> DLLs = new[]
{
    AppPath + "API.dll",
    AppPath + "Prism.dll",
    AppPath + "Acquisition.dll",
    AppPath + "Infrastructure.dll",
    AppPath + "CoffeeBot_DeskTop.dll",
    AppPath + "Skender.Stock.Indicators.dll",

    corePath + "System.dll",
    corePath + "mscorlib.dll",
    corePath + "System.Core.dll",
    corePath + "System.Linq.dll",
    corePath + "System.Runtime.dll",
    corePath + "Microsoft.CSharp.dll",
    corePath + "System.Reflection.dll",
    corePath + "System.Collections.dll",
    corePath + "System.Globalization.dll",
    corePath + "System.Net.Primitives.dll",
    corePath + "System.Private.CoreLib.dll",        //** I am loading it here (this is required)
    corePath + "System.Linq.Expressions.dll",
    corePath + "System.Collections.Concurrent.dll",
    corePath + "System.Collections.NonGeneric.dll",
    corePath + "System.Text.RegularExpressions.dll",
    corePath + "System.ComponentModel.Primitives.dll",

    deskPath + "PresentationCore.dll",
    deskPath + "PresentationFramework.dll",
};

var References = new List<MetadataReference>();

foreach (var dll in DLLs)
{
    References.Add(AssemblyMetadata.CreateFromFile(dll).GetReference());
};

return References;

}

// Creating these defaults are redundant and are not required
private static readonly IEnumerable DefaultNamespaces =
new[]
{
"System",
"System.IO",
"System.Net",
"System.Linq",
"System.Text",
"Prism.Events",
"Infrastructure",
"System.Windows",
"System.Collections",
"Infrastructure.Enums",
"Skender.Stock.Indicators",
"System.Collections.Generic",
"System.Collections.ObjectModel",
"System.Text.RegularExpressions",
};

//**************** I am compiling as so:

var compilation = CSharpCompilation.Create(
    codeAssemblyFile,
    syntaxTrees: Trees,
    references: DefaultReferences(),
    options: DefaultCompilationOptions);

`
I also try loading "Basic.Reference.Assemblies.Net70.dll"
but I get lots of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant