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

loading .cs files missing dll References? #344

Closed
bilago opened this issue Nov 2, 2015 · 10 comments
Closed

loading .cs files missing dll References? #344

bilago opened this issue Nov 2, 2015 · 10 comments

Comments

@bilago
Copy link

bilago commented Nov 2, 2015

if I create a .cs script and reference System.Xml for example I get this when trying to load the game:

Failed to compile 'FiveStarResponse.cs' with 1 error(s):
at line 12: The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?)

If I compile the .cs it works without problem. Any way to fix this? Same issue with System.Linq

@crosire
Copy link
Collaborator

crosire commented Nov 2, 2015

Source code scripts are limited to use features in the System, System.Drawing and System.Windows.Forms namespaces. If you need any other reference, it is required to compile the script beforehand.

@crosire crosire closed this as completed Nov 2, 2015
@bilago
Copy link
Author

bilago commented Nov 2, 2015

Any reason you're hard coding just those specific namespaces instead of supporting all System.* references made in the script?

@bilago
Copy link
Author

bilago commented Nov 2, 2015

something simple like the following (hacky approach):

if (extension->Equals(".cs", StringComparison::InvariantCultureIgnoreCase))
    {
        for each(String ^UsingLines in IO::File::ReadAllLines(filename))
        {
            if (UsingLines->StartsWith("using System."))
            {
                compilerOptions->ReferencedAssemblies->Add(UsingLines->Split(' ')[1]);
            }
            else if (UsingLines->StartsWith("public"))
                break;
        }
        compiler = gcnew Microsoft::CSharp::CSharpCodeProvider();
        compilerOptions->CompilerOptions += " /unsafe";
    }

@crosire
Copy link
Collaborator

crosire commented Nov 2, 2015

Using an IDE for developing scripts and compiling them to binaries is the preferred (and more common) way to go. Plain source code scripts are mainly available for quick prototyping, which usually does not need all the framework references. I guess it won't do any damage to add a few more of the most used ones (like System.Xml and System.Linq) though.

@crosire crosire reopened this Nov 2, 2015
@bilago
Copy link
Author

bilago commented Nov 2, 2015

When I give out code to my team members for testing, it's a lot easier to locate crashes with the .cs file as the exceptions will include the line numbers while the already compiled dll can't provide such granular information about the crash/error. Thanks!

@crosire
Copy link
Collaborator

crosire commented Nov 3, 2015

It can actually. Simply put the .pdb the compiler generated in the same directory and line numbers will show up.

@RainerHilmer
Copy link

@bilago If you go with SRP/SOC you shouldn't have to rely on line numbers as you don't have god classes and big methods full of spaghetti code.

@JohnnyCrazy
Copy link
Collaborator

I guess it won't do any damage to add a few more of the most used ones (like System.Xml and System.Linq) though.

What would you guys suggest as a compact, but sufficient, list of references?

@Fireboyd78
Copy link
Contributor

@crosire @JohnnyCrazy How about the following references?

System.Collections.Generic
System.IO
System.Linq
System.Text

@crosire
Copy link
Collaborator

crosire commented Mar 29, 2016

@Fireboyd78 Sounds reasonable, yes.

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

No branches or pull requests

5 participants