Silverlight 4 Assembly Sharing Problem

南笙酒味 提交于 2019-12-06 05:48:56

问题


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.


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/2982106/silverlight-4-assembly-sharing-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!