Tag Archives: Visual Studio

Cannot deserialize XBF metadata type list as NullableBoolToBoolConverter was not found in namespace

I was trying to get something working last night and kept hitting this exception when my app was trying to InitializeComponent() at one point.

CannotDeserializeXbf

First-chance exception at 0x750D1D4D in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x037CDDC0. HRESULT:0x802B000A The text associated with this error code could not be found.

WinRT information: Windows.UI.Xaml.Markup.XamlParseException: The text associated with this error code could not be found.

Cannot deserialize XBF metadata type list as ‘NullableBoolToBoolConverter’ was not found in namespace ‘WinRTXamlToolkit.Converters’. [Line: 0 Position: 0]

at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)

All this seemed complete and utter bogus, since NullableBoolToBoolConverter was obviously there and it would work perfectly well in other projects or solution configurations, so let’s look what was happening.

  • NullableBoolToBoolConverter is defined in WinRTXamlToolkit – a .NET Class Library that I’d typically build as Any CPU. It has a ton of controls, converters and other such goodies and of course it typically works just fine.
  • NullableBoolToBoolConverter is used in WinRTXamlToolkit.Debugging – another .NET Class Library that has an in-app XAML visual tree debugger tool – essentially a TreeView control that displays information about the visual tree of your application – hierarchy of UI elements and their properties. The main control in the library uses NullableBoolToBoolConverter and it normally works when used from a .NET Windows Store app.
  • The problem is that WinRTXamlToolkit.Debugging is a .NET Class Library and there is still a small, but important range of WinRT XAML apps written in C++ that can’t use it, so I created a managed WinRT component library – WinRTXamlToolkit.Debugging.WinRTProxy that C++/CX projects can reference. It’s fairly straightforward to do it seems – you just create a proxy class in the WinRT Component library that has methods that invoke methods in the referenced class library (WinRTXamlToolkit.Debugging) and now you can use it from C++/CX. I prefer to keep WinRTXamlToolkit.Debugging a regular .NET class library because WinRT Components have limitations that would limit the APIs I currently have in WinRTXamlToolkit.Debugging. The proxy methods in the WinRTProxy library still have these limitations, but at least I can use it from a native app. The problem is that it wouldn’t work and keep giving me that exception, so what’s up?

It turns out WinRT XAML generates these files – XamlTypeInfo.g.cs that allow the XAML parser to see the types it can use and I noticed that file was missing in the obj folder of WinRTXamlToolkit.Debugging.WinRTProxy. To get it to generate I simply added one empty UserControl to WinRTXamlToolkit.Debugging.WinRTProxy and everything started working fine! Weird but it works. So now I’m left with figuring out how to wrap this all as a NuGet component with native versions of the .NET libraries, since I’ve previously only packaged Any CPU binaries…

Tagged , , , , , ,

How to safely use your time while you build a project?

So your build takes a while… How do you make use of that time (e.g. check Stack Overflow) and not forget to get back to work when the build is done? Well, you can make a sound. I am not sure if there is a simple built-in option to Visual Studio allows to play sounds on events. It is quite possible there is, but I will use what I know. I found you can play a sounds in command line by typing echo ^G, but it didn’t seem to work for me in a VS project post-build step. I blogged about using batch scripts and C# code together in a single file and here’s a way to beep from a batch script:

Continue reading

Tagged , ,

Visual Studio 2012 – ALL CAPS vs. Old Style

Richard Banks – a Visual Studio ALM MVP posted about a registry hack to disable ALL CAPS in Visual Studio 2012, which gives an opportunity to compare Visual Studio 2012 with and without the highly controversial SHOUTING MENU.

See image below for comparison:

Continue reading

Tagged

Windows 8 Love

So I installed Windows 8 Release Preview today. I had a bit of a trouble since I first tried the unsupported method that ported my user profile from the previous version which was something between CP and RP. After backing up my files and doing a clean install – things started whirring and it works great now. It works so great in fact that I now love Windows 8. It has been an interesting experience with Developer Preview and Consumer Preview before, but mostly from the novelty of developing for a new platform that is somewhat familiar to a WPF/Silverlight developer. The only metro apps that I used were the ones I worked on myself and otherwise – I had staid in the desktop world, which is still good – with numerous improvements from Windows 7. With RP and the updated set of apps – things changed. I love the new apps. They finally have features that I can find useful and they look brilliant in the chromeless Metro style on my laptop.

Continue reading

Tagged , , ,

Using Visual Studio Macros and Block Selection/Edit with ReSharper

I love using Macros in Visual Studio. If you need to process multiple lines quickly – like modifying a list of words into a list of C# properties with backing fields etc. – you kind of can do these things with regular expressions search/replace, but it is a bit difficult to come up with multiline match and replace expressions while escaping lots of special characters, marking groups etc. Macros work great because you just record a macro in which you process one line by manually typing the changes, make sure to go to the next line and then replaying the macro multiple times gets all the lines processed the same way and it just looks magical when it works. Just as useful in more simple cases is block selection (Alt+Drag) – when you just need to modify a column of one-line statements – eg. when you have a column of words and you want to modify each line to add each of these words to a collection.
Well, I also love ReSharper for making my code better and teaching me to code better every day, but it just does not work with macros or block select edit. One thing is – it somehow breaks the Ctrl+Shift+R/Ctrl+Shift+P shortcuts to record/play a temporary macro – and it breaks it beyond fix, but it is OK, since you can start/stop recording using the menus/toolbar. What is worse though – it interrupts your recording by doing some automated coding assistance. The same way – it often interrupts editing multiple lines of text when using block selection. A fix is to disable ReSharper, but going to Tools/Options/ReSharper/General/Suspend-Resume every time you want to record or play a macro is really annoying. It turns out there is a command you can execute to switch it, but it does not show up when you customize your toolbars (it was reported as an issue in ReSharper 5.1, but is still not fixed in 6.0 – I guess it was low priority or just overlooked). Well, you can go to you Macros IDE (Alt+F11) and add the below macro, which you can then add to a toolbar (toolbar-Right Click/Customize/Commands/Toolbar/Add Command/Macros/Macros.MyMacros.Shortcuts.Resharper_ToggleSuspended):

Public Module Shortcuts
    Sub Resharper_ToggleSuspended()
        DTE.ExecuteCommand(“Resharper_ToggleSuspended”)
    End Sub
End Module

Now this is enough for me for now, but an ideal solution would be to have a method that first disables ReSharper and then starts recording a macro, so you could have that happen automatically when you start recording a macro…
The next step is to go to Tools/Options/Keyboard, search for Tools.RecordTemporaryMacro and assign some key to it – e.g. Ctrl+Shift+Alt+R. Ctrl+Shift+P should still hopefully work to play back the macro.
Tagged , , , ,

Beginning WinRT development

I finally found some time to take a look at Windows 8 development + a shiny Build edition Samsung Series 7 Slate device, so it is time to start taking apart this WinRT development thing.
I am starting by setting up my development and blogging environment. I installed Live Essentials to use my usual Live Writer, which took a while since it first had to enable .NET 3.5… Well, it is good to know 3.5 is alive and kicking! 🙂

Now I still haven’t figured out the best way to paste code in Live Writer – VS Paste plugins output weird frames, while copying through Word looks nice, but it breaks quotes and some other characters, besides – I don’t have Office on this unit, which also means – I can’t use OneNote to do screen clippings. Well – I’ll figure something out I guess.

Creating a simple Windows 8 app

When you start Visual Studio 11 Express and start a new project you get to choose a couple of things:

image

First – the language – JS/VB/C#/C++. I chose C#. This is what I know best and while I believe it is worth learning something new – I still believe C# and .NET is in many ways better than JS+HTML5+CSS and what these are best is in attracting developers who already know these best.

Then – picking a project template – I just selected Application, since I want to focus on the basics first before I look at the cooler controls, whatever the temptation says.

I end up with the following minus the yellow rectangle that I added to see some content in the window and the one attribute per line formatting that I prefer:

<UserControl
    x:Class="Application1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="768"
    d:DesignWidth="1366">
    <Grid 
        x:Name="LayoutRoot" 
        Background="#FF0C0C0C">
        <Rectangle
            Fill="Yellow"
            Width="200"
            Height="200" />
    </Grid>
</UserControl>

When I hit F5 – I get the below image displayed on full-screen:

image

Great! A simple application is indeed very similar to Silverlight or WPF. I wonder why the default background is almost black… It looks pretty cool when I change my rectangle background to black – almost a screen test: Smile

image

I mentioned one attribute per line – this is my preference and recommendation in XAML development as it reduces the need for horizontal scrolling and makes reviewing and merging changes easier. It turns out it works just as well in VS11Express as it does in VS10 for Silverlight and WPF – just go to Tools/Options/Text Editor/XAML/Formatting/Spacing (yeah, just) – and click to “Position each attribute on a separate line” and uncheck “Position attribute on same line as start tag”:

image

Now while at it – also save yourself some time and go to XAML/Miscellaneous and check “Always open documents in full XAML view” – this gives you more space to code your XAML and prevents delays when VS loads the XAML designer.

image

It seems like the root control in XAML of a default screen type in WinRT is a UserControl – just like in Silverlight – another point for compatibility with Silverlight and against WPF where you usually deal with Window objects.

What is a UserControl? According to MSDN – it has same inheritance hierarchy as the one in Silverlight, though it throws in a bunch of interfaces – a side effect of WinRT’s close ties to C++ and cross-language support I guess:

image

Tagged , , , , ,