.net-4.0

Parallel.For and Break() misunderstanding?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 21:27:44
问题 I'm investigating the Parallelism Break in a For loop. After reading this and this I still have a question: I'd expect this code : Parallel.For(0, 10, (i,state) => { Console.WriteLine(i); if (i == 5) state.Break(); } To yield at most 6 numbers (0..6). not only he is not doing it but have different result length : 02351486 013542 0135642 Very annoying. (where the hell is Break() {after 5} here ??) So I looked at msdn Break may be used to communicate to the loop that no other iterations after

How to exclude specific types from serialization?

旧时模样 提交于 2019-12-06 21:10:55
问题 I run sgen against my assembly with a metric ton of types. I want to exclude 2 types from serialization. I don't seem to be able to find a way to do it. I see that sgen has a /type switch to specify a specific type, but nothing to exclude a specific type. Is there a way to exclude specific types from serialization? 回答1: Apart from putting the types you wish to exclude in a different assembly, you cannot exclude types from the serializer generation. Update Other posters have come up with

How to read an .RTF file using .NET 4.0

给你一囗甜甜゛ 提交于 2019-12-06 20:33:06
问题 I have seen samples using Word 9.0 object library. But I have Office 2010 Beta and .NET 4.0 in VS2010. Any tips on how to go with the new Word Dlls? So I just wanted to get the functionality of RTF to TEXT with .NET3.5 or later. 回答1: I got a better solution with WPF , using TextRange. FlowDocument document = new FlowDocument(); //Read the file stream to a Byte array 'data' TextRange txtRange = null; using (MemoryStream stream = new MemoryStream(data)) { // create a TextRange around the entire

WPF DotNET Application will run in debug mode, but .EXE will not run

我是研究僧i 提交于 2019-12-06 20:21:06
问题 I wrote a WPF application in C# using VS 2010. The application will run fine in debug mode using Visual Studio, but when I go to run the .EXE from the bin\release folder, nothing happens. I do not get any error messages from windows and there are no errors or warnings in VS. I have tried to build, rebuild and clean the solution (in every possible order) with no luck. My solution contains 2 projects, both of which use .NET 4.0 framework, and I have .NET 4.0 installed on my PC. I have tried on

How to fix exception thrown when sending mail message to multiple recipients?

好久不见. 提交于 2019-12-06 19:47:51
问题 In the code snippet below, I'm getting a FormatException on 'this.Recipients'. More specifically, the message is "An invalid character was found in the mail header: ';'". Recipients is a string of three email addresses separated by semicolons (the ';' character). The list of recipients is read from an app.config and the data is making it into the Recipients variable. How can I be getting this error when multiple recipients should be separated by a semicolon? Any suggestions? As always, thanks

Why don't object reference error exceptions in .net tell me which object was null?

戏子无情 提交于 2019-12-06 19:13:57
问题 Maybe asking the question betrays my lack of knowledge about the process, but then again, there's no better reason to ask! Tracking these down can be frustrating because stack traces can help me know where to start looking but not which object was null. What is going on under the hood here? Is it because the variable names aren't bundled in the executable? 回答1: .NET code built with full optimizations and no debug info: your local variable names are gone, some local variables may have been

Timeout.InfiniteTimespan in .Net 4.0?

这一生的挚爱 提交于 2019-12-06 19:12:40
问题 I actually do know that Timeout.InfiniteTimespan does not exist in .NET 4.0. Noticed, there's also Timeout.Infinite which does exist in .NET 4.0 I am calling those two methods: // the Change-Method public bool Change( TimeSpan dueTime, TimeSpan period ) // the Constructor of Timer public Timer( TimerCallback callback, Object state, TimeSpan dueTime, TimeSpan period ) in some cases, the dueTime Parameter needs to be infinite, which means the Event is not fired. I know I could simply use an

Microsoft ReportViewer Web Control Requiring a ScriptManager

荒凉一梦 提交于 2019-12-06 19:06:27
问题 I'm trying to render the report viewer programmatically within a custom Page placed in an IHttpHandler context ReportViewer rv = new ReportViewer(); ReportDataSource rds = new ReportDataSource(); rds.Name = "Report"; rv.LocalReport.ReportPath = "Report.rdlc"; rds.Value = SomeReportObject; rv.LocalReport.DataSources.Add(rds); rv.LocalReport.Refresh(); ScriptManager scriptHandler = new ScriptManager(); MyPage p = new MyPage(); p.Controls.Add(scriptHandler); p.Controls.Add(rv); using (TextWriter

EF, Code First - How to set a custom Guid identity value on insert

故事扮演 提交于 2019-12-06 18:50:08
问题 I`m facing the following problem when dealing with inserting new entities in the DB that has Guid as primary keys - EF 5 with Code first approach. I know there are a lot similar topics as I was roving for hours for this issue, but I couldn`t find topic with this problem. As an example, my POCO class is: public class EntityRole : IAdminModel { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [Required] [MaxLength(50)] public string Name { get; set; }

Repercussions of enabling useLegacyV2RuntimeActivationPolicy?

守給你的承諾、 提交于 2019-12-06 18:40:41
问题 For my current project, we're using some CLR 2 based mixed mode assemblies. In order to use these from within a .NET 4 targetted assembly, I know you have to add useLegacyV2RuntimeActivationPolicy=true to the <startup> element within app.config. I understand that this changes the activation policy, causing these mixed-mode assemblies to be loaded using the highest supported version of the CLR. However, are there any side effects to doing this? What potential issues should I watch for when