Cannot resolve Assembly or Windows Metadata file 'System.Data.dll'

那年仲夏 提交于 2019-12-23 09:59:49

问题


I just created a new windows 8 app in c#/XML and download mongodb c# driver and add its reference in my project and follows the rest of tutorial , but when i try to run my app now its saying

Cannot resolve Assembly or Windows Metadata file 'System.Data.dll'

Type universe cannot resolve assembly: System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

Please help me thanks in advance .


回答1:


Looks like system.data is unavailable to metro apps. The general consensus seems to be that you'll have to create a middle "go-between" tier (using a technology such as WCF) to allow your metro app to communication with the database.

References:

  • Retrieving data from SQL using C# Metro App
  • Make System.Data available to Metro style apps
  • WinRT System.Data - Connect to SQL

Although these links have SQL in the title, they really address connecting metro apps directly to any database.

Here's a bit from an answer at one of the above links:

You are correct, System.Data is not there (I looked for the same thing when I first started messing around with WinRT). You won't be able to reference it either. If you want to talk to a SQL database you're going to need to use some kind of other protocol (WebService, SOAP, WCF, etc.).


Followup question in comment:

I am trying to connect with mongodb , not sql . Is it necessary to have system.data for this purpose ?

When I tried this, I could reference MongoDB.Bson.dll by itself and the project builds, but once I referenced MongoDB.Driver.dll I got the same message as you.

It would appear the sql driver and the mongodb driver both require System.Data.dll, which you could reference directly in a standard winforms/wpf app (but probably shouldn't), but which you cannot reference directly in a metro app.

I'd say it's necessary to have access to System.Data if you want to use MongoDB. So you'll have to create a separate project that references the MongoDB driver and actually performs the connections to the database, and make that project accessible to your metro app via WCF calls or a web service. You just need something sitting between your metro app and the database, because you cannot connect directly to it.

I know it seems to make things more complicated, especially if you're just trying to play around, but it's apparently a design decision Microsoft made regarding their metro apps.




回答2:


Take a look at these posts, it mentions that the DLL is not yet available: Using NHibernate in a Metro & http://social.msdn.microsoft.com/Forums/en-US/DataMarket/thread/385475ce-edf9-416f-b0f7-1369760aa73b/



来源:https://stackoverflow.com/questions/15589820/cannot-resolve-assembly-or-windows-metadata-file-system-data-dll

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