Question

I have a WPF .NET 4.0 class library referencing a Silverlight 4 class library.

The SL library compiles fine but when I compile the WPF class library, I get:

Error   2   Unknown build error, 'Cannot resolve dependency to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.'    MyProj.Presentation.Wpf

I figure the problem must be similar to the one mentioned here: http://markti.spaces.live.com/blog/cns!D92CF278F0F91957!273.entry

but my WPF library doesn't contain any XAML that references a user control from my SL library. In fact, my SL library doesn't have any XAML in it at all. It does, however, have several shared DependencyObjects, such as an EventCommander (binding UI element events to Commands), and some DataTemplate helpers.

Is there any way I can narrow down the problem here? And has anyone found a way of effectively referencing UI elements in a SL4 project from .NET 4.0?

Thanks.

Was it helpful?

Solution

this

does anyone know of a way to reference a SL4 assembly with System.Windows references from a full .NET assembly (without just linking the files and creating two different projects to maintain)?

is not possible at the moment. Referencing SL assemblies in .NET projects will only work if the SL project does not reference any assemblies other than mscorlib, System, System.Core, System.ComponentModel.Composition and Microsoft.VisualBasic. Adding a WPF project and linking your SL files into that project is the only way you can reuse your SL code if it uses e.g. System.Windows.

Cheers, Alex

OTHER TIPS

I'm maybe late, but this has not been answered yet.

There is a plugin to VisualStudio 2010, which allows you create assemblies, which can be referenced in .NET, Silverlight, Windows Phone and XNA on xbox. It's called PortableLibrary.

http://blogs.msdn.com/b/bclteam/archive/2011/01/19/announcing-portable-library-tools-ctp-justin-van-patten.aspx

Found it! I had some xmlns namespaces defined in my SL4 class library like:

using System.Windows.Markup;

[assembly: XmlnsDefinition("http://MyProj/Presentation", "MyProj.Presentation")]
[assembly: XmlnsDefinition("http://MyProj/Presentation", "MyProj.Presentation.Controls")]

and that prevented the WPF assembly from referencing it, producing the aforementioned error. Just moved the namespace declarations into the WPF project to fix...

[Edit]

Ok, so this fixed the problem...but does anyone know of a way to reference a SL4 assembly with System.Windows references from a full .NET assembly (without just linking the files and creating two different projects to maintain)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top