天道酬勤,学无止境

c#

Property already registered by 'ListView'

I have this code: using System.Collections; using System.Windows; using System.Windows.Controls; public static class SelectedItems { private static readonly DependencyProperty SelectedItemsBehaviorProperty = DependencyProperty.RegisterAttached( "SelectedItemsBehavior", typeof(SelectedItemsBehavior), typeof(ListView), null); public static readonly DependencyProperty ItemsProperty = DependencyProperty.RegisterAttached( "Items", typeof(IList), typeof(SelectedItems), new PropertyMetadata(null, ItemsPropertyChanged)); public static void SetItems(ListView listView, IList list) { listView.SetValue

2021-06-15 18:15:56    分类:问答    c#   wpf   mvvm   visual-studio-2012

Why is implicit conversion allowed from superclass to subclass?

Can someone tell me why the line with "//Compiles" compiles, and why the line with "//Doesn't Compile" does not? I don't understand why A would be implicitly convertible to B, not the other way round. public class SomeClass { static public void Test() { AClass a = new AClass(); BClass b = new BClass(); a = b; // Compiles b = a; // Doesn't compile } } public class AClass { public void AMethod() { Console.WriteLine("AMethod"); } } public class BClass : AClass { public void BMethod() { Console.WriteLine("BMethod"); } } thanks!

2021-06-15 18:15:46    分类:问答    c#   .net   inheritance   type-conversion   implicit-conversion

String matching problem in Entity framework. Works for a string literal but not for a string variable

I am trying to get a row from a table using the entity framework in C#. I have a table called "TipoPlanta" with a primary key called "Tipo" which is of type String. When I try to get a row from the table usng a String I can only find something if I use a string literal. If I use the string passed to the method I find no rows. I have the following method which has a bit of added stuff that I have been trying to debug. I pass the String tipoString which in this example has a value of "Arbol persistente". Here's the code: private TipoPlanta getTipoPlanta(String tipoString) { try { if (tipoString

2021-06-15 18:13:41    分类:问答    c#   linq   entity-framework

DirectoryEntry.Invoke(“groups”,null) not retrieving all groups?

I created a WCF web service to return user and group information from Active Directory. It works for most groups and users. I use directoryEntry.Invoke("groups",null) to return the groups a specified user is member of. This returns MOST groups. The odd thing is I can find any group and enumerate its members, even if it is one of the groups missing when I use the invoke query on one of its members. Most of the groups that exhibit this behavior are Exchange-enabled. Most of the problematic user accounts are for users in a federated domain, who use an Exchange server in the domain that I query. I

2021-06-15 18:13:17    分类:问答    c#   windows   active-directory   active-directory-group

Try-Catch and “Continue” - is this possible?

I have a section in my code where I am querying all SQL Server Databases on my network. I am first trying to use a SQL Login to access the SQL Server Instance but if that fails then I want to try connecting using my Windows Credentials. After that if I still can't connect then I want the code to fail and then notify the user. So I guess what I am asking is how can I loop back from inside of a Try-Catch block to the line just above the Try-Catch block: String conxString = @"Data Source=SQLInstance1;User ID=FOO;Password=BAR;"; bool secondTime = false; using (SqlConnection sqlConx = new

2021-06-15 18:12:05    分类:问答    c#   .net   try-catch

How to update textboxes in main thread from another thread?

How you update textboxes and labels in the main thread from a new thread running a different class. MainForm.cs (Main thread) public partial class MainForm : Form { public MainForm() { Test t = new Test(); Thread testThread = new Thread(new ThreadStart(t.HelloWorld)); testThread.IsBackground = true; testThread.Start(); } private void UpdateTextBox(string text) { textBox1.AppendText(text + "\r\n"); } } public class Test { public void HelloWorld() { MainForm.UpdateTextBox("Hello World"); // How do I execute this on the main thread ??? } } I have looked at the examples on here but cant seem to

2021-06-15 18:11:55    分类:问答    c#   multithreading   user-interface

How to resolve a 'Bad packet length' error in SSH.NET?

I'm trying to upload files via SFTP, using SSH.NET. SFTPClient.Connect() throws an SshConnectionException with the message, "Bad packet length 1302334341." This is my code: static void Main() { try { SftpClient sftp = new SftpClient(server, 22, userID, password); sftp.Connect(); } catch(Exception e) { Console.WriteLine(e.Message); } } I saw in another discussion that this probably has to do with encryption. I'm using AES, and I have a host key. I don't understand how to enter the encryption, though. Based on that discussion, I was playing with this: ConnectionInfo connectionInfo = new

2021-06-15 18:10:14    分类:问答    c#   .net   ssh   sftp

SQL CONNECTION best Practices

Currently there is discussion as to what are the pros and cons of having a single sql connection architecture. To elaborate what we are discussing is, at application creation open a sql connection and at application close or error closing the sql connection. And not creating another connection at all, but using just that one to talk with the DB. We are wondering what the community thinks.

2021-06-15 18:09:57    分类:问答    c#   sql

NHibernate + SqlServer full text search

I have to do Full text search in NHibernate For following operation previously I am using Lucene.Net I have a table called candidate For full text query Lucene will return all candidate Id from lucene index and form that id I put in query in candidate and return the result But the problem is there is more than 10 Lack of candidate resume available so Lucene is very slow because filter value from 10 Lk row and put return value for in query against candidate and again filter candidate is taking too much time Also i have a paging criteria and for each page i return 100 candidates now i added new

2021-06-15 18:09:36    分类:问答    c#   sql-server   nhibernate   full-text-search   lucene.net

Can I emulate MS Compute Cluster Server on my dev machine?

I have a project for a client that will consist of managing jobs on a MS Compute Cluster. I will be developing the application outside of their network, and would like a way to develop/debug my app without the need to be on their network. I am developing the app in C#, and all I have so far is the Microsoft Compute Cluster Pack SDK.

2021-06-15 18:07:37    分类:问答    c#   .net   cluster-computing   hpc