UnresolvedAssemblyException in Blend for VS design view ONLY - works fine in VS design view

.NET Framework: 4.5.1

I'm getting a curious error in Blend for visual studio 2015 which I cannot find the source of.

If I open my WPF solution in VS, it loads and runs fine. The design view also works.

However, if I open my WPF solution in Blend, whenever I open any of my .xaml files in the designer, they load briefly (for about a second)and then throw the following error:

Microsoft.MetadataReader.UnresolvedAssemblyException
Type universe cannot resolve assembly: System.Runtime, Version=4.0.0.0, 

Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
   at Microsoft.MetadataReader.SimpleUniverse.Microsoft.MetadataReader.ITypeUniverse.ResolveAssembly(AssemblyName name)
   at Microsoft.MetadataReader.SimpleUniverse.Microsoft.MetadataReader.ITypeUniverse.ResolveAssembly(Module scope, Token tokenAssemblyRef)
   at Microsoft.MetadataReader.MetadataOnlyModule.ResolveTypeRef(ITypeReference typeReference)
   at Microsoft.MetadataReader.MetadataOnlyTypeReference.GetResolvedTypeWorker()
   at Microsoft.MetadataReader.TypeProxy.GetResolvedType()
   at Microsoft.MetadataReader.TypeProxy.GetHashCode()
   at System.Collections.Generic.ObjectEqualityComparer`1.GetHashCode(T obj)
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Metadata.XamlPlatformMetadata.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.TypeResolver.GetType(String key, IAssembly assembly, Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.TypeResolver.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Metadata.XamlProjectMetadata.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.ProjectContextType.Cache()
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.ProjectContextType.Initialize(IXmlNamespace xmlNamespace, Type type)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Metadata.MockType.Initialize(IXmlNamespace xmlNamespace, Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.TypeResolver.GetType(String key, IAssembly assembly, Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.TypeResolver.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Metadata.XamlProjectMetadata.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.ProjectContextType.Cache()
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.ProjectContextType.Initialize(IXmlNamespace xmlNamespace, Type type)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Metadata.MockType.Initialize(IXmlNamespace xmlNamespace, Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.TypeResolver.GetType(String key, IAssembly assembly, Type type)
   at Microsoft.VisualStudio.DesignTools.Platform.Metadata.TypeResolver.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Metadata.XamlProjectMetadata.GetType(Type type)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Tools.Assets.AssemblyAssetProvider.SynchronizedInitialize()
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Tools.Assets.AssemblyAssetProvider.UpdateAssets()
   at Microsoft.VisualStudio.DesignTools.Designer.Tools.Assets.AssetProvider.Update()
   at Microsoft.VisualStudio.DesignTools.Designer.Tools.Assets.AssetLibrary.UpdateAssetProvidersWorker()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation operation, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority)
   at Microsoft.VisualStudio.DesignTools.Platform.Utility.UIThreadDispatcherHelper.Invoke(DispatcherPriority dispatcherPriority, Action action)
   at Microsoft.VisualStudio.DesignTools.Designer.View.DesignTimeResourceResolver.Resolve(IDocumentContext documentContext, EditDesignTimeResourceModelMode mode, String missingResourceName) ........etc

If I debug this in Visual studio (attach to the blend.exe process) I get the following error:

Exception thrown: 'System.IO.DirectoryNotFoundException' in mscorlib.dll

Additional information: Could not find a part of the path '<path to my project>\Design\projectGuides.guides'.

This "Design" folder doesn't exist and I don't know where it's getting requested from. I dont have any guides defined across my entire project or anything like that.

Also, I can't see any connection between these two messages.

Any tips or ideas would be greatly appreciated!

Answers


Solution

So the solution to this became clear when I updated to .NET framework 4.6. The Exception became something that returned something useful in a search:

Cannot add additional fields to a type that does not have a constructor

The first result when I searched for this was Corrado's Blog, where I was directed to a setting in Tools > Options > XAML designer, and then tick the "Run project code in XAML Designer (if supported)" option.

No problems since then. Hope this helps someone else at some point.


Funny, my Blend version does not have the option. The rest of the window looks equal, only the mentioned option is missing :/.

But it is possible to click the 2nd option in the excpetion dialog: Click here to enable running project code and reload the designer.

The option can also be deactivated via a small toggle button at the lower left corner of the designer window:

See here for further explanation.


I was facing the similiar problem in BLEND. View in Visual Studio was running fine. I was getting this exception:

Type universe cannot resolve assembly: System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

So Designer in BLEND was showing view for 1-2 sec and then threw the exception.

My solution for this problem was:

I opened up my VS csproj file and found out that somehow another line appeared in references and I didn't know why, because I haven't use Unit Tests yet. Reference as follows:

<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

After commenting it out, designer didn't throw this exception anymore. So I hope it might help someone currently looking for the solution :)


Need Your Help

Force CALayer's rotation direction?

iphone math rotation calayer

This one has been driving me nuts...