在Win7上使用Visual Studio 2012。
我最近通过替换XAML标志< Window>将WPF应用程序转换为WPF用户控件。与< UserControl>并将资源更改为< Control.Resources>。我还改变了代码隐藏以继承UserControl只是为了安全,但在某些时候这破坏了应用程序,我无法再在设计模式下查看它。我得到的只是废话:
System.NullReferenceException
Object reference not set to an instance of an object.
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOutSynchronous(Action action, Int32 targetApartmentId, WaitHandle aborted, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOut(Action action, Int32 targetApartmentId, WaitHandle aborted, CallSynchronizationMode syncMode, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TValue](RemoteHandle`1 targetObject, Action action, CallSynchronizationMode syncMode)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TResult,TValue](RemoteHandle`1 targetObject, Func`2 func, CallSynchronizationMode syncMode)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.CreateDesignerImpl(IHostSourceItem item, IHostTextEditor editor, RemoteCancellationToken remoteCancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.<>c__DisplayClass12.<Microsoft.Expression.DesignHost.IDesignerService.CreateDesigner>b__11(RemoteCancellationToken remoteToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.CallWithCancellation[TResult](CancellationToken cancelToken, Func`2 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.Microsoft.Expression.DesignHost.IDesignerService.CreateDesigner(IHostSourceItem item, IHostTextEditor editor, CancellationToken cancelToken)
at Microsoft.Expression.DesignHost.IsolatedDesignerService.IsolatedDesignerView.CreateDesignerViewInfo(CancellationToken cancelToken)
System.NullReferenceException
Object reference not set to an instance of an object.
Server stack trace:
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalIn(Action action, Int32 targetApartmentId)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn(IRemoteObject targetObject, Action action)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn[TResult](IRemoteObject targetObject, Func`1 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerService.CreateDesigner(IRemoteHostSourceItem remoteItem, IRemoteHostTextEditor remoteEditor, IRemoteCancellationToken remoteToken)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerService.CreateDesigner(IRemoteHostSourceItem remoteItem, IRemoteHostTextEditor remoteEditor, IRemoteCancellationToken cancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.<>c__DisplayClass8.<CreateDesignerImpl>b__6(IRemoteDesignerService d)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass4`2.<MarshalOut>b__3()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
System.NullReferenceException
Object reference not set to an instance of an object.
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOutSynchronous(Action action, Int32 targetApartmentId, WaitHandle aborted, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOut(Action action, Int32 targetApartmentId, WaitHandle aborted, CallSynchronizationMode syncMode, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TValue](RemoteHandle`1 targetObject, Action action, CallSynchronizationMode syncMode)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TResult,TValue](RemoteHandle`1 targetObject, Func`2 func, CallSynchronizationMode syncMode)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalHostProjectService.Microsoft.Expression.DesignHost.IHostProjectService.FindProject(FindProjectCriteria criteria, String criteriaValue)
at Microsoft.Expression.DesignSurface.Project.ProjectContextManager.FindApplicationProjectContext(XamlProjectContext requestingContext)
at Microsoft.Expression.DesignSurface.Project.XamlProjectContext.get_Application()
at Microsoft.Expression.DesignSurface.Documents.SceneDocument.GetApplicationDocument(IXamlProjectContext activeContext)
at Microsoft.Expression.DesignSurface.Documents.SceneDocument.get_ApplicationSceneDocument()
at Microsoft.Expression.DesignSurface.DocumentViewContext.CreateAndOpenView(ISourceItemContext sourceItem, CancellationToken cancelToken, Boolean activate, Boolean ensureOpenInHost, Boolean suppressUI)
at Microsoft.Expression.DesignSurface.DesignerService.CreateDesigner(IHostSourceItem item, IHostTextEditor editor, CancellationToken cancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.<>c__DisplayClass10.<>c__DisplayClass12.<Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerService.CreateDesigner>b__f(CancellationToken cancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.CallWithCancellation[TResult](IRemoteCancellationToken remoteToken, Func`2 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.<>c__DisplayClass10.<Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerService.CreateDesigner>b__e()
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass16`1.<MarshalIn>b__15()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
System.NullReferenceException
Object reference not set to an instance of an object.
Server stack trace:
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalIn(Action action, Int32 targetApartmentId)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn(IRemoteObject targetObject, Action action)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn[TResult](IRemoteObject targetObject, Func`1 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteHostProjectService.Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteHostProjectService.FindProject(FindProjectCriteria criteria, String criteriaValue)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteHostProjectService.FindProject(FindProjectCriteria criteria, String criteriaValue)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalHostProjectService.<>c__DisplayClass7.<Microsoft.Expression.DesignHost.IHostProjectService.FindProject>b__6(IRemoteHostProjectService ps)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass4`2.<MarshalOut>b__3()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
System.NullReferenceException
Object reference not set to an instance of an object.
at MS.Internal.VSUtilities.GetBuildAction(IVsHierarchy hierarchy, UInt32 itemid)
at Microsoft.VisualStudio.ExpressionHost.HostServices.HostSourceItem.<>c__DisplayClass9.<Microsoft.Expression.DesignHost.IHostSourceItem.get_BuildItemType>b__7()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.Invoke(Boolean waitingInExternalCall)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.InvokeCall(Call call)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.DirectInvoke(Action action, Int32 sourceApartmentId, Int32 targetApartmentId, Int32 originId, WaitHandle aborted)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.DirectInvokeInbound(Action action, Int32 targetApartmentId)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalIn(Action action, Int32 targetApartmentId)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn(IRemoteObject targetObject, Action action)
at Microsoft.VisualStudio.ExpressionHost.HostServices.HostSourceItem.Microsoft.Expression.DesignHost.IHostSourceItem.get_BuildItemType()
at Microsoft.Expression.HostUtility.Extensions.HostExtensions.<HasApplicationDocument>b__0(IHostSourceItem i)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.Expression.HostUtility.Extensions.HostExtensions.HasApplicationDocument(IHostProject hostProject)
at Microsoft.VisualStudio.ExpressionHost.HostServices.HostProjectService.FindApplicationProject(String projectPath)
at Microsoft.VisualStudio.ExpressionHost.HostServices.HostProjectService.<FindProjectsInternal>d__30.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Microsoft.VisualStudio.ExpressionHost.HostServices.HostProjectService.Microsoft.Expression.DesignHost.IHostProjectService.FindProject(FindProjectCriteria criteria, String criteriaValue)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteHostProjectService.<>c__DisplayClass1d.<Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteHostProjectService.FindProject>b__1c()
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass16`1.<MarshalIn>b__15()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
经过几次谷歌搜索后,我发现这是2012年的一个热门话题,但从那时起似乎已经全部消失了。但是现在我什么都没有了!我的所有程序集都是3.5+(当时2.0程序集是一个已知问题),我尝试删除引用,但这也没有帮助。除了在控件的负载中实例化IoC之外,我几乎没有进行任何代码更改,但我也完全删除了该代码,但无效。
任何人都有这方面的经验吗?
编辑 - 请注意,如果我添加一个完全没有自定义的新UserControl并尝试查看它,我会收到同样的错误。
编辑2 - 尝试“附加到进程”,当我尝试重新加载设计器时,它没有做任何事情。
答案 0 :(得分:4)
Visual Studio在创建错误的中间文件时出现的错误。只重建所有项目可能无法解决问题。
试试这个,
答案 1 :(得分:1)
其中一个原因可能是某些静态资源绑定到临时为null的对象
它可能是例如绑定到RowData.Row.Property,其中row是另一个资源的当前行,在“设计时”中为null。
更好的方法是使用Converter
绑定到RowData.Rowpublic object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (value is MyContentType)
{
return (value as MyContentType).Property
}
else
{
return defaultValue // this value is valid for wpf control property
}
}
其他原因可能是您的某些转换器或TemplateSelectors未检查传入值为null
可能是别的但我不知道......
答案 2 :(得分:0)
在注意到我的其他同事可以看到控制权之后终于明白了。
在这种情况下的答案似乎是我的视觉工作室仍处于首次发布状态并需要更新到版本4.因此,如果所有其他方法都失败并且其他人遇到此问题,请下载最新的visual studio补丁并踢它关了。我确定它在一段时间内完成安装后会再次运行。