Tag: .net 4.0

使用.net 4.0测试程序集测试.net 3.5程序集时的风险有多大

我意识到Visual Studio 2010 sp1允许测试项目现在以3.5为目标。 但是,出于各种原因,我并不完全了解,我们的测试项目仍然以dot net 4.0为目标。 一般问题在标题中。 风险有多大? 具体来说,这可能意味着测试将在CLR v4中运行,而我们的许多客户将使用CLR v2。 此外,测试似乎使用v4库组件(例如System.Data),即使应用程序是针对v2构建的。 一个方法(System.Data.SqlClient.SqlBulkCopy)包含v2中的错误,该错误已在v4中修复。 我们的测试错过了。 暂且不说CLR,我怎样才能强制我的应用程序使用某些库的v2,即使它被v4测试程序集引用(加载到应用程序域中)? 我一直在尝试一个例子,似乎无法实现它。 我的3.5应用程序引用System.Data v2,并将程序集版本号回显到控制台。 从3.5测试程序集调用时,版本为2.0。 从4.0测试程序集中,版本为4.0。 (在我的应用程序的参考中,“特定版本”设置为true)

GC根源误解?

我知道Roots是: 静态字段 方法参数 当地的fielfs f-queue还包含一个指向“即将被完成”的对象的指针 cpu寄存器<= ??? 现在让我们谈谈寄存器。 他们可以包含的代码如下: mov bx, 0034h ; bx = 52 (stored in 16 bits) mov cl, bl ; cl = lower 8-bits of bx mov eax, ecx call print_int 但是等等 ! 如果我没有弄错的话,这就是实际的代码,那就是从那里开始拿那些static , local和parameters ! 那么为什么写这个TWICE呢? (或从另一个方向?) 为什么要写(例如) Foo f = new Foo(); **and also** mov bx, 0034h //<——– […]

如何在“应用程序和服务日志”中深入指定事件?

以下代码段会在记录事件时触发事件。 示例代码工作正常但我要监视的日志实际上是“应用程序和服务日志> Microsoft> Windows>任务计划程序>操作”。 我在代码示例中插入了什么代替“Application”? … EventLog myNewLog = new EventLog(“Application”, “.”, “testEventLogEvent”); myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten); myNewLog.EnableRaisingEvents = true; …

c#MemoryMappedFile in .net 3.5

我需要在.net 3.5中使用MemoryMappedFile类…有没有办法找到.net 4.0中使用的类的代码并创建在.net 3.5中使用? 提前致谢

.NET4.0:更新字典及其值的线程安全方式

我有一个静态词典,我想安全更新。 最初,字典将为空,但在应用程序的生命周期内,它将添加新值。 此外,整数值将作为可以递增和递减的单个计数器。 private static Dictionary foo = new Dictionary(); public static void Add(string bar) { if (!foo.ContainsKey(bar)) foo.Add(bar, 0); foo[bar] = foo[bar] + 1; } public static void Remove(string bar) { if (foo.ContainsKey(bar)) { if (foo[bar] > 0) foo[bar] = foo[bar] – 1; } } 我一直在阅读Interlocked类作为提供线程安全的方法,看起来这可能是我可以使用的东西: public static void Add(string bar) { if (!foo.ContainsKey(bar)) […]

c#Linq’s – GroupedEnumerable用法?

Fruit[] data = new[] { new Fruit {Name = “Gala”,Type = “Apple”,Price = 0.75m,Quantity = 10}, new Fruit {Name = “Granny Smith”,Type = “Apple”,Price = 0.80m,Quantity = 7}, new Fruit {Name = “Tasty”,Type = “Strawberries”,Price = 1.90m,Quantity = 20} }; var grouped = from fruit in data group fruit by fruit.Type; grouped类型是: System.Linq.GroupedEnumerable 看看它: 我的问题 […]

IMetaDataImport :: ResolveTypeRef方法的问题

我有自己的.NET应用调试器,它使用IMetaDataImport接口 当我调用ResolveTypeRef方法时,我总是得到NotImplementedException 。 ResolveTypeRef的定义如下: [ComImport] [Guid(“….”)] //a valid GUID [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [CLSCompliant(false)] public interface IMetaDataImport { void ResolveTypeRef( [ComAliasName(“mdTypeRef”)] mdToken tr, [ComAliasName(“REFIID”)] ref Guid riid, [ComAliasName(“IUnknown**”), Out, MarshalAs(UnmanagedType.IUnknown)] out object ppIScope, [ComAliasName(“mdTypeDef*”), Out] out mdToken ptd ); // … other methods from IMetaDataImport } 调用方法: metadataImport.ResolveTypeRef(typeRefToken, ref metadataImportGuid, out metadataObject, out typeDefToken) 通常,该方法应解析类型System.Exception或System.SystemException。 当我将应用程序从.NET 3.5移动到.NET 4时出现问题。 […]

读取没有任何部分的ini文件?

我的ini文件没有任何部分。 它有以下数据 com.ibm.rcp.toolbox.admin / toolboxvisibleChild =假 com.ibm.collaboration.realtime.community/defaultAuthType=ST-DOMINO-SSO com.ibm.collaboration.realtime.brokerbridge / startBroker =假 com.ibm.collaboration.realtime.webapi / startWebContainer =真 我想用function。 [DllImport(“kernel32”)] private static extern int GetPrivateProfileString(string section, string key,string def, StringBuilder retVal, int size,string filePath); 我的问题 我不能在函数中给出节名,因为我没有 如果我给段名称null,则不返回任何内容 我不想像ReadAllText那样使用蛮力

asp.net在网站中添加自定义控件

我想在我的网站上制作一个自定义控件(注意:不是Web应用程序) 以下是代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; namespace AnkitControls { /// /// Summary description for CustomTreeView /// public class CustomTreeViewControl : WebControl { } } Default.aspx: Welcome to ASP.NET! To learn more about ASP.NET visit www.asp.net. You can also find documentation on ASP.NET at MSDN. 当我编译网站时,它给我组装错误。 […]

从委托中锁定静态对象不起作用

为什么这不起作用? private static object Lock_HandleError = new object(); public static void HandleError(Exception ex) { lock( Lock_HandleError ) { //IF the UI is processing a visual tree event (such as IsVisibleChanged), it throws an exception when showing a MessageBox as described here: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/44962927-006e-4629-9aa3-100357861442 //The solution is to dispatch and queue the MessageBox. We must use BeginInvoke […]