views:

23

answers:

0

I have a WPF project where I load a WindowsForsm assembly (dll file) dynamically like this:

        Assembly currentAssembly = Assembly.LoadFile(System.IO.Directory.GetCurrentDirectory() + @"\" + fileName);            
        System.Windows.Forms.Control currentControl = (System.Windows.Forms.Control)currentAssembly.CreateInstance(featureName, false);

        featureHost.Child = currentControl;

My XAML code for the for the featureHost looks like this:

<WindowsFormsHost Name="featureHost" Grid.Row="1" Margin="14,4,14,14" Background="WhiteSmoke"></WindowsFormsHost>

The problem that I have is that in the C# code the currentControl will be null, but currentAssembly seasm to be loaded correctly. But if I add project reference to a project that is a Windows Forms project the currentControl getts the correct value. Of coures I don't want to have a reference to a WindowsForms project that I don't need. Dose anyone have any suggestions on why it works like this and how I can fix it? I'm using .Net 4.0.