我正在使用Visual Studio 2012和.Net Framework 4.5我有2个解决方案:1)WPF应用程序2)类库(dll)
类库包含3个按钮和一个必须位于WindosFormsHost控件内的控件,因为它是为WinForms制作的.
.NET Framework之外唯一引用的程序集用于前面提到的winforms控件和iTextSharp.
winforms控件似乎有点老了,当我把引用放在我的dll中时,我得到了与标题相同的错误但是跟着其他SO问题/答案,我把它放在我的配置文件中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
错误:
混合模式程序集是针对运行时的版本"v2.0.50727"构建的,如果没有其他配置信息,则无法在4.0运行时加载
正如我所提到的,我已经看到了发布这个问题的问题,他们确实在我的DLL项目中解决了这个问题,但是在使用该DLL的项目中我尝试了它们都无济于事.以供参考:
在该项目中,我的配置文件具有完全相同的标签,具有相同的值.
还要注意,在我的WPF应用程序中,一开始我收到一个错误,它无法找到指定的dll(对于winforms控件),最后我将该控件的dll放在GAC中.
我已经尝试更改我的目标框架的所有可能性(4.5,4.0完全和客户端,3.5完整和客户端,3.0和2.0),在调试和发布中构建我的DLL并将"生成序列化程序集"设置为OFF,也,将平台目标从Any CPU更改为x86和x64.我只尝试一次更改一个设置的值.
这是VS2012中的问题,或者我需要做些什么来解决这个问题?
编辑:
上述错误在设计时显示在错误列表中,设计者显示错误"无法创建'my_class'的实例"
该内部异常说:"Set connectionId引发异常",其中的内部异常是标题消息.
这仍然允许构建解决方案,并且在运行应用程序时,我得到的基本相同,除了最里面的异常说:
"无法加载文件或程序集'SigPlusNET,Version = 1.1.3358.14336,Culture = neutral,PublicKeyToken = 6aef07010bb0624f'或其中一个依赖项.尝试加载格式不正确的程序."
那个是winForms控件的程序集,经过dotPeek检查,它唯一的依赖是.NET Framework的
此处的最佳答案:“useLegacyV2RuntimeActivationPolicy”在 .NET 4 配置中有什么作用?以及在 .NET 4.0 项目中引用 .NET 2.0 混合模式程序集需要什么“附加配置”?没有帮助。
我的特定用例是 .Net 4.5 及更高版本的 WinForms 和控制台应用程序VS2015,同时尝试使用.net 2.0 dll
在 VS2015 下,将这个的建议变体添加到项目配置文件没有帮助。
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
编辑:
.net 2.0 库依赖于外部的非 dotnet dll。
在 .net 4.0 客户端模式和 .net 4.0 Full 模式下,它按预期工作。
但是对于 .net 4.5 及更高版本,即使应用程序启动,该库中的功能也会停止工作。
我正在更新这篇文章,我想我现在知道如何获得这个配置; 但是,还有更多要知道,因为我仍然有一个问题是一个关键领域.
我使用SQLite进行单元测试,现在可以正常工作,使用下面的配置步骤.当我想要使用比内存中测试数据更多的数据的UI测试运行但没有SQLServer的开销时,我也使用它 - 此配置失败,具有以下内容:
{"Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."}
Run Code Online (Sandbox Code Playgroud)
这是有关工作的配置的更新信息:
1)哪个SQLite DLL?有一些不好的链接看起来很有帮助,但是它们中存在构建错误.在只有良好的下载,这个日期是这里Source Forge上.v1.066于今天发布,2010年4月18日.
2)您必须使用GAC吗?不,正如毛里西奥回答的那样.
3)x64版本 - 由Mauricio回答.
4)NHib驱动程序 - SQLite20Driver,由Mauricio回答
5)FNH是一种潜在的冲突 - 不,正如Mauricio所回答的那样
干杯,
Berryl
== ADD'L DEBUG INFO ===
当异常被击中并且我调用了SQLite20Drive程序集时,我得到以下内容,这表明驱动程序应该可用.我很想知道,因为配置代码在不同的程序集中.
- 装配时出错----
?typeof(SQLite20Driver).Assembly
{NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
[System.Reflection.RuntimeAssembly]: {NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
CodeBase: "file:///C:/Users/Lord & Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.WpfPresentation/bin/Debug/NHibernate.DLL"
EntryPoint: null
EscapedCodeBase: "file:///C:/Users/Lord%20%26%20Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.WpfPresentation/bin/Debug/NHibernate.DLL"
Evidence: {System.Security.Policy.Evidence}
FullName: "NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"
GlobalAssemblyCache: false
HostContext: 0
ImageRuntimeVersion: "v2.0.50727"
IsDynamic: …Run Code Online (Sandbox Code Playgroud) 我是这样尝试的:
using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
namespace SqlProfiller
{
public partial class Form1 : Form
{
TraceServer reader = new TraceServer();
SqlConnectionInfo connInfo = new SqlConnectionInfo();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
connInfo.ServerName = @".\SQLR2";
connInfo.DatabaseName = "DB";
connInfo.UserName = "sa";
connInfo.Password = "123";
reader.InitializeAsReader(connInfo, @"Standard.tdf");
while (reader.Read())
{
Console.WriteLine("SPID : " + reader["SPID"]);
Console.WriteLine("Login : " + reader["SessionLoginName"]);
Console.WriteLine("Object: " + reader["ObjectName"]);
Console.WriteLine("Text : " + reader["TextData"]);
Console.WriteLine();
textBox1.Text += …Run Code Online (Sandbox Code Playgroud) .net ×2
.net-4.5 ×2
mixed-mode ×2
.net-4.0 ×1
assemblies ×1
c# ×1
dll ×1
events ×1
nhibernate ×1
profiling ×1
sql-server ×1
sqlite ×1
trace ×1