Tag: bcl

Microsoft.Threading.Tasks引用不正确的System.Threading.Tasks.dll版本

我正在使用.NET framework 4.0开发一个C#库。 在这个库上我安装了这些NuGet包: 这是我的App.config内容: 在这个项目中,我正在引用System.Threading.Tasks version 2.6.10.0 。 我已经创建了一个安装程序并将该项目安装在另一台计算机 我在安装程序上添加了System.Threading.Tasks version 2.6.10.0 (在GAC上安装此dll)。 但是,当我运行可执行文件时,我收到此错误: Could not load file or assembly ‘System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified. at MyProject.Common.WebApi.Client.AsyncHelpers.c__DisplayClass7 1.b__6(Object _) at MyProject.Common.WebApi.Client.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() at MyProject.Common.WebApi.Client.AsyncHelpers.RunSync[T](Func 1 task) at MyProjectCodesManagerWindowsService.WebApi.Client.MyProjectCodesManagerClient.PrepareAndStartv2(String orderNumber, String userName, String systemName) 但在所有项目中我都引用System.Threading.Tasks […]

MemoryStream的byte 缓冲区可以变化吗?

我正在使用MemoryStream将对象序列化为byte[] : byte[] serialized = new byte[1000]; using (MemoryStream stream = new MemoryStream(serialized)) using (TextWriter textWriter = new StreamWriter(stream)) serializer.Serialize(textWriter, stuffToSerialize); 有没有什么方法可以根据stuffToSerialize的大小设置’serialized’来增长?

为什么我在使用Microsoft.Bcl时不能在Windows Phone 7.1 MvvmCross项目中使用await关键字 – 无法等待’System.Threading.Tasks.Task?

在使用Microsoft.Bcl“Microsoft BCL Portability Pack”时,我无法在MvvmCross Windows Phone 7.1项目中使用await关键字。 我已经在GitHub上发布了我在下面描述的示例项目的代码, 并且此行发生了await错误 。 当我尝试构建包含FirstViewModel的第三个“核心”Windows可移植类库(PCL)时,我得到以下错误: Type System.Threading.Tasks.Task not awaitable under VS red squiggles, and Cannot await ‘System.Threading.Tasks.Task’ when building. 解决方案中有四个项目: 一个Windows可移植类库(PCL),其中包含一个接口,该接口引用BCL提供的“任务”对象。 一个针对OS 7.1的Windows Phone类库,它实现了上面的接口,并且还使用了BCL中的“任务”。 另一个Windows可移植类库(PCL),提供应用程序的“核心”function,包括ViewModel。 尝试引用和使用上述DLL的Windows Phone 7.1 /“7.5”应用程序。 前两个项目包含接口和接口的实现编译没有任何错误。 但第3个“核心”PCL无法使用上面显示的错误构建。 更多细节如果你想要他们: 我尝试了这个App.config“修复”,如“已知的BCL问题”中所述: http : //blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx 。但是当我添加时没有解决错误App.config只是“核心”项目,也不是我尝试将相同的App.config添加到每个项目。 我可能没有在元素中使用正确的版本,或者我只是错误地完成了App.config的操作。 解决方案中设置为以PCL为目标的每个项目在Visual Studio中都设置为“Profile104”。 那些DLL位于: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\ 此PCL配置文件显示为在Visual Studio项目属性中定位这些平台:.NET for Windows […]

转到声明有害吗?

如果上面的陈述是正确的,那么为什么当我在.Net BCL上使用reflection器时,我看到它被大量使用了? 编辑:让我重新说一下:我在人类或编译器编写的reflection器中看到的所有GO-TO是什么?

使用CodeDOM将程序集添加到BuildManager导致间歇性错误

我正在使用CodeDOM在运行时创建内存中的程序集,如下所示: public Assembly Compile(CodeCompileUnit targetUnit) { string path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath); var compilerParameters = new CompilerParameters { GenerateInMemory = true, IncludeDebugInformation = true, TreatWarningsAsErrors = true, WarningLevel = 4, CompilerOptions = “/nostdlib”, }; //For system.dll compilerParameters.ReferencedAssemblies.Add(typeof(System.Diagnostics.Debug).Assembly.Location); //For system.core.dll compilerParameters.ReferencedAssemblies.Add(typeof(System.IO.DirectoryInfo).Assembly.Location); //For Microsoft.CSharp.dll compilerParameters.ReferencedAssemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).Assembly.Location); compilerParameters.ReferencedAssemblies.Add(typeof(System.Runtime.CompilerServices.CallSite).Assembly.Location); //Add other assemblies as needed. var compilerResults = new CSharpCodeProvider() .CompileAssemblyFromDom(compilerParameters, targetUnit); […]

使用隐式/显式转换而不是构造函数的原因是什么?

一个例子是: XNamespace ns = “my namespace” 为什么不?: XNamespace ns = new XNamespace ( “my namespace” ) 使用隐式/显式转换而不是构造函数背后的想法是什么? 方便? 有这方面的指导方针吗?

RuntimeHelpers.GetHashCode做了什么

RuntimeHelpers.GetHashCode(object)方法允许基于对象的标识生成哈希码。 MSDN 声明 : RuntimeHelpers.GetHashCode方法总是非虚拟地调用Object.GetHashCode方法,即使对象的类型已重写Object.GetHashCode方法。 [MethodImpl(MethodImplOptions.InternalCall)] [SecuritySafeCritical] public static extern int GetHashCode(object o); 但是,在使用Reflector(.NET 4.0)检查Object.GetHashCode()方法时,我们将看到以下代码: public virtual int GetHashCode() { return RuntimeHelpers.GetHashCode(this); } 这让我相信MSDN文档是错误的,因为从RuntimeHelpers.GetHashCode(object)调用Object.GetHashCode会导致堆栈溢出。 那么RuntimeHelpers.GetHashCode(object)的实际行为是什么?它是如何工作的? 它是如何计算哈希值的?

数学解释为什么Decimal的转换为Double并且Decimal.GetHashCode将相等的实例分开

我不确定这种说明Stack Overflow问题的非标准方式是好还是坏,但是这里有: 什么是最好的(数学或其他技术)解释为什么代码: static void Main() { decimal[] arr = { 42m, 42.0m, 42.00m, 42.000m, 42.0000m, 42.00000m, 42.000000m, 42.0000000m, 42.00000000m, 42.000000000m, 42.0000000000m, 42.00000000000m, 42.000000000000m, 42.0000000000000m, 42.00000000000000m, 42.000000000000000m, 42.0000000000000000m, 42.00000000000000000m, 42.000000000000000000m, 42.0000000000000000000m, 42.00000000000000000000m, 42.000000000000000000000m, 42.0000000000000000000000m, 42.00000000000000000000000m, 42.000000000000000000000000m, 42.0000000000000000000000000m, 42.00000000000000000000000000m, 42.000000000000000000000000000m, }; foreach (var m in arr) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, “{0,-32}{1,-20:R}{2:X8}”, m, (double)m, m.GetHashCode() )); } Console.WriteLine(“Funny consequences:”); […]

ConcurrentBag 实现中是否存在内存泄漏?

可能重复: ConcurrentBag中可能的内存泄漏? EDIT1: 实际的问题是。 你能证实这一点,或者我的样本是错误的,我错过了一些明显的东西吗? 我认为ConcurrentBag是一个简单的替代无序列表。 但是我错了。 ConcurrentBag确实将自己作为ThreadLocal添加到创建线程,这基本上会导致内存泄漏。 class Program { static void Main(string[] args) { var start = GC.GetTotalMemory(true); new Program().Start(args); Console.WriteLine(“Diff: {0:N0} bytes”, GC.GetTotalMemory(true) – start); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Thread.Sleep(5000); } private void Start(string[] args) { for (int i = 0; i < 1000; i++) { var bag = new ConcurrentBag(); bag.Add(1); byte […]

Microsoft.Bcl.Async如何工作?

Microsoft.Bcl.Async使开发人员能够使用async/await关键字,而不使用.NET Framework 4.5,他们应该使用这些关键字来使用它们。 这很棒,这得益于Microsoft CLR和语言团队中人员的辛勤工作。 现在我很好奇这是如何工作的。 async/await要求编译器做一些繁重的工作来将代码变成可以等待操作的东西。 编译器最初在.NET Framework 4.0下抛出编译错误,即使它清楚地知道async/await是什么意思(Visual Studio 2012/2013。) 那么这个库如何告诉编译器不要抛出与异步操作相关的特定编译错误,并且像在.NET Framework 4.5下一样解除一些代码?