0

I'm trying to get a script compiled with Roslyn but whatever I do it keeps complaining about this, at this moment I tried almost everything and have no idea what to try next.

This is the error I get :

'(11,7): error CS0246: The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)'

It is complaining that the namespace can't be found

I already added the references to the file and even added the assemblies to the InteractiveAssemblyLoader but still no luck.

        try
        {
#if (DEBUG)
            var metadataReferences = ApplicationSettings.Instance.GetValuesAsStringList("Script editor", "MetadataReferences_VOP");
#else
            var metadataReferences = ApplicationSettings.Instance.GetValuesAsStringList("Script editor", "MetadataReferences");
#endif

            var scriptOptions = ScriptOptions.Default.WithEmitDebugInformation(true);
            scriptOptions.AddReferences(metadataReferences);

            using var assemblyLoader = new InteractiveAssemblyLoader();

            foreach(var reference in metadataReferences)
                assemblyLoader.RegisterDependency(Assembly.Load(File.ReadAllBytes(reference)));

            scriptRunner = CSharpScript
                .Create<string>(script, scriptOptions, typeof(MainGlobals), assemblyLoader)
                .ContinueWith("new NewEmail().Main(Email)")
                .CreateDelegate();

            exception = null;
            return true;
        }
        catch (Exception e)
        {
            exception = e;
            scriptRunner = null;
            return false;
        }

Is there somebody that has an idea about what to try next?

1 Answer 1

0

It seems that the AddReferences returns a new scriptOptions object that is the one with the added references :-)

So the solution was easy, just do this

scriptOptions = scriptOptions.AddReferences(metadataReferences);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.