C# 类型为'的首次机会例外;系统。未经授权的访问异常';发生在System.Windows.ni.dll中

C# 类型为'的首次机会例外;系统。未经授权的访问异常';发生在System.Windows.ni.dll中,c#,plugins,windows-phone-8,unity3d,admob,C#,Plugins,Windows Phone 8,Unity3d,Admob,我正在尝试为unity3d开发一个windows phone插件来显示admob广告。我是windows phone的新手。我沿着楼梯走。我的windows phone类库类代码为: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using GoogleAds;

我正在尝试为unity3d开发一个windows phone插件来显示admob广告。我是windows phone的新手。我沿着楼梯走。我的windows phone类库类代码为:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GoogleAds;

namespace UnityPluginForWindowsPhone
{
     /**
     * this class belongs to windows phone class library.
     **/
    public class TAdmob
    {
        private static string interstitialAdUnitId;
        private static InterstitialAd interstitialAd;

        public static void InitInterstitialAd(string adUnitId)
        {
            interstitialAdUnitId = adUnitId;
            interstitialAd = new InterstitialAd(adUnitId);           
        }

        public static void ShowInterstitialAd()
        {
            AdRequest adRequest = new AdRequest();
            interstitialAd.ReceivedAd += OnInterstitialAdRecieved;
            interstitialAd.LoadAd(adRequest);            
        }

        private static void OnInterstitialAdRecieved(object sender, AdEventArgs e)
        {
            interstitialAd.ShowAd();
        }

        public static string GetString()
        {
            return "Hello, Not a device";
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnityPluginForWindowsPhone
{
    /**
     * this class belongs to windows class library which is used for the unity editor.
     **/
    public class TAdmob
    {

        public static void InitInterstitialAd(string adUnitId)
        {

        }

        public static void ShowInterstitialAd()
        {

        }
    }
}
我的windows类库类是:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GoogleAds;

namespace UnityPluginForWindowsPhone
{
     /**
     * this class belongs to windows phone class library.
     **/
    public class TAdmob
    {
        private static string interstitialAdUnitId;
        private static InterstitialAd interstitialAd;

        public static void InitInterstitialAd(string adUnitId)
        {
            interstitialAdUnitId = adUnitId;
            interstitialAd = new InterstitialAd(adUnitId);           
        }

        public static void ShowInterstitialAd()
        {
            AdRequest adRequest = new AdRequest();
            interstitialAd.ReceivedAd += OnInterstitialAdRecieved;
            interstitialAd.LoadAd(adRequest);            
        }

        private static void OnInterstitialAdRecieved(object sender, AdEventArgs e)
        {
            interstitialAd.ShowAd();
        }

        public static string GetString()
        {
            return "Hello, Not a device";
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnityPluginForWindowsPhone
{
    /**
     * this class belongs to windows class library which is used for the unity editor.
     **/
    public class TAdmob
    {

        public static void InitInterstitialAd(string adUnitId)
        {

        }

        public static void ShowInterstitialAd()
        {

        }
    }
}
我在日志中得到以下信息:

'TaskHost.exe' (CoreCLR: DefaultDomain): Loaded 'C:\windows\system32\mscorlib.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Windows.RuntimeHost.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Windows.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Net.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Xml.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityPluginTestForWindowsPhone.DLL'. Symbols loaded.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\Microsoft.Phone.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\Microsoft.Phone.Interop.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\WinRTBridge.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\BridgeInterface.winmd'. Module was built without symbols.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityPlayer.winmd'. Module was built without symbols.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\WinMetadata\Windows.winmd'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Runtime.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Core.ni.dll'. Cannot find or open the PDB file.
Build from '' branch, version is '4.3.4f1 (e444f76e01cd)' (Release build).

Physical memory: 907 MB, commited memory limit: 380 MB.

PlayerConnection initialized from C:/Data/Programs/{857FF137-25B1-462A-BC86-829A1236A776}/Install/Data (debug = 0)

PlayerConnection initialized network socket : 0.0.0.0 55344

Multi-casting "[IP] 192.168.0.114 [Port] 55344 [Flags] 2 [Guid] 352403036 [EditorId] 599262348 [Version] 1048832 [Id] WP8Player(192.168.0.114) [Debug] 0" to [225.0.0.222:54997]...

Direct3D:

    Version:  Direct3D 11.0 [level 9.3]

    Renderer: Qualcomm Adreno 305 (WDDM v1.2) (ID=0x30303330)

    Vendor:   Qualcomm

    VRAM:     98 MB

Initialize engine version: 4.3.4f1 (e444f76e01cd)

'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityEngine.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityEngineProxy.DLL'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\Assembly-CSharp.DLL'. Symbols loaded.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\GoogleAds.DLL'. Symbols loaded.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityPluginForWindowsPhone.DLL'. Symbols loaded.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityEngineDelegates.winmd'. Module was built without symbols.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Runtime.InteropServices.WindowsRuntime.ni.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\en-US\mscorlib.debug.resources.dll'. Module was built without symbols.
A first chance exception of type 'System.UnauthorizedAccessException' occurred in Microsoft.Phone.ni.dll
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Runtime.Serialization.ni.dll'. Cannot find or open the PDB file.
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll

Exception: Invalid cross-thread access.
Type: System.UnauthorizedAccessException
Module: System.Windows
InnerException: <No Data>
AdditionalInfo:Invoking AdButton::OnMouseUpAsButton method with argument count: 0
   at MS.Internal.XcpImports.CheckThread()
   at MS.Internal.XcpImports.MessageBox_ShowCore(String messageBoxText, String caption, UInt32 type)
   at System.Windows.MessageBox.ShowCore(String messageBoxText, String caption, MessageBoxButton button)
   at System.Windows.MessageBox.Show(String messageBoxText)
   at UnityPluginForWindowsPhone.TAdmob.ShowInterstitialAd()
   at AdButton.OnMouseUpAsButton()
   at lambda_method(Closure , Object , Object[] , Int32 )
   at WinRTBridge.MethodTools.InvokeMethod(Object instance, Int32 methodIndex, Object[] args)

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/Runtime/Scripting/WinRTUtility.cpp Line: 65)
'TaskHost.exe'(CoreCLR:DefaultDomain):加载了'C:\windows\system32\mscorlib.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.windows.RuntimeHost.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.windows.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.Net.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.Xml.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityPluginTestForWindowsPhone.DLL'。已加载符号。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\Microsoft.Phone.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\Microsoft.Phone.Interop.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\WinRTBridge.DLL'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\BridgeInterface.winmd'。模块是在没有符号的情况下构建的。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityPlayer.winmd'。模块是在没有符号的情况下构建的。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\WinMetadata\windows.winmd'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.Runtime.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.Core.ni.dll'。找不到或无法打开PDB文件。
从“”分支生成,版本为“4.3.4f1(e444f76e01cd)”(发布生成)。
物理内存:907 MB,承诺的内存限制:380 MB。
从C:/Data/Programs/{857FF137-25B1-462A-BC86-829A1236A776}/Install/Data初始化的播放器连接(调试=0)
PlayerConnection已初始化网络套接字:0.0.0.0 55344
多播“[IP]192.168.0.114[Port]55344[Flags]2[Guid]352403036[EditorId]599262348[Version]1048832[Id]WP8Player(192.168.0.114)[Debug]0”到[225.0.0.222:54997]。。。
Direct3D:
版本:Direct3D 11.0[级别9.3]
渲染器:高通Adreno 305(WDDM v1.2)(ID=0x30303330)
供应商:高通公司
VRAM:98MB
初始化引擎版本:4.3.4f1(e444f76e01cd)
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityEngine.DLL'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityEngineProxy.DLL'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\Assembly CSharp.DLL'。已加载符号。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\GoogleAds.DLL'。已加载符号。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityPluginForWindowsPhone.DLL'。已加载符号。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'Anonymously Hosted DynamicMethods Assembly'。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\Data\Programs\{857FF137-25B1-462A-BC86-829A1236A776}\Install\UnityEngineedElegates.winmd'。模块是在没有符号的情况下构建的。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.Runtime.InteropServices.WindowsRuntime.ni.dll'。找不到或无法打开PDB文件。
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\en US\mscorlib.debug.resources.dll'。模块是在没有符号的情况下构建的。
Microsoft.Phone.ni.dll中发生了类型为“System.UnauthorizedAccessException”的首次意外异常
'TaskHost.exe'(CoreCLR:Silverlight AppDomain):加载了'C:\windows\system32\System.Runtime.Serialization.ni.dll'。找不到或无法打开PDB文件。
mscorlib.ni.dll中发生类型为“System.IO.FileNotFoundException”的第一次意外异常
System.Windows.ni.dll中发生类型为“System.UnauthorizedAccessException”的首次意外异常
异常:无效的跨线程访问。
类型:System.UnauthorizedAccessException
模块:System.Windows
内部异常:
AdditionalInfo:调用参数计数为0的AdButton::OnMouseUpAsButton方法
在MS.Internal.XcpImports.CheckThread()处
位于MS.Internal.XcpImports.MessageBox\u ShowCore(字符串MessageBox文本、字符串标题、UInt32类型)
在System.Windows.MessageBox.ShowCore(字符串messageBoxText、字符串标题、MessageBoxButton按钮)
在System.Windows.MessageBox.Show(字符串messageBoxText)
在UnityPluginForWindowsPhone.TAdmob.showInterstitutionAlad()上
在AdButton.OnMouseUpAsButton()上
at lambda_方法(闭包、对象、对象[]、Int32)
位于WinRTBridge.MethodTools.InvokeMethod(对象实例,Int32 methodIndex,对象[]args)
(文件名:C:/BuildAgent/work/d3d49558e4d408f4/Runtime/Scripting/WinRTUtil