Tag: c#

Visual Studio颜色属性编辑器中的自定义调色板

在Visual Studio Designer中,在属性窗口下,您可以使用颜色选择器选择ForeColor , BackColor等。 当您想要选择颜色时,颜色选择器会出现“自定义,Web,系统”选项卡。 如果选择自定义,则可以向选择器添加新颜色,但只有底部2行可以更改,并且更改不会在控件之间保留。 因此,如果您向调色板添加颜色,当您选择另一个控件并想要更改例如BackColor您之前添加的颜色不存在。 有没有办法在设计师的颜色选择器控件中创建和导入一组自定义颜色? 注意:这个问题不是询问VS主题,或者是否可以在代码隐藏中将颜色实现为类。 我正在寻找一种定制设计师的方法。

C#connectionString加密问题

我正在学习如何为我们的C#(3.5)应用程序加密ConnectionString。 我阅读了关于保护连接字符串的.Net Framwork开发人员指南( http://msdn.microsoft.com/en-us/library/89211k9b(VS.80).aspx )。 但没有完全理解内容。 它说“ The connection string can only be decrypted on the computer on which it was encrypted.” 我们有一个发布机器,它将构建我们的应用程序,它将生成OurApp.exe.config,然后将其安装到许多产品机器上。 那是不是我们必须将这个加密过程与我们的应用程序分开并在单独的产品机器上运行? 我们可以使用“ RSAProtectedConfigurationProvider ”。 它提到我们需要该提供商的encryption key 。 何时以及如何提供加密密钥? 谢谢,

错误:System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity中出现“操作错误”

我有以下代码来检索我的MVC3 Web应用程序中给定用户名的AD组: PrincipalContext userDomain = new PrincipalContext(ContextType.Domain, username.Split(‘\\’)[0]); UserPrincipal user = UserPrincipal.FindByIdentity(userDomain, username); PrincipalSearchResult memberOfGroups = user.GetGroups(); IEnumerator memberOfGroupsEnumerator = memberOfGroups.GetEnumerator(); List userADGroups = new List(); try { while (memberOfGroupsEnumerator.MoveNext()) { userADGroups.Add(memberOfGroupsEnumerator.Current.ToString()); } } catch { // When trying to access AD groups of a different domain, issues can arise at the end of the […]

使用WebService自动捕获所有未处理的exception

我有一个C#WebService应用程序,我想在其中捕获从应用程序抛出的所有未处理的exception。 我怎样才能做到这一点?

新的和覆盖之间的区别?

我有一个基类,我想为所有inheritance类的方法提供一些“基础”function。 在我想inheritance的inheritance类中: public override void Setup() { base.Setup(); } 但目前它说我必须使用new关键字。 我怎么拥有它所以我必须使用override关键字? 目前我使用new关键字和使用override有什么区别吗?

从源字符串中查找多个索引

基本上我需要做String.IndexOf(),我需要从源字符串中获取索引数组。 有没有简单的方法来获取索引数组? 在提出这个问题之前,我已经搜索了很多,但还没有找到解决这个简单问题的简单解决方案。

PCWSTR与LPWSTR

这是我的理解(如果我错了,请纠正我),它们之间的唯一区别是字符串是否可能被被调用函数修改。 ( PCWSTR , LPWSTR ) 我现在正试图将一个字符串从C#传递给一个期望PCWSTR的函数,但我能找到的只是[MarshalAs(UnmanagedType.LPWStr)] 。 我纠正那没关系吗? (是的,它有效 。但是,这并不能certificate它没问题。有些东西可以工作,但会导致内存泄漏等)

SQL Server管理对象

我使用受信任或SQL登录在下面的代码中得到相同的错误: VS2010,控制台应用程序.NET4,Win XP。 SQL2005完整版。 转移炸弹.TransferData 错误:errorCode = -1073548784 description =执行查询“”失败,并显示以下错误:“由于以下错误,检索具有CLSID {19E353EF-DAF4-45D8-9A04-FB7F7798DCA7}的组件的COM类工厂失败:80040154” 。 可能的失败原因:查询问题,“ResultSet”属性设置不正确,参数设置不正确或连接未正确建立。 这感觉就像安全。 任何想法都会很棒! using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; using System.Collections.Specialized; using System.IO; using System.Configuration; namespace GenerateScripts { class Program { static void Main(string[] args) { ServerConnection sourceConnection = new ServerConnection(“localhost”); Server sourceServer = new Server(sourceConnection); //sourceServer.ConnectionContext.LoginSecure […]

使用VID和PID识别连接到x64的USB设备的COM端口

如下我能够通过给定的pid和vid获得连接到32位win7OS机器的usb com端口名称,但是当在x64中运行时,它会卡在以下行中: comports.Add((string)rk6.GetValue(“PortName”)); 这是我的代码 static List ComPortNames(String VID, String PID) { String pattern = String.Format(“^VID_{0}.PID_{1}”, VID, PID); Regex _rx = new Regex(pattern, RegexOptions.IgnoreCase); List comports = new List(); RegistryKey rk1 = Registry.LocalMachine; RegistryKey rk2 = rk1.OpenSubKey(“SYSTEM\\CurrentControlSet\\Enum”); foreach (String s3 in rk2.GetSubKeyNames()) { RegistryKey rk3 = rk2.OpenSubKey(s3); foreach (String s in rk3.GetSubKeyNames()) { if (_rx.Match(s).Success) { […]

尝试获取ICacheManager类型的实例时出现激活错误,键“Cache Manager”

我似乎在这里遇到了障碍,并希望得到任何能够在这一方面得到帮助的人。 我不确定下面的错误消息是什么意思。 我正在使用企业模式服务的缓存块,但我继续遇到下面的问题。 我下载了最新版本,并尝试逐步解决这个问题,但我似乎无法解决确切的问题,我需要帮助。 提前致谢 Test method WorldBank.Service.Business.UnitTest.TopicsManagerTest.Call_Children_out_of_schoolTest threw exception: Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ICacheManager, key “Cache Manager” —> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = “Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager”, name = “Cache Manager”. Exception occurred while: while resolving. Exception is: InvalidOperationException – The current type, Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, is an interface […]