This post provides information on a few high profile Visual Studio 2010 Release Candidate bugs and some additional information that will help developers have a successful experience with the WPF & Silverlight Designer.
Problem: Users have reported frequent crashes of Visual Studio 2010 Release Candidate when IntelliSense displays. This can happen in the XAML Editor or Code Editor.
Solution: If you are experiencing crashes please install this Hot Fix: http://code.msdn.microsoft.com/KB980610
Problem: Some customers have reported that the Find if Files feature of Visual Studio can by very slow if a XAML Editor document is open and the search is conducted shortly after opening the solution.
Solution: If this bug affects your work, close all Visual Studio documents and then close Visual Studio. Reopen Visual Studio and the solution you were working on. Before opening any documents, perform the Find in Files search.
This bug will be corrected for the final release of Visual Studio 2010.
Problem: If you have an implicit Style that uses BaseOn that is located in App.xaml or in a Merged Resource Dictionary that is merged in App.xaml, the WPF & Silverlight Designer will always be in a read-only error state.
Gold Bar Error: InstanceBuilderException was thrown due to a document error: a loop was detected in the property expressions
Error List Error: A loop was detected in the property expressions
Solutions
Dictionary1.xaml content – note BaseOn Style
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}"> <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="Background" Value="Green" /> <Setter Property="Foreground" Value="Yellow" /> </Style> </ResourceDictionary>
MainWindow.xaml – note Dictionary1.xaml was merged here, rather than App.xaml.
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:WpfApplication1"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Dictionary1.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <TextBlock Text="Hello" /> </Grid> </Window>
Silverlight 3 projects are supported with the Visual Studio 2010 Release Candidate build – however Silverlight 4 projects are not yet supported.
We will be adding Visual Studio 2010 Release Candidate support for Silverlight 4 with the next public Silverlight 4 drop.
If you are doing active Silverlight 4 development today we recommend staying with the Visual Studio 2010 Beta 2 build for now.
Tim Heuer has also blogged about this limitation here.
Expression Blend does not support for .NET 4.0 projects.
Visual Studio 2010 Release Candidate customers can use Blend to target .NET 3.5 and SL3, but not .NET 4.0.
Developers writing their own MarkupExtensions should locate them in a separate assembly from the assembly that is consuming them for the best design support. If located in the same assembly the following error may be displayed:
Error Message: No constructor for type '[ClassName]' has 0 parameters
Usually, Silverlight image files have their Build Action set to Resource. The Silverlight run-time supports setting the Build Action to Content. However the Designer will display the following gold bar error:
Error Message: Project does not support paths relative to the root application directory.
At design-time, the Designer executes code in Converters and DataTemplateSelectors. If those classes allow an unhandled exception to bubble up to the Designer, an exception will be displayed in the Designer.
Developers must ensure they code defensively to avoid this design-time problem.
>> No Expression Blend Support for .NET 4.0 Projects
There is support with Expression Blend Preview for .NET 4:
http://timheuer.com/blog/archive/2009/11/22/fix-open-in-expression-blend-missing-link-in-visual-studio.aspx
Download: http://www.microsoft.com/downloads/details.aspx?FamilyID=6806e466-dd25-482b-a9b3-3f93d2599699&displaylang=en
@Ed, the Blend Preview for .NET 4 crashes when trying to open projects, so at the moment "no Blend support" is quite correct for the RC.
(sent too soon)
Obvious if you want to continue using the Blend preview with Beta2 just don't install the RC. :)
This bug is really nasty I have a gazillion of my custom local markup extensions, I raelly don't want to move them to a different assembly!
Shimmy,
We do appologize for the inconvenience of moving the Custom MarkUpExtensions to another assembly
This requirement will be reviewed in a future version of Visual Stuio.
Have a nice day,
Karl Shifflett
Visual Studio Product Team
Be sure that I am not going to move all my markup exts to an external assembly just because the IDE has quirks.
Lucky me that the designer anyhow works.
BTW, there is also a problem with converters, for example, I have a converter that converts Int values to String, the designer send in an incompatibe parameter variable (I think it was the unbeloved MS.Internal.UnsetValue something like this), and the converter throws exception.
Now, of course you'll say "So convert it to string", the answer is I am a lazy VB programmer, and this converter uses the CInt function so it accepts strings, ints and bigints etc (the actual result of the converter is the enum string of int value).
Now I had to wrap it in a try, and return empty str when CInt tries to convert the goddamned UnsetValue instance, and I hate to write code that doesn't serve my own needs.
Anyway Karl, I love reading your blogs and your articles and I am having fun using the Mole of yours!
It is a big honor for me to have a response from Karl Shifflett!
Thanks!
Hi Shimmy,
Sorry you are having another problem.
With converters here is what I normally do:
Check if the value parameter is null. If so, return value.
Check if the value is of the expected type. If not, return value.
Then cast value to the correct type and perform your logic.
This removes the need for try/catch blocks.
If you are working with enums it's much easier to use the Shared methods on the Enum type.
Check out:
Enum.GetName
Enum.Parse
Enum.IsDefined
Glad you like the blog.
Have a super day,
Oh g zuz!
hell thawas a quick response
I know of the above and I do use the GetName func in my converter, but since the expected type is either string, int or more, so wrapping the CInt function in a try works best for me, and since an exception is only expected at runtime I don't mind so much (I made myself a not to remove it on release, I will maybe wrap the whole try in a #If DEBUG -try- #Else -no try-
Whatever.
A good idea would be implementing (maybe it's already implemented and I am not aware of?) System.ComponentModel.DesignerProperties.IsIndesignMode, not related to any element but to the running thread etc.
Note, that even though I use 2010, I still use 3.5.
Thanks a gazillion.
Please post you converter code for me. Let me see what you are doing. You should not have to do any magic for converters work.
BTW: You can use this hack if you need it, "DesignerProperties.IsIndesignMode(New DependencyObject())"
This enables your classes to get access to this information.
Cheers,
OMG, almost a chat...
I haven't your line but it loox like a very good idea.
I think I will include such a function in my public module (yeah that's what I like in VB, calling just a function, I told you I am a lazy VBer..).
My converter consist of multiple enum types and is a bit complicated, I don't find a reason to post it.
It works just fine, as I said, I don't mind to wrap in a try, cuz no exceptions are expected.
I will anyway want to convert the 'value' param thru CInt.
Also, I anyway use try for another cast (to control the ret type, call it managed TryCast), so I will post my code, I am sure you can enrich my knowledge with tips, and I always love to learn, especially when it's from people like you.
So here it is:
If value Is Nothing OrElse parameter Is Nothing Then Return Nothing
Try
Dim type = DirectCast(parameter, Type) 'throw if not type and return nothing
If Not type.IsEnum Then Return Nothing 'if is not enum don't continue to next line
value = CInt(value) 'make sure the value is anyhow compatible with integer.
Catch
Return Nothing
End Try
BTW, FYI, I was wrong before, the converter returns image based on the enum type and the value.
Try this out, it works in the designer and at runtime.
You really never want to throw from the Convert method.
Public Class DemoConverter
Implements IValueConverter
Public Enum Demo
None
Happy
VeryHappy
End Enum
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
If value Is Nothing OrElse parameter Is Nothing OrElse Not TypeOf value Is Integer Then Return Nothing
If TypeOf parameter Is Type Then
Dim type = DirectCast(parameter, Type)
If Not type.IsEnum Then Return Nothing
Dim enumValue As Demo
If [Enum].TryParse(value.ToString(), enumValue) Then
'enumValue has a value you can use
Else
'bummer, out of range value passed
End If
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
End Class
Karl
OK whatever.
When using the CInt, the ToString is not necessary lol.
Thanks a lot.
And since I have a huge library of enum types, I prefer to make the validation at the beginning rather then TryParse of each enum, plus the ByRef is not what I am looking for.
Anyway thanks for your suggestions.