简体   繁体   English

在ASP.NET和Silverlight之间共享程序集

[英]Sharing an assembly between ASP.NET and Silverlight

I've created an assembly to share it between my main app and the silverlight app. 我创建了一个程序集,以在我的主应用程序和silverlight应用程序之间共享它。 At the beginning it looked like it was going to work but now I get this exception: "System.IO.FileNotFoundException was caught, Message="Could not load file or assembly 'System.Xml.Linq". I'm using .NET 3.5 Sp1 and Silverlight 3. 一开始它看起来像是可以正常工作,但是现在我得到了这个异常:“ System.IO.FileNotFoundException被捕获,Message =“无法加载文件或程序集'System.Xml.Linq”。我正在使用.NET 3.5 Sp1和Silverlight 3。

That shared assembly uses System.Xml.Linq, and it cannot find it... I think because it is trying to find that version in the .NET framework instead looking in the silverlight one. 该共享程序集使用System.Xml.Linq,但找不到它...我认为是因为它正试图在.NET框架中找到该版本,而不是在Silverlight中寻找该版本。 How can I fix this? 我怎样才能解决这个问题?

Cheers. 干杯。

PS: this is the full exception output: PS:这是完整的异常输出:


System.IO.FileNotFoundException was caught Message="Could not load file or assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified." 捕获了System.IO.FileNotFoundException Message =“无法加载文件或程序集'System.Xml.Linq,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。系统找不到指定的文件“。 Source="MyApp.Metadata" FileName="System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" FusionLog="=== Pre-bind state information ===\\r\\nLOG: User = IIS APPPOOL\\DefaultAppPool\\r\\nLOG: DisplayName = System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\\n (Fully-specified)\\r\\nLOG: Appbase = file:///C:/Users/vtortola.MyApp/Documents/MyApp/MyAppSAS/WebApplication1/WebApplication1/\\r\\nLOG: Initial PrivatePath = C:\\Users\\vtortola.MyApp\\Documents\\MyApp\\MyAppSAS\\WebApplication1\\WebApplication1\\bin\\r\\nCalling assembly : MyApp.Metadata, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.\\r\\n===\\r\\nLOG: This bind starts in default load context.\\r\\nLOG: Using application configuration file: C:\\Users\\vtortola.MyApp\\Documents\\MyApp\\MyAppSAS\\WebApplication1\\WebApplication1\\web.config\\r\\nLOG: Using host configuration file: C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\Aspnet.config\\r\\nLOG: Using machine configuration file from C:\\Windows\\ Source =“ MyApp.Metadata” FileName =“ System.Xml.Linq,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35” FusionLog =“ ===预绑定状态信息=== \\ r \\ nLOG:用户= IIS APPPOOL \\ DefaultAppPool \\ r \\ nLOG:DisplayName = System.Xml.Linq,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35 \\ n(完全指定)\\ r \\ nLOG:Appbase = file:/// C:/Users/vtortola.MyApp/Documents/MyApp/MyAppSAS/WebApplication1/WebApplication1/ \\ r \\ nLOG:初始PrivatePath = C:\\ Users \\ vtortola.MyApp \\ Documents \\ MyApp \\ MyAppSAS \\​​ WebApplication1 \\ WebApplication1 \\ bin \\ r \\ n调用程序集:MyApp.Metadata,版本= 1.0.0.0,文化=中性,PublicKeyToken =空。\\ r \\ n ==== \\ r \\ nLOG:此绑定在默认的加载上下文中启动。\\ r \\ nLOG:使用应用程序配置文件:C:\\ Users \\ vtortola.MyApp \\ Documents \\ MyApp \\ MyAppSAS \\​​ WebApplication1 \\ WebApplication1 \\ web.config \\ r \\ nLOG:使用主机配置文件:C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v2.0.50727 \\ Aspnet。 config \\ r \\ nLOG:使用C:\\ Windows \\中的计算机配置文件 Microsoft.NET\\Framework64\\v2.0.50727\\config\\machine.config.\\r\\nLOG: Post-policy reference: System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\\r\\nLOG: The same bind was seen before, and was failed with hr = 0x80070002.\\r\\n" StackTrace: at MyApp.Metadata.MyAppEntity.Deserialize(String message) Microsoft.NET \\ Framework64 \\ v2.0.50727 \\ config \\ machine.config。\\ r \\ nLOG:策略后参考:System.Xml.Linq,版本= 2.0.5.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35 \\ r \\ nLOG:以前看到过相同的绑定,但由于hr = 0x80070002而失败。\\ r \\ n“ StackTrace:位于MyApp.Metadata.MyAppEntity.Deserialize(字符串消息)

You must maintain two separate projects - one for desktop and for Silverlight. 您必须维护两个单独的项目-一个用于桌面和Silverlight。 Have a look here for more information: 在这里查看更多信息:

How can I use non-Silverlight assemblies in a Silverlight app? 如何在Silverlight应用程序中使用非Silverlight程序集?

You can share most of the code between projects (as in link files from one to another). 您可以在项目之间共享大多数代码(例如在一个到另一个的链接文件中)。 Here is the Microsoft page that describes how to do exactly this: 这是Microsoft页面,描述了如何执行此操作:

http://msdn.microsoft.com/en-us/library/ff648215.aspx http://msdn.microsoft.com/en-us/library/ff648215.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM