1

Using Visual Studio 2012 on Win7.

I recently converted a WPF application to a WPF user control by replacing the XAML flags <Window> with <UserControl> and changing the resources to <Control.Resources>. I also altered the codebehind to inherit from UserControl just to be safe, but at some point this broke the application and I can no longer view it in Design mode. All I get is this nonsense:

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() 

After several googlings I located that this was a hot issue in 2012 but seems to have all but evaporated since then. But now I have nothing to go on! All my assemblies are 3.5+ (2.0 assemblies being a known issue back then) and I tried removing references but that didn't help either. I've made almost no code changes except instantiating an IoC in the control's load, but I also removed that code completely to no avail.

Anyone have any experience with this issue?

Edit - Please note, if I add a new UserControl with absolutely no customization and attempt to view it I get the same error.

Edit 2 - Tried "Attach to Process", it didn't do anything when I tried to reload the designer.

2
  • I had a lot of trouble with the WPF Designer because my Source Code was on a mapped network drive, which is a thing Visual Studio does not like. Maybe this can help Commented Jan 7, 2014 at 16:33
  • My code is, unfortunately, in a subversion repo on my local machine. Thanks though. Commented Jan 7, 2014 at 16:38

3 Answers 3

6

It's the bug of Visual Studio in creating incorrect intermediate files. Only rebuilding all projects may not solve the problem.

Try this,

  1. Close the Visual Studio.
  2. Delete the 'obj' folder.
  3. Reopen Visual Studio.
  4. Rebuild all projects.

Good luck !

Sign up to request clarification or add additional context in comments.

2 Comments

Simply closing and re-opening Visual Studio worked for me.
Can confirm that this happens in VS2019 (16.1.5) too. Everytime I build my Designer goes dead. After Cleaning my project and reopening the designer it works again.
1

One of the reason may be a binding of some your static resource to object which is temporary null

It may be for example binding to RowData.Row.Property where row is current row of another resource, which is null in Design Time.

The better way is Binding to RowData.Row which with Converter

public 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 } } 

Other reason may be that some of your Converters or TemplateSelectors doesn't check incoming value for null

May be something else but i have no idea ....

Comments

0

Finally figured it out after noticing my other coworkers could see the control just fine.

The answer in this case appears to be that my visual studio was still at first release and required an update to version 4. So if all else fails and someone else runs into this issue, download the most recent visual studio patch and kick it off. I'm sure when it's done installing in a little while it'll work again.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.