Encog dll in Unity?

2019-07-02 06:28发布

问题:

I would like to implement Encog to Unity. When I put dll in assets, no errors occur. I can even create new neural networks with no errors.

When I paste XOR example to script, I get error shown below. I googled its somehow related that Encog uses parts of C# that arent covered in Unity mono behaviour.

Some people say that I should use dll built by net framework 3.5, but when I try to load solution file in visual basic, I get another errors similar to this:

Error   1   The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)  C:\Programs\Unity\ncog\encog-dotnet-core-3.2.0\encog-core-cs\Util\Concurrency\Job\ConcurrentJob.cs  24  24  encog-core-cs

I tried modifying build.bat included with encog source so that it uses path to 3.5 framework: C:\Windows\Microsoft.NET\Framework64\v3.5\msbuild (This compiles with no errors/warnings) but when I try to use this dll in unity, I get same error as with dll normaly distributed on encog site.

Error in unity when trying to safe example script with XOR

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.TypeLoadException: Could not load type 'Encog.ML.Train.BasicTraining' from assembly 'encog-core-cs, Version=3.2.0.0, Culture=neutral, PublicKeyToken=3e882172b12155d4'.

  at (wrapper managed-to-native) System.MonoType:GetMethodsByName (string,System.Reflection.BindingFlags,bool,System.Type)

  at System.MonoType.GetMethods (BindingFlags bindingAttr) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.MemberCache.AddMethods (BindingFlags bf, System.Type type) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.MemberCache.AddMethods (System.Type type) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.MemberCache..ctor (IMemberContainer container) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle..ctor (System.Type type) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle.GetTypeHandle (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle.GetMemberCache (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeManager.LookupMemberCache (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle..ctor (System.Type type) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle.GetTypeHandle (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle.GetMemberCache (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeManager.LookupMemberCache (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle..ctor (System.Type type) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle.GetTypeHandle (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeHandle.GetMemberCache (System.Type t) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeManager.MemberLookup_FindMembers (System.Type t, MemberTypes mt, BindingFlags bf, System.String name, System.Boolean& used_cache) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeManager.RealMemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.TypeManager.MemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.MemberLookup (Mono.CSharp.CompilerContext ctx, System.Type container_type, System.Type qualifier_type, System.Type queried_type, System.String name, MemberTypes mt, BindingFlags bf, Location loc) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.MemberLookupFinal (Mono.CSharp.ResolveContext ec, System.Type qualifier_type, System.Type queried_type, System.String name, MemberTypes mt, BindingFlags bf, Location loc) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.New.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 

  at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0 

回答1:

This seems to be a common issue with DLL support. I've seen similar questions from people trying to connect Encog to Ninjatrader. The current version of Ninjatrader supports an outdated (several versions behind) version of .Net, with no LINQ support. I assume Unity3D has a similar issue. I am not an active developer in Ninjatrader or Unity3D. I really do not want to support both a Ninjatrader and Unity3D version (only so many hours in the day). Yet the later versions of .Net support some very useful features in LINQ, as well as very advanced palatalization features.

I suppose one answer would be to create a very basic non-LINQ/non-Parallel that is compatible to any .Net version within the last 10 years.