本文介绍了无法在MacOS的Unity和MonoDevelop中使用.NET的JavaScriptSerializer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用.NET的System.Web.Script.Serialization.JavaScriptSerializer在MacOS上的MonoDevelop中将JSON文件读入字典中.

I'm trying to use .NET's System.Web.Script.Serialization.JavaScriptSerializer to read a JSON file into a Dictionary in Unity with MonoDevelop on MacOS.

到目前为止,我已经在MonoDevelop中添加了System.Web.Extensions程序集,这使得它可以很好地构建"Assembly-CSharp"项目.

So far I've added the System.Web.Extensions assembly to MonoDevelop which makes it build the "Assembly-CSharp" project fine.

但是当我回到Unity时,它仍然显示错误:错误CS0234:名称空间"System"中不存在类型或名称空间名称"Web".您是否缺少程序集参考?

But when I go back to Unity, it still shows the error: error CS0234: The type or namespace name `Web' does not exist in the namespace `System'. Are you missing an assembly reference?

然后我在网上阅读到将DLL添加到资产文件夹中的任何位置都可以,因此我在MonoDevelop的路径中找到文件System.Web.Extensions.dll的某些版本,它们位于:/Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Versions/2.10.2/lib/mono/gac/System.Web.Extensions

Then I read on the web that adding the DLL anywhere into the assets folder would do, so I found some versions of the file System.Web.Extensions.dll inside MonoDevelop's path, they are in: /Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Versions/2.10.2/lib/mono/gac/System.Web.Extensions

有3个文件夹,其文件版本不同:1.0.61025.0__31bf3856ad364e353.5.0.0__31bf3856ad364e354.0.0.0__31bf3856ad364e35

There are 3 folders with different versions of the file: 1.0.61025.0__31bf3856ad364e35, 3.5.0.0__31bf3856ad364e35 and 4.0.0.0__31bf3856ad364e35

尝试了所有这些方法,但均无效果,Unity给出此错误:

Tried all of them, but none works, Unity gives this error:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
File name: 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
  at (wrapper managed-to-native) System.Reflection.Assembly:InternalGetType (System.Reflection.Module,string,bool,bool)
  at System.Reflection.Assembly.GetType (System.String name, Boolean throwOnError, Boolean ignoreCase) [0x00000] in <filename unknown>:0
  at System.Reflection.Assembly.GetType (System.String name) [0x00000] in <filename unknown>:0
  at Mono.CSharp.RootNamespace.GetTypeInAssembly (System.Reflection.Assembly assembly, System.String name) [0x00000] in <filename unknown>:0
  at Mono.CSharp.RootNamespace.LookupTypeReflection (Mono.CSharp.CompilerContext ctx, System.String name, Location loc, Boolean must_be_unique) [0x00000] in <filename unknown>:0
  at Mono.CSharp.GlobalRootNamespace.LookupTypeReflection (Mono.CSharp.CompilerContext ctx, System.String name, Location loc, Boolean must_be_unique) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Namespace.LookupType (Mono.CSharp.CompilerContext ctx, System.String name, Location loc) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Namespace.Lookup (Mono.CSharp.CompilerContext ctx, System.String name, Location loc) [0x00000] in <filename unknown>:0
  at Mono.CSharp.TypeManager.CoreLookupType (Mono.CSharp.CompilerContext ctx, System.String ns_name, System.String name, Kind type_kind, Boolean required) [0x00000] in <filename unknown>:0
  at Mono.CSharp.TypeManager.InitCoreTypes (Mono.CSharp.CompilerContext ctx) [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

那么,现在怎么办?

推荐答案

Unity使用了不支持.NET 4的旧版Mono.我相信,由于System,他们也删除了System.Web.dll以使其精简. Web主要包含ASP.NET,它与游戏开发人员并没有真正的联系.

Unity uses an old version of Mono that does not support .NET 4. I believe they also remove System.Web.dll to slim it down, since System.Web mostly contains ASP.NET which isn't really relevant to game developers.

您也许可以复制Mono的dll,但是请确保使用System.Web.dll的v2.0和System.Web.Extensions.dll的v3.5.

You might be able to copy over Mono's dlls, however make sure you use v2.0 of System.Web.dll and v3.5 of System.Web.Extensions.dll.

或者,您可以尝试JSON.NET.

Alternatively you might try JSON.NET.

这篇关于无法在MacOS的Unity和MonoDevelop中使用.NET的JavaScriptSerializer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 21:57