我使用Xamarin编写了一个小型Android应用程序。在MainActivity类中,有一部分我可以访问一个名为“ ListColorRGB.txt”的文件。
string path = "C:\\ListColorRGB.txt";
StreamReader sr = new StreamReader(path);
Run Code Online (Sandbox Code Playgroud)
调试时,出现以下异常:
System.IO.FileNotFoundException: Could not find file "//C:\ListColorRGB.txt".
Run Code Online (Sandbox Code Playgroud)
我不知道两个斜杠来自何处,因为我没有首先指定它们?
Visual Studio 13,Windows 8.1
我正在编写一个通过tcp套接字与嵌入式Linux服务器通信的应用程序.我正在寻找一种方法来编写常见的客户端代码定位iOS和Android设备使用Xamarin C#.
我想知道TcpClientclass(System.Net.Sockets)是否可用于pcl目标iOS和Android.如果没有,我还有其他选择吗?
TL; DR为什么(int)Math.Pow(2,32)返回0Mono和Int32.MinValue.NET?
在Mono上测试我编写的.NET代码时,我偶然发现了以下行:
var i = X / ( (int)Math.Pow(2,32) );
那条线路当然没有多大意义,我已经把它改成了long.
然而我很好奇为什么我的代码没有抛出DivideByZeroException.NET所以我已经在Mono和.NET上检查了该表达式的返回值
有人可以解释一下结果吗?
我正在尝试使用Raycast2D来检测攻击是否击中了敌人。我为“敌人”图层创建了一个图层蒙版,并且在“敌人”图层上有一个带有碰撞器的对象。如果不使用LayerMask,我不会撞到对撞机,但是当我这样做时,我什么也没回来。我在这里想念什么?
LayerMask EnemyLayer;
void Start ()
{
EnemyLayer = LayerMask.NameToLayer ("Enemy");
}
public void BasicAttack()
{
PlayerVitality.Stamina = 0;
Vector2 attackDirection = CalculateAttackDirection ();
float attackDamage = CalculateDamage (BasicAttackDamage);
Debug.Log (EnemyLayer.value);
RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x + 2, transform.position.y), attackDirection, BasicAttackDistance, EnemyLayer.value);
if (hit.collider != null)
{
Debug.Log("You hit: " + hit.collider.gameObject.name);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个我要序列化的简单类:
public class InnerCharacter : Object {
public double xp;
public double hp;
}
Run Code Online (Sandbox Code Playgroud)
我累了不同的方法,例如:
public static void TestSerialize()
{
InnerCharacter c = new InnerCharacter();
Serialize(c);
}
static public void Serialize(InnerCharacter details)
{
XmlSerializer serializer = new XmlSerializer(typeof(InnerCharacter));
using (TextWriter writer = new StreamWriter(@"Xml.xml")) {
serializer.Serialize(writer, details);
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过文件流和其他方法,但它们都会导致相同的异常.以下是我尝试在我的一个GameObjects上加载Unity中的代码:
public void Start()
{
TestSerialize();
}
Run Code Online (Sandbox Code Playgroud)
它们都以相同的NullReferenceException失败:
NullReferenceException
System.Reflection.MonoProperty.GetterAdapterFrame[Object,String] (System.Reflection.Getter`2 getter, System.Object obj) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:234)
System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:292)
System.Xml.Serialization.XmlTypeMapMember.GetValue (System.Object ob)
System.Xml.Serialization.XmlSerializationWriterInterpreter.GetMemberValue (System.Xml.Serialization.XmlTypeMapMember member, System.Object ob, …Run Code Online (Sandbox Code Playgroud) 我目前在App.xaml文件中拥有所有样式.有没有办法将它们分组为一个主题,所以我可以多个应用程序主题并随意更改?
我不明白,因为它给了我错误代码:
Socket socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Udp
);
Run Code Online (Sandbox Code Playgroud)
返回错误:
me@machine:~/Demo/bin/Debug$ mono Demo.exe
Marshaling clicked signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: Protocol not supported
at System.Net.Sockets.Socket..ctor (AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) [0x00000] in <filename unknown>:0
...
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
at Demo.MainClass.Main(System.String[] args)
Run Code Online (Sandbox Code Playgroud)
但我的系统支持UDP连接:
me@machine:~$ nc -u -v host.com 53
Connection to host.com 53 port [udp/domain] …Run Code Online (Sandbox Code Playgroud) 我正在尝试从https://github.com/aspnet/home运行示例
我按照文档中的所有步骤操作,但我无法使其工作.
我正在运行dnx . kestrel(在CentOS上),错误是:
System.InvalidOperationException: Unable to load libuv. Make sure libuv is installed and available as libuv.so.1
at Microsoft.AspNet.Server.Kestrel.Networking.Libuv.Load (System.String dllToLoad) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Server.Kestrel.KestrelEngine..ctor (ILibraryManager libraryManager, IApplicationShutdown appShutdownService) [0x00000] in <filename unknown>:0
at Kestrel.ServerFactory.Start (IServerInformation serverInformation, System.Func`2 application) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start () [0x00000] in <filename unknown>:0
Run Code Online (Sandbox Code Playgroud)
我libuv.so.1.0.0在/usr/local/lib
[/usr/local/lib]$ ls
libuv.a libuv.la libuv.so libuv.so.1 libuv.so.1.0.0 pkgconfig
Run Code Online (Sandbox Code Playgroud)
我还为libuv.so.1in /usr/lib和添加了符号链接/usr/lib64
我甚至检查了kestrel的源代码, …
如果这是重新发布的道歉,但我无法从mongodb文档示例中获得我想要的查询.
这是我的问题.我无法在单个查询中执行更新现有文档的array_field或添加新文档并使用初始值初始化array_field.
我可以使用一些条件逻辑的findOne(),并可能解决这个问题,但我认为mongodb有一个这个用例的实现
这是迄今为止的代码:
#data_json = JSON document to be added to collection
collection.update_one({"json_id":data_json["json_id"], "_dashbd_id_":dashboard_id},{{"$addToSet": {"array_field":keyword}},{"$setOnInsert":data_json}}, upsert=True)
Run Code Online (Sandbox Code Playgroud)
我正在查询json_id和我的收藏中的_dashbd_id_.如果它存在,那么我打算将"keyword"添加到array_field.如果它不存在,请创建一个新文档data_json,其中包括array_field = [keyword]
任何提示和建议表示赞赏!
在链接器任务中升级到mvvmcross 4.1后获取编译错误:
The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Boolean MvvmCross.Droid.Shared.Attributes.MvxFragmentAttributeExtensionMethods::IsFragmentCacheable(System.Type)' (defined in 'MvvmCross.Droid.Support.V7.Fragging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') from 'MvvmCross.Droid.Support.V7.Fragging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Boolean MvvmCross.Droid.Shared.Attributes.MvxFragmentAttributeExtensionMethods::IsFragmentCacheable(System.Type)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
--- End of inner exception stack trace ---
at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, …