Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UnityEngine.dll中的System.Runtime.InteropServices.SEHException_C#_Windows_Visual Studio_Windows Phone 8_Unity3d - Fatal编程技术网

C# UnityEngine.dll中的System.Runtime.InteropServices.SEHException

C# UnityEngine.dll中的System.Runtime.InteropServices.SEHException,c#,windows,visual-studio,windows-phone-8,unity3d,C#,Windows,Visual Studio,Windows Phone 8,Unity3d,我正在为windows phone 8导入unity3D项目。并在unity3D中向对象(SphereScript)的事件更改处理程序添加几行与c#代码交互的代码 var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>(); sphereScript.SphereStateChanged += sphereScript_SphereStateChanged; sphereScript_SphereSta

我正在为windows phone 8导入unity3D项目。并在unity3D中向对象(SphereScript)的事件更改处理程序添加几行与c#代码交互的代码

var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>();
sphereScript.SphereStateChanged += sphereScript_SphereStateChanged;
sphereScript_SphereStateChanged(sphereScript.IsSphereMoving);
var sphereScript=UnityEngine.Object.FindObjectOfType();
sphereScript.SphereStateChanged+=sphereScript_SphereStateChanged;
sphereScript_SphereStateChanged(sphereScript.IsSphereMoving);
这个项目编译得很好,没有错误,但当它在电话上运行时,它会在网上给出一个错误

UnityEngine.Object.FindObjectOfType<SphereScript>();
UnityEngine.Object.FindObjectOfType();

UnityEngine.DLL中发生类型为“System.Runtime.InteropServices.SehexException”的异常,但未在用户代码中处理。我不知道为什么会发生这种错误。但第一次启动项目时,它要求我查找文件名UnityEngineObject.cs。在哪里可以找到此文件,或者如何解决此问题。谢谢


在Unity 5x中,完整代码的Url与问题相同。 所以试试这个:

在脚本SphereScript.cs中:

重新编写以下内容:

public event Action<bool> SphereStateChanged;
现在在私有void Unity_Loaded()中插入以下内容:

最后加上:

void SphereStateChanged(bool currentSpehreState)
{
    Dispatcher.BeginInvoke(() =>
    {
        SphereStateTextBlock.Text = currentSpehreState ? "Spehre is moving" : "Sphere is stopped";
    });
}

祝您好运,再见:)

能否添加引发异常的堆栈跟踪?System.Runtime.InteropServices.SehexException未由用户代码HResult=-2147467259 Message=外部组件引发异常。Source=UnityEngine ErrorCode=-2147467259 StackTrace:at UnityEngine.Internal.$Calli.Invoke38(Int32 arg0,IntPtr方法)at UnityEngine.Object.FindObjectSoftType(类型)at UnityEngine.Object.FindObjectOfType(类型)at UnityEngine.Object.FindObjectOfType[T]()在UnityxamInteractionExample.MainPage.Unity_Loaded()InnerException中:
UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); });

private void Unity_Loaded() { }
ShareScript.SphereStateChanged += SphereStateChanged;
void SphereStateChanged(bool currentSpehreState)
{
    Dispatcher.BeginInvoke(() =>
    {
        SphereStateTextBlock.Text = currentSpehreState ? "Spehre is moving" : "Sphere is stopped";
    });
}