views:

367

answers:

2

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.

A: 

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)?

JeffN825
Is this an answer or question?
AnthonyWJones
Both, sorry. It's my answer as to how I fixed the immediate problem but the question is still open...specifically I'd still like to figure out a way of doing assembly sharing without having the problem mentioned. Would you suggest putting this into my original question or leaving it as an answer? Thanks.
JeffN825
+1  A: 

Hi there,

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

alexander.biskop
Thanks. One more question: if I can get it to compile, and I know that I'm not using any surface are that is incompatible, is there a way I can trick the runtime to use an assembly? Right now I'm trying to share an assembly that uses System.Xml.Linq, but I get Could not load file or assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. I tried binding to the AppDomain AssemblyResolve event and manually loading the full .NET System.Xml.Linq assembly there, but then I get a manifest definition mismatch exception instead.
JeffN825