Comments (25)
Just solved it in a way that is acceptable for me so for anyone else getting stuck on this @Artaani :
The problem is in that once you add a dynamic assembly (the first time you add a script), this assembly doesn't support .Location and throws a NotSupportedException | "The current assembly is a dynamic assembly, represented by an AssemblyBuilder object."
https://msdn.microsoft.com/en-us/library/system.reflection.assembly.location(v=vs.110).aspx
So this line in ScriptBundleLoader.cs errors out:
domain.GetAssemblies().Select(a => a.Location).ToArray();
I instead replaced it with:
var prevAssemblies = domain.GetAssemblies();
var tempAssemblyRefs = new List<string>();
for (int i = 0; i < prevAssemblies.Length; i++)
{
try
{
tempAssemblyRefs.Add(prevAssemblies[i].Location);
}
catch (System.NotSupportedException e)
{
Debug.Log(e);
}
}
this.assemblyReferences = tempAssemblyRefs.ToArray();
Though it can be done neater probably.
from mcs-icodecompiler.
@z3t0 I finally solved it with the AppDomain.AssemblyResolve. Thank you so much!
from mcs-icodecompiler.
@ioioio8888
Been at this problem for hours, i'm trying to compile many cs files and the 2nd etc have this same error.
If you know how to fix it, simdiff at gmail com PLEASE! :) I'll be here trying stuff to fix it but if you can help I have other work to do.
from mcs-icodecompiler.
@Artaani Hey, sorry there was a line that went missing in the formatting.
I've updated the comment above with the full code. It replaces this line in ScriptBundleLoader.cs:
domain.GetAssemblies().Select(a => a.Location).ToArray();
from mcs-icodecompiler.
@Artaani
As I suspected, there's a way of doing it without try catch, which is a bit neater.
var prevAssemblies = domain.GetAssemblies();
List<string> tempAssemblyRefs = new List<string>();
for (int i = 0; i < prevAssemblies.Length; i++)
{
// In .Net 4 this would would be: if (prevAssemblies[i].IsDynamic)
if (prevAssemblies[i].ManifestModule is System.Reflection.Emit.ModuleBuilder)
continue;
tempAssemblyRefs.Add(prevAssemblies[i].Location);
}
this.assemblyReferences = tempAssemblyRefs.ToArray();
from mcs-icodecompiler.
@Veguard Wow! Perfect!
You basically made C# runtime compiler for Unity! Without this fix it was unusable.
Great job! Thanks you very much!
from mcs-icodecompiler.
What was the problem and how did you fix it ? Some other people might encounter similar problem.
from mcs-icodecompiler.
The problem was that trying to load a second file always failed with the abov error. I didn't really fix it but instead chose to bundle all files into one so its only compiled once. This seemed to be working but then I started to get crashes so now I'm not so sure.
I'll see if I can find a way to fix it since my work around may be buggy itself
from mcs-icodecompiler.
Still working on this but, for now it seems that trying to load a second file will always fail, unless they are loaded together as a bundle.
from mcs-icodecompiler.
I ran into this problem myself, I solved it by implementing the AppDomain.AssemblyResolve Event
https://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(v=vs.110).aspx
I basically just cache all the dynamic assemblies by name, and use a try/catch so when the error comes up it gets looked up in the local dictionary instead. I haven't encountered any problems with this so far.
from mcs-icodecompiler.
Can you give an example of this Lypyl?
from mcs-icodecompiler.
@Lypyl excellent, I was working towards a similar solution but ended up moving onto other projects instead!
from mcs-icodecompiler.
@Lypyl @z3t0 Can You provide some examples to solve this problem? I am also facing the same problem but I don't know how to solve it. Thank you so much
from mcs-icodecompiler.
It's been a long while since I tried this but the issue was that loading a second file using the method in this project would always fail for some reason.
It seems that @Lypyl solved it by checking for an error. I can't exactly remember how I solved it but I did something similar.
from mcs-icodecompiler.
@z3t0 @Lypyl I cant really get the meaning of "looked up in the local dictionary". Can you explain the procedure of doing this? Since I am trying to implement this on unity3d. I want to attach some script at run time, but when I tried to load scripts second time, the problem come up like u mentioned.
from mcs-icodecompiler.
I can't exactly remember the procedure, maybe if you share some code on a gist I could make suggestions?
from mcs-icodecompiler.
Don't support you could share the code for the solution you got for this?
from mcs-icodecompiler.
he's probably not going to bother like the others who also didnt bother submitting in a patch either.. but hey if you do find the solution milo83 maybe do otherwise.
personally i'm not going to even bother using this myself, as this one issue kinda makes the thing pointless.
from mcs-icodecompiler.
hi, if you share your code i can mess around and try to reimplement the solution I had. I would just provide a patch but i lost the files to my old project
from mcs-icodecompiler.
okay never mind i found my code but its not commented at all so im guessing a bit at this point. Though I think these lines may be relevant
public void createInstance(GameObject gameObject, Type t)
{
if (typeof(UnityEngine.Component).IsAssignableFrom(t))
{
gameObject.AddComponent(t);
return;
}
System.Activator.CreateInstance(t);
}
from mcs-icodecompiler.
from mcs-icodecompiler.
@ioioio8888 Hello. I am also tried to solve this problem for a long time, but with no success. Could you please send me a solution too? : ) It would be very helpful.
from mcs-icodecompiler.
I'm also totally lost on this. Can either of you share how you did this with AppDomain.AssemblyResolve @ioioio8888 @z3t0 ?
from mcs-icodecompiler.
@Veguard , thanks for your reply!
I tried to use your code, but there is no "prevAssemblies" variable anywhere. Seems like it is your code.
Can you please, show, where exactly you added this variable and what you do with it?
Or maybe you can upload full Unity project?
It will be extremely helpful.
from mcs-icodecompiler.
@Veguard thank you
from mcs-icodecompiler.
Related Issues (14)
- Unhandled Exception: System.Reflection.ReflectionTypeLoadException HOT 4
- Compiling using CodeCompiler.CompileAssemblyFromSourceBatch() results in an exception HOT 1
- Disable updating files HOT 2
- Compiling mcs HOT 11
- Non-MonoBehaviour Scripts HOT 3
- Issue when trying to compile scripts containing enums HOT 3
- Support Android platform? HOT 1
- Building Unity example for UWP
- [NOT AN ISSUE] Thank you for creating this! HOT 1
- Building On Unity 2017 HOT 8
- Error "assemblyString cannot have zero length" + fix HOT 1
- Conflict with new Visual studio HOT 4
- error occur when using "dynamic" and "enum" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcs-icodecompiler.