【发布时间】:2012-02-27 14:24:34
【问题描述】:
我目前正在为 WP7 制作一款游戏,该游戏主要使用 Silverlight 制作。但现在我需要一个可以使用 XNA 的页面。 XNA 页面将接收战斗数据,然后将其可视化为用户。
我尝试在我的解决方案中创建一个“Windows Phone Silverlight 和 XNA”项目(BattleSimulator)并导航到 GamePage.xaml。但我在 (Application.Current as App) 上收到 NullReferenceException 和警告。警告在 BattleSimulator 项目中。
警告
Warning 1 The project 'BattleSimulatorLib' cannot be referenced. The referenced project is targeted to a different framework family (.NETFramework)
代码
public GamePage()
{
InitializeComponent();
// Get the content manager from the application
contentManager = (Application.Current as App).Content; //NullReference here
堆栈跟踪
at BattleSimulator.GamePage..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type)
at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)
at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
解决这个问题的一种方法是将我所有的 silverlight 类和标记复制到一个新的 SL 和 XNA 项目中,但这是我的 if-all-else-fails 计划。
有谁知道如何解决这个 NullReferenceException 或警告?还是我应该尝试以其他方式做到这一点?
编辑:在此处找到有关警告的信息:http://forums.create.msdn.com/forums/p/93769/561676.aspx 它是无害的。
【问题讨论】:
标签: silverlight windows-phone-7 xna nullreferenceexception