无法加载文件或程序集

我正在使用一个系统来使用带有NHibernate的SqlServerCe。 从我的驱动程序,如果我添加System.Data.SqlServerCe程序集作为参考,我可以创建和运行对数据库的查询就好了。 但是,当尝试使用NHibernate时,我得到以下exception: mscorlib.dll中出现“System.IO.FileNotFoundException”类型的第一次机会exception附加信息:无法加载文件或程序集“System.Data.SqlServerCe”或其依赖项之一。 该系统找不到指定的文件。 我已经跟踪了对Assembly.Load(“System.Data.SqlServerCe”)的调用的exception,这看起来应该可行。 System.Data.SqlServerCe程序集在GAC中(我也尝试将它作为本地引用添加到CopyLocal = true,无济于事),我可以使用其成员,所以为什么我不能显式加载它? 当我在Reflector中打开程序集时,它无法加载System.Transactions引用(我也尝试将其添加为本地引用,再次无效),因此加载该程序集可能是问题,而不是系统。 Data.SqlServerCe程序集。 这是个常见的问题吗? 可能是系统配置错误?

因为循环超出范围

using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { MyClass myClass = new MyClass(); myClass.StartTasks(); } } class MyClass { int[] arr; public void StartTasks() { arr = new int[2]; arr[0] = 100; arr[1] = 101; for (int i = 0; i WorkerMethod(arr[i])); // IndexOutOfRangeException: […]

entity framework7中是否存在DbSet .Local等效项?

我需要一个 ObservableCollection 在EF7中, DbSet.Local 似乎不存在; 有没有解决方法?

尝试Catch以外:await Task.Run(()

尝试在外面捕获: await Task.Run(() =>有意义还是只在await中使用它们? private async void Test() { try { await Task.Run(() => { try { DoingSomething(); } catch (Exception ex) { log.Error(ex.Message); } }); } catch (Exception ex) { log.Error(ex.Message); } }

WebClient.UploadData用于发布请求的正确用法

我想我有点疯狂,当我在我的本地网络服务器上测试它时,它在我去实况网站时工作正常,它返回一个空白字符串而不是我期待的数据 我对C#并不熟悉,所以我只是想检查一下我做得对。 数据只是简单的ascii文本 wc = new WebClient(); wc.Headers.Add(“Content-Type”, “application/x-www-form-urlencoded”); response = wc.UploadData(this.urlUpdate, Encoding.ASCII.GetBytes(“data=” + HttpUtility.UrlEncode(buf.ToString()))); s = Encoding.ASCII.GetString(response);

entity framework4.3不创建数据库

我创建了新项目并添加了最新的entity framework(版本4.3)。 我像以前的EF版本一样创建了类和上下文。 但是,在第一次运行时应该创建数据库(在我的情况下是SQL Server 2005),我收到以下错误: 执行命令定义时发生错误。 有关详细信息,请参阅内部exception 具有以下内部exception: 无效的对象名称’dbo .__ MigrationHistory’。 据我了解,此表适用于迁移,但如果没有数据库,则此表不存在。 难道我做错了什么? 更多信息:出于测试目的,我只创建了一个类: public class Test { [Key] public int TestId { get; set;} public string Name {get; set;} } public class Context : DbContext { public Context() : base(“MyConnection”) { } public DbSet Tests { get; set;} } 更新1 经过一些测试后,我意识到应用程序正在从视觉工作室抛出未处理的exception并在视觉工作室中中断。 System.Data.EntityCommandExecutionException是一个例外。 一旦我忽略了这个期望并且没有停止代码执行,就创建了数据库。 […]

使用TcpClient创建http请求

我创建了一个空的asp.net Web应用程序,我有一个简单的aspx页面: protected void Page_Load(object sender, EventArgs e) { Response.Write(“Hello world”); } 当我转到http://localhost:2006/1.aspx我看到一个页面上写着“Hello world”。 好吧,如果我这样做的话#: WebClient webClient = new WebClient() { Proxy = null }; var response2 = webClient.DownloadString(“http://localhost:2006/1.aspx”); 那么response2 ==“Hello world” 我需要使用原始tcp连接实现相同的function 我试图用tcp连接实现同样的事情,由于某种原因它不起作用: byte[] buf = new byte[1024]; string header = “GET http://localhost:2006/1.aspx HTTP/1.1\r\n” + “Host: localhost:2006\r\n” + “Connection: keep-alive\r\n” + “User-Agent: Mozilla/5.0\r\n” + […]

使用c#复制文件夹和所有子文件夹和文件的最佳方法是什么?

我需要将文件夹从一个驱动器复制到可移动硬盘。 需要复制的文件夹中将包含许多子文件夹和文件。 输入将是源路径和目标路径。 喜欢.. 源路径:“C:\ SourceFolder” 目标路径:“E:\” 复制完成后,我可以在我的E:驱动器中看到文件夹“SourceFolder”。 谢谢。

将TLB导入C#

我想将类型库(tlb)导入C#。 如何将.tlb导入.cs代码文件? Borland Delphi可以使用命令行工具tlibimp.exe将.tlb导入tlibimp.exe : C:\Develop>tlibimp.exe SopQuotingEngineActiveX.tlb Borland TLIBIMP Version 5.1 Copyright (c) 1997, 2000 Inprise Corporation Type library loaded… Created C:\Develop\SopQuotingEngineActiveX_TLB.dcr Created C:\Develop\SopQuotingEngineActiveX_TLB.pas 现在有一个包含常量,枚举,接口的.pas源代码文件,它们位于已编译的Type Library(tlb)文件中: SopQuotingEngineActiveX_TLB.pas : unit SopQuotingEngineActiveX_TLB; interface … const CLASS_XSopQuotingEngine: TGUID = ‘{3A46FFB8-8092-4920-AEE4-0A1AAACF81A0}’; … // *********************************************************************// // Interface: IXSopQuotingEngine // Flags: (4416) Dual OleAutomation Dispatchable // GUID: {AA3B73CC-8ED6-4261-AB68-E6AE154D7D52} // *********************************************************************// IXSopQuotingEngine […]

在Xamarin.Forms中绑定自定义视图

我在将Xamarin表单中的自定义视图中的数据绑定到包含页面的视图模型时遇到问题。 我的自定义视图非常简单,一对代表键值对的标签: 后面的代码: public partial class KeyValueView : ContentView { public KeyValueView() { InitializeComponent(); this.VerticalOptions = LayoutOptions.Start; this.BindingContext = this; } public static readonly BindableProperty ValueProperty = BindableProperty.Create(w => w.Value, default(string)); public string Value { get {return (string)GetValue(ValueProperty);} set {SetValue(ValueProperty, value);} } public static readonly BindableProperty KeyProperty = BindableProperty.Create(w => w.Key, default(string)); public string Key […]