Add reference problem in silverlight: You can't add a reference to dll as it was not built against the silverlight runtime

≡放荡痞女 提交于 2019-12-11 09:25:41

问题


I have a silverlight application which has a class library project in it. th class library is running in .Net framework 4 and the silverlight project is running in silverlight 3. when I want to add a reference in the silverlight proj to the class library I get this message:

"You can't add a reference to Classlibrary1.dll as it was not built against the silverlight runtime. silverlight project will only work with silverlight asseblies."

I've tried to change the framework the classlibrary1 used to .net framework 3.5, 3, and 2 but it does not help. ( and my silverlight application can only run in silverlight 3)


回答1:


Apparently Silverlight project will only work with Silverlight asseblies. CLRs for .NET and Silverlight are different, therefore assemblies are not compatible. These frameworks provide different set of classes, assemblies have different versions, et cetera.

You need to change your Class Library to Silverlight Class Library.
This can either be done by changing project file manually or by creating Silverlight Class Library project and copying the sources in it. If you need the same library for a non-Silverlight project and don't want to maintain two versions, consider using Add as Link feature of Add Existing Item... dialog to only reference the original sources without copying them. But you'll need to make sure you only use functionality available on both platforms for both library versions to build.




回答2:


You have to add a new project to the solution using the "Silverlight Class Library" project template. Then move your files from the .NET Class Library project into the Silverlight Class Library project.

Silverlight applications can't reference .NET assemblies.




回答3:


Rebuild the library as a sliverlight library; this will mean a new csproj, with mostly the same files. You may (not always) find you also need to tweak the code to avoid any operations not available in the slimmer Silverlight BCL.



来源:https://stackoverflow.com/questions/4912306/add-reference-problem-in-silverlight-you-cant-add-a-reference-to-dll-as-it-was

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