{"id":3528,"date":"2014-03-27T07:54:30","date_gmt":"2014-03-27T07:54:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/27\/cdatetimelinq-to-datasetrelated-issues-collection-of-common-programming-errors\/"},"modified":"2014-03-27T07:54:30","modified_gmt":"2014-03-27T07:54:30","slug":"cdatetimelinq-to-datasetrelated-issues-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/27\/cdatetimelinq-to-datasetrelated-issues-collection-of-common-programming-errors\/","title":{"rendered":"c#,datetime,linq-to-datasetRelated issues-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b2e31a8153fa41f6c3e933d705af9a90?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nQwerty Bob<br \/>\nc# protocol-buffers protobuf-net<br \/>\nI updated an older version of protobuf to the current one in a huge project (the used version is around 1-2 years old. I don&#8217;t know the rev). Sadly the newer version throws an exceptionCreateWireTypeException in ProtoReader.cs line 292in the following test case:enum Test{test1 = 0,test2};static public void Test1(){Test original = Test.test2;using (MemoryStream ms = new MemoryStream()){Serializer.SerializeWithLengthPrefix&lt;Test&gt;(ms, original, PrefixStyle.Fixed32, 1);ms.Position = 0;Test obj;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1b2b5d5007262ea3f9e21ab5b15f8b75?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ncasperOne<br \/>\nc# .net system.reactive<br \/>\nI&#8217;m using the reactive extensions for a kind of a in process message bus. The implementation is quite simple.Register looks likepublic IDisposable Register&lt;T&gt;(Action&lt;T&gt; action) where T : IMessage {return this.subject.OfType&lt;T&gt;().Subscribe(action); }And send simply:private void SendMessage(IMessage message){this.subject.OnNext(message);}However i&#8217;m now having some trouble with the exception behaviour of RX. One an exception is thrown in a registered\/subscribed action &#8211; the Obser<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/8Tmx5.gif?s=32&amp;g=1\" \/><br \/>\nMikO<br \/>\nc# .net multithreading task<br \/>\nThis question already has an answer here:Access to foreach variable in closure1 answerCan anybody explain why this snippet:\/\/ Create required tasks foreach (var messageToSend in messagesToSend) {EmailMessage messageToBeSent = messageToSend;Task&lt;bool&gt; processingTask = new Task&lt;bool&gt;(() =&gt; SendMessage(messageToBeSent));processingTask.Start(); }Works differently from this one:\/\/ Create required tasks foreach (var messageToSend in messagesToSend) {Task&lt;bool&gt; processingTask = new<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3ddb4866d835dcc369b4b21c9e07b543?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nchrislarson<br \/>\nc# microsoft-metro windows-runtime<br \/>\nI&#8217;m writing a Windows 8 Metro app. I&#8217;m trying to draw a GridView with three Groups. I want one of those groups to layout their items differently than the others. I&#8217;ve used Selectors before in WPF, so I thought that&#8217;d be a good route. So I tried the GroupStyleSelector and I found this example on MSDN :public class ListGroupStyleSelector : GroupStyleSelector {protected override GroupStyle SelectGroupStyleCore(object group, uint level){return (GroupStyle)App.Current.Resources[&#8220;listViewGroupStyle&#8221;];<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/axhfg.jpg?s=32&amp;g=1\" \/><br \/>\neitan barazani<br \/>\nc# windows-8 sharepoint2013 csom<br \/>\nI am developing a Win8 (WinRT, C#, XAML) client application (CSOM) that needs to download\/upload files from\/to SharePoint 2013.How do I do the Download\/Upload? Thx<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/308b211bb6be6cb9d13c127295ee581a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBrian Ball<br \/>\nc# lambda<br \/>\nI&#8217;m running into a problem that I did not expect. An example will probably illustrate my question better than a paragraph:UPDATED: Skip to last code-block for a more eloquent code example.public class A {public string B { get; set; } }public class C : A { }Here is some code from a method:var a = typeof(C).GetMember(&#8220;B&#8221;)[0]; var b = typeof(A).GetMember(&#8220;B&#8221;)[0];Expression&lt;Func&lt;C, string&gt;&gt; c = x =&gt; x.B;var d = (c.Body as MemberExpression).Member;Here are the results of some compariso<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/Qfp6z.png?s=32&amp;g=1\" \/><br \/>\nMatthew Watson<br \/>\nc# optimization<br \/>\nConsider the following code&#8230;In my tests for a RELEASE (not debug!) x86 build on a Windows 7 x64 PC (Intel i7 3GHz) I obtained the following results:CreateSequence() with new() took 00:00:00.9158071 CreateSequence() with creator() took 00:00:00.1383482CreateSequence() with new() took 00:00:00.9198317 CreateSequence() with creator() took 00:00:00.1372920CreateSequence() with new() took 00:00:00.9340462 CreateSequence() with creator() took 00:00:00.1447375CreateSequence() with new() took 00:00:00<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/af631eb847bc9295e3a273a7677555e8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAxel Magagnini<br \/>\nc# .net windows-services desktop-application watchdog<br \/>\nI need some way to monitor a desktop application and restart it if it dies. Initially I assumed the best way would be to monitor\/restart the process from a Windows service, until I found out that since Vista Windows services should not interact with the desktopI&#8217;ve seen several questions dealing with this issue, but every answer I&#8217;ve seen involved some kind of hack that is discouraged by Microsoft and will likely stop working in future OS updates.So, a Windows service is probably not an option a<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/75ee864ee3bef78f2a144398789fed25?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJens<br \/>\nc# .net networking<br \/>\nI am trying to (more or less) uniquely identify a system for licensing purposes. I have chosen the computer&#8217;s on-board network adapter&#8217;s MAC address for this task, since I can be sure that every cmputer running this software actually has one, and this avoids re-activation when changing e.g. the harddrive.I am having troubles reliably identifying the onboard network adapter, though. Using the &#8220;Win32_NetworkAdapterConfiguration&#8221; ManagementClass, I can get a whole lot of MAC Addresses, including th<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9c673c88ffa1d7dfd00b66e9010ffc0a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNailuj<br \/>\nc# reflection attributes tdd assert<br \/>\nI have an example classpublic class MyClass{ActionResult Method1(){&#8230;.} [Authorize]ActionResult Method2(){&#8230;.}[Authorize] ActionResult Method3(int value){&#8230;.}}Now what I want is to write a function returning true\/false that can be executed like thisvar controller = new MyClass();Assert.IsFalse(MethodHasAuthorizeAttribute(controller.Method1)); Assert.IsTrue(MethodHasAuthorizeAttribute(controller.Method2)); Assert.IsTrue(MethodHasAuthorizeAttribute(controller.Method3));I got to the point whe<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1a6ca736b1d0c7cfc9c2055a5408ccc4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMartin Brown<br \/>\nwindows datetime formatting batch-file<br \/>\nIn a windows (XP) batch script I need to format the current date and time for later use in files names etc.,Similar to How to append a date in batch files but with time in as wellI have this so far:echo %DATE% echo %TIME% set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2% echo %datetimef%which gives:28\/07\/20098:35:31.01 2009_07_28__ 8_36_01Is there anyway I can allow for single digit hour in %TIME% so I can get:2009_07_28__08_36_01<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/84502cb3302558cf60f0ba7a7ce87e5a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNeil D<br \/>\ndatetime ssis conditional dataflow dataflowtask<br \/>\nI have an SSIS data flow conditional split transformation that is returning a &gt;= result when it should be returning a &gt; result.From the beginning&#8230; My SSIS package executes a SQL task that stores a max(date) from one table in variable User::max_date of type DateTime that has package scope. My package then proceeds to execute a Data Flow task which has a conditional split transformation in it that has the condition date &gt; @[User::max_date]. The result set is always a single row which has th<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8348bcf40f55bc5818651824369caff1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSoner G\u00f6n\u00fcl<br \/>\nc# .net winforms datetime type-conversion<br \/>\nI need to store DateTime in int. So I tried below codesInt64 n = Int64.Parse(DateTime.Today.ToString(&#8220;dd-MM-yyyy&#8221;));orInt64 twoday_date=Convert.ToInt64(System.DateTime.Today.ToString(&#8220;dd-MM-yyyy&#8221;));but its showing error:Input string was not in a correct format.Where is the error?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ceb4ec169153ed2cdc5a6fb93c5829a6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nanonymous coward<br \/>\nphp datetime<br \/>\nUsing PHP 5.2.5 I was working with some DateTime objects and noticed a time that seemed off. The problem I&#8217;m having may be related to timezones, but I&#8217;m not sure &#8211; I&#8217;m creating a DateTime from a Unix Time Stamp and getting different\/unexpected results depending on how I output it. I created the following to easily illustrate the &#8220;issue&#8221;: $timezone = new DateTimeZone(&#8216;America\/Chicago&#8217;); $now = time(); $now_datetime = new DateTime(&#8216;@&#8217; . $now, $timezone); echo phpversion() . &#8220;\\n\\n&#8221;; echo $now .<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6bd5aa9919e84f930d76026606e5e87c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDolfa<br \/>\nphp datetime db2 timestamp<br \/>\nAfter upgrade to PHP 5.3 my application is returning DB2 columns with Timestamp type as &#8220;2010-12-15-10.23.22.716000&#8221;. This is causing problem for PHP DateTime function , as it fails with$time = new DateTime(&#8220;2010-12-15-10.23.22.716000&#8221;);Failed to parse time string (2010-12-15-10.23.22.716000) at position 25 (0): Unexpected characterIt seems its having a problem with too much accuracy in DB2 timestamp. Can I somehow force connection to change timestamp format with it is fetching data into?I am<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d84b558fd67be10d5a718fb94231909d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBohemian<br \/>\ndatetime delayed-job<br \/>\nI&#8217;m not sure if you guys test like this, but I&#8217;m a TDD guy and keep stumbling into wierd stuff. The timestamps are converted somehow by DJ, or the time zone&#8230; I don&#8217;t know. Test example followsI&#8217;m using delayed_job 2.0.3 data = {:value =&gt; 0.856, :timestamp =&gt; Time.zone.now} job = MyMailer.send_later :send_values, data, emailsMyMailer.expects(:send_values).with(data, emails).once job.payload_object.performclass MyMailerdef self.send_values(data, emails)end endOK, test expectation failureun<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3b4af6fbcb37d41021119636bc1a2e12?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSarfraz<br \/>\nphp mysql datetime date<br \/>\nIn my mySQL database I have a field called FlowerOpen that is in the DATE format (YYYY-MM-DD) in my php script, I want to convert it so the user sees Monday, May 28, 2012I keep finding explanations on how to convert DATETIME to DATE but not DATE to DATETIMEI tried converting the date with the following command:$Date = DATE_FORMAT($ResultsLists[&#8216;FlowerOpen&#8217;],&#8217;%W, %M %e, %Y&#8217;);I keep getting the following error:Warning: date_format() expects parameter 1 to be DateTime, string given in C:\\xampp\\htdo<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a6015b7c906ada6c2fe6f19feee54557?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGlench<br \/>\npython django datetime<br \/>\nBasically I have two datetimes, one from each model. According to python, the datetimes are equal. When I try to query one type of object with the other&#8217;s datetime, no results are returned. However when I try to do the reverse and query the other by the first&#8217;s datetime, a result is returned. The examples below should clarify what is wrong.My models look like this (abbreviated):class Shift(models.Model):normalized_start = models.DateTimeField(null=True)class ScheduledShift(models.Model):start_da<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/e51Ks.jpg?s=32&amp;g=1\" \/><br \/>\nBrian Rogers<br \/>\njquery-ajax datetime asp.net-web-api json.net<br \/>\nI&#8217;ve modified WebAPI JSON.Net serialization to use JavaScriptDateTimeConverter. The plan was to get jscript date object instead of ISO 8601 formatted string. But unfortunately when I do post request with jquery like this:$.ajax({type: &#8220;POST&#8221;,contentType: &#8220;application\/json; charset=utf-8&#8221;,url: &#8220;#UrlToService&#8221;,dataType: &#8220;json&#8221;,data: JSON.stringify(args),success: function (data) {callSucceeded(data);},error: function (jqXHR, textStatus, errorThrown) {BJ.GenericWebAPIFailMethod(jqXHR);}});error: is<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/000bb1d00847e45d13261de83cc6a181?s=128&amp;d=identicon&amp;r=PG\" \/><br \/>\nbanditKing<br \/>\nruby-on-rails ruby datetime<br \/>\nIm trying to get the current date inside my rails model like this:Inside Photo.rbPaperclip.interpolates :prefix do |attachment, style|:today_date =&gt; Date.today.to_s&#8221;#{:today_date}\/#{attachment.instance.image_file_name}&#8221;end When I send a Photo to the server from the client I get an error and the following console output on the server. This tells me that there is a problem with the &#8220;Date&#8221; functionServer Console:Started POST &#8220;\/photos.json&#8221; for 127.0.0.1 at 2013-02-20 13:47:35 -080013:47:35 web.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/bLX0T.png?s=32&amp;g=1\" \/><br \/>\n13 revsTim Schmelter<br \/>\n.net vb.net linq compiler linq-to-dataset<br \/>\nEdit: Here is a much more simpler example of this issue (i&#8217;ve deleted my original question):Dim numbers1 As New List(Of Int32)({1, 2, 3}) Dim numbers2 As New List(Of Int32)({3, 4, 5}) For Each n1 In numbers1&#8242; no warning &#8216;Dim contains = numbers2.Contains(n1) Next For Each n1 In numbers1&#8217; warning on n1&#8217;Dim contains = (From num In numbers2 Where num = n1).Any NextSo i still don&#8217;t understand why the compiler thinks that i may get unexpected results in the second iteration whereas i&#8217;m safe with the f<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/52d8d1714c9b0fa45895b79852e1ad25?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nO.O<br \/>\nc# generics linq-to-dataset<br \/>\nI have a method that determines the min and max of a column in a DataTable:public void GetMinMaxRange( DataTable data, string valueColumnName ) {var min = data.AsEnumerable().Min(m =&gt; m.Field&lt;double&gt;(valueColumnName));var max = data.AsEnumerable().Max(m =&gt; m.Field&lt;double&gt;(valueColumnName)); }I want to refactor this to be:public void GetMinMaxRange( DataTable data, string valueColumnName ) {DataColumn column = data.Columns[valueColumnName];var min = data.AsEnumerable().Min(m =&amp;g<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/39a090e48ae3a94fe025a73573ead91f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njulien<br \/>\nc# linq dataset strongly-typed-dataset linq-to-dataset<br \/>\nHere is the configuration of my datatables that I use in my linq query: I have 2 dataset files (all the columns of all the tables have a DataType specified and their AllowDbNull property set to True): * deposit_position_imbalance.xsd:Contains 2 datables : &#8211; Imbalance- ImbalanceDetailForRealTime * dep_pos_imbalance_detail.xsd:Contains 1 datatable : &#8211; TableIn the code below, the problem lies in the 2 lines &#8220;deal_date = b.deal_date&#8221;. Indeed, when I retrieve from the database b.deal_date that has a<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/770eb708789729b6ccbae9e2973e9996?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJay Stevens<br \/>\nc# datetime linq-to-dataset<br \/>\nI need to get the minimum DateTime value of a column in a DataTable. The DataTable is generated dynamically from a CSV file, therefore I don&#8217;t know the name of that column until runtime. Here is code I&#8217;ve got that doesn&#8217;t work&#8230;private DateTime GetStartDateFromCSV(string inputFile, string date_attr) {EnumerableRowCollection&lt;DataRow&gt; table = CsvStreamReader.GetDataTableFromCSV(inputFile, &#8220;input&#8221;, true).AsEnumerable();DateTime dt = table.Select(record =&gt; record.Field&lt;DateTime&gt;(dat<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Qwerty Bob c# protocol-buffers protobuf-net I updated an older version of protobuf to the current one in a huge project (the used version is around 1-2 years old. I don&#8217;t know the rev). Sadly the newer version throws an exceptionCreateWireTypeException in ProtoReader.cs line 292in the following test case:enum Test{test1 = 0,test2};static public void Test1(){Test original [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3528","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3528"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3528\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}