5

我正在 C# Visual Studio 2012 RC 中构建一个应用程序。

我必须在应用程序中运行脚本。为此我正在使用。这两个库。我的应用程序的目标 .net 框架是 4.5。

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

在检查天气数据库是否存在后,我编写了运行脚本的代码。

当我运行代码时,会弹出一个意外的异常。我真的知道这是什么意思。你能帮我摆脱这个例外吗?

我还附上了我的代码和异常预览。

请帮助我...我已经用谷歌搜索了太多。

在此处输入图像描述

**Here are the Exception Details.**

System.IO.FileLoadException 未处理 HResult=-2146232799 消息=混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有其他配置信息,则无法在 4.0 运行时中加载。Source=mscorlib StackTrace:在 System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) 在 System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly 程序集,字符串名称,布尔 throwOnError,布尔忽略Case,ObjectHandleOnStack 类型)。 Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query, ExecutionTypes executionType, Int32& statementsToReverse) 在 Microsoft.SqlServer.Management.Common.ServerConnection 的 Reflection.Assembly.GetType(String name, Boolean throwOnError)。

4

1 回答 1

5

看起来您正在尝试加载 Microsoft.SqlServer.xxxx.dll 的 .net 2 版本。更新您对 .net4 版本的引用(首选),或将以下咒语添加到<configuration>节点下的 app.config

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  <requiredRuntime version="v4.0" />
</startup>

允许加载 .net 2 程序集。详情请看这里

于 2012-07-01T22:29:47.870 回答