Tuesday, January 23, 2007

XAML and Error MC3074

I'm lucky. Really lucky. I have frequently had the fortune to get paid to play with new technologies. Right now I'm starting a project where I get to use WCF and WPF (curses on the Microsoft drone who dropped the far cooler names of "Indigo" and "Avalon"). It's fun.

 

Of course, life on the bleeding edge is not without challenges. For starters, there's the fact that I don't know what the hell I'm doing yet. That's usually the case anyway, but what's different now is that Google can't always save me. Usually I just type in some well-chosen search terms and lo and behold someone else has made the same mistake. Only it looks like I get to go first this time.

 

At any rate, I'm working on a project that makes use of the <WindowsFormsHost> control tag in XAML. This very cool tag, shown to me by Chris Sells, allows an Avalon form to host a Windows Forms control. In my case, it's the WebBrowser control, as Avalon (I'm going to keep calling it Avalon until no one can understand what I'm talking about) has no browser control in-built. However, when I went from the sample project that Chris sent me to my project, I kept getting build failures:

 

Error MC3074: Unrecognized tag 'WindowsFormsHost' in namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

 

After about half an hour of digging, I figured out that the problem is a missing reference. In my case, I was missing a reference to WindowsFormsIntegration, an assembly that can be found on my computer in C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0. Once I added it, all was well again.

 

Given what little I've been able to dig up on Google, I'm guessing this is going to be a common problem, so hopefully this post will help someone else at some point. Just be aware that it might not be WindowsFormsIntegration that you need to reference - I believe this error to be a general symptom of some missing reference, and not that assembly in particular. You'll have to do some detective work to figure out which one you need.

5 comments:

  1. A very cool tag indeed, but not needed for web browsing as Avalon seems quite able to do this all by itself.



    Look at Petzold's Navigate the Web example on page 82 of Applications = Code + Markup.



    All he does is set the Contents of a Window to a Frame, and then set the Source of the Frame to a Uri.



    Wouldn't this do what you need?

    ReplyDelete
  2. Sure enough, that works great. Unfortunately, I'm unable to figure out how to make it accept HTML from a string without writing it to the filesystem first (ick). But with the WebForms approach, there are at least three ways to do that, so that's where I'm staying for now.

    ReplyDelete
  3. I cant add reference even! Im using Windows XP SP2 with .net 3.5 and visual C# express edition. It shows WindowsFormsIntegration assembly not found when I add it to xmlns syntax.

    ReplyDelete
  4. Happened with me too. And thanks for the pointer Craig. I could not drill down to the exact issue but fortunately had another machine where the source was building.

    Just copied the folder contents in v3.0 and v3.5 folders from working system and it worked!

    Thanks Again

    ReplyDelete
  5. I had this problem with different namespace. I was looking at my project properties and noticed the framework was .net 4 CLIENT profile. Changing it to the full profile fixed the error. Nice and obscure.

    ReplyDelete