jakubnei / mcs-icodecompiler Goto Github PK
View Code? Open in Web Editor NEWFully C# mannaged ICodeCompiler implementation that uses modified MCS (Mono C# compiler) usable in Unity.
License: Other
Fully C# mannaged ICodeCompiler implementation that uses modified MCS (Mono C# compiler) usable in Unity.
License: Other
When I used the "dynamic" and "enum" as follow:
class DynamicEnum
{
enum TEST
{
t1
}
TEST _test;
void Selected(dynamic param)
{
_test = param;
}
}
I got an error without useful info:
error : 10(18,14): native.DynamicEnum.Selected(dynamic)
UnityEngine.Debug:Log(Object)
CSharpCompiler.UnityLogTextWriter:Log(String) (at Assets/ThridParty/mcs_ICodeCompiler/UnityLogTextWriter.cs:19)
CSharpCompiler.SourceCodeBundle:.ctor(ScriptBundleLoader, IEnumerable1) (at Assets/ThridParty/mcs_ICodeCompiler/ScriptBundleLoader.cs:227) CSharpCompiler.ScriptBundleLoader:LoadAndWatchSourceBundle(IEnumerable
1) (at Assets/ThridParty/mcs_ICodeCompiler/ScriptBundleLoader.cs:41)
But if change the type of _test as "string", the error is disappeared
Error (101): The namespace
global::' already contains a definition for
Test'
Where Test is the name of one of the classes to be compiled (and no it's not already in the project).
It doesn't throw an error if you compile only 1 source string at a time, and CompileAssemblyFromFileBatch() works fine with any number of files.
The best I've been able to determine what is happening is in CompileAssemblyFromSourceBatch(), the subsequent:
Func<Stream> getStream = () => { return new MemoryStream(Encoding.UTF8.GetBytes(source ?? "")); };
overwrite the previous MemoryStreams that are stored in source files, so all the source files end up with the same code.
Assets/CSharpCompiler/CodeCompiler.cs(17,33): error CS0246: The type or namespace name `ICodeCompiler' could not be found. Are you missing an assembly reference?
The same for CompilerResults and CompilerParameters, both cannot be found.
Hi,
Is it possible to not use Synchronized Invoke and instead just compile the files once at startup?
Is it possible to use MCS with Unity targets UWP Apps ?
At the moment it seems that only scripts inheriting MonoBehaviour will work successfully, otherwise the constructor will have to be empty. If a script does not inherit MonoBehaviour but has a non-empty constructor then the following error will be thrown in the Unity Console:
The class being tested here is called "Test"
MissingMethodException: Method not found: 'Default constructor not found...ctor() of RuntimeCSharpCompiler.Test'.
This has something to do with this where System.Activator.CreateInstance does not know what to do when trying to instantiate a class that requires arguments in the constructor.
Do you have any ideas for how to work around this limitation? Currently I am looking into the docs for CreateInstance so I should figure something out soon but was just wondering if you had any thoughts on this.
Thanks!
Hi,
I'd like to compile mcs myself and was wondering if you could add some more details as to how you compiled it. Such as what was removed from the Mono SDK and then what externals were added.
Thank you 😄
below are two errors I'm getting constantly now (after recent update of the unity[2017.3] and visual studio [15.5] for this library, otherwise this is amazing code! )
The imported type `Mono.CSharp.Target' is defined multiple times
Cannot implicitly convert type Mono.CSharp.Target [SyntaxTree.VisualStudio.Unity.Bridge, Version=3.5.0.2, Culture=neutral, PublicKeyToken=null -- C:\Program Files (x86)\Microsoft Visual Studio Tools for Unity\15.0\Editor\SyntaxTree.VisualStudio.Unity.Bridge.dll]' to
Mono.CSharp.Target [mcs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null -- C:\Projects\Game\Assets\Plugins\MCSCompiler\mcs.dll]'. An explicit conversion exists (are you missing a cast?)
I just had to change 3 lines from my code, to make it work with mcs-ICodeCompiler
, and now i can build my game for windows with...
Thank you for spending your time to make this and for sharing it for free!
If i ever finish my game, i will send you a key!
I tried it on the Android platform, but it didn't seem to work. I don't know if my usage is wrong. Has anyone been successful?
thank :)
I'm not entirely sure what's causing this, but I ran into a problem trying to compile any scripts containing enum types. It always results in Unity editor crashing.
I get this error after adding your project to unity. I am using Unity 5, which may be the issue. Here's the full error:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
Hi,
Can you please provide an example for how I can load multiple files? When adding a second file the GUI shows two buttons, loading one script works perfectly, but I get an error whenever I try to load a second script.
Any help is greatly appreciated
NotSupportedException: The invoked member is not supported in a dynamic module.
System.Reflection.Emit.AssemblyBuilder.get_Location () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs:241)
CSharpCompiler.ScriptBundleLoader+ScriptBundle.<ScriptBundle>m__6 (System.Reflection.Assembly a) (at Assets/CSharpCompiler/ScriptBundleLoader.cs:57)
System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[System.Reflection.Assembly,System.String].MoveNext ()
System.Collections.Generic.List`1[System.String].AddEnumerable (IEnumerable`1 enumerable) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:128)
System.Collections.Generic.List`1[System.String]..ctor (IEnumerable`1 collection) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:65)
System.Linq.Enumerable.ToArray[String] (IEnumerable`1 source)
CSharpCompiler.ScriptBundleLoader+ScriptBundle..ctor (CSharpCompiler.ScriptBundleLoader manager, IEnumerable`1 filePaths) (at Assets/CSharpCompiler/ScriptBundleLoader.cs:57)
CSharpCompiler.ScriptBundleLoader.LoadAndWatchScriptsBundle (IEnumerable`1 fileSources) (at Assets/CSharpCompiler/ScriptBundleLoader.cs:33)
CSharpCompiler.DemoLoadScripts.OnGUI () (at Assets/CSharpCompiler/Demo/DemoLoadScripts.cs:61)
(firstly, great resource, thanks!)
Just fixed a tiny bug in ScriptBundleLoader that caused the titular bug.
Line 59 (middle of the LINQ in ScriptBundle constructor), switch:
.Where(a => !(a is System.Reflection.Emit.AssemblyBuilder))
to
.Where(a => (!(a is System.Reflection.Emit.AssemblyBuilder) && !string.IsNullOrEmpty(a.Location)))
to remove blanks.
HTH
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.