c#,datetime,linq-to-datasetRelated issues-Collection of common programming errors


  • 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’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<Test>(ms, original, PrefixStyle.Fixed32, 1);ms.Position = 0;Test obj;

  • casperOne
    c# .net system.reactive
    I’m using the reactive extensions for a kind of a in process message bus. The implementation is quite simple.Register looks likepublic IDisposable Register<T>(Action<T> action) where T : IMessage {return this.subject.OfType<T>().Subscribe(action); }And send simply:private void SendMessage(IMessage message){this.subject.OnNext(message);}However i’m now having some trouble with the exception behaviour of RX. One an exception is thrown in a registered/subscribed action – the Obser

  • MikO
    c# .net multithreading task
    This 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<bool> processingTask = new Task<bool>(() => SendMessage(messageToBeSent));processingTask.Start(); }Works differently from this one:// Create required tasks foreach (var messageToSend in messagesToSend) {Task<bool> processingTask = new

  • chrislarson
    c# microsoft-metro windows-runtime
    I’m writing a Windows 8 Metro app. I’m trying to draw a GridView with three Groups. I want one of those groups to layout their items differently than the others. I’ve used Selectors before in WPF, so I thought that’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[“listViewGroupStyle”];

  • eitan barazani
    c# windows-8 sharepoint2013 csom
    I 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

  • Brian Ball
    c# lambda
    I’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(“B”)[0]; var b = typeof(A).GetMember(“B”)[0];Expression<Func<C, string>> c = x => x.B;var d = (c.Body as MemberExpression).Member;Here are the results of some compariso

  • Matthew Watson
    c# optimization
    Consider the following code…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

  • Axel Magagnini
    c# .net windows-services desktop-application watchdog
    I 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’ve seen several questions dealing with this issue, but every answer I’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

  • Jens
    c# .net networking
    I am trying to (more or less) uniquely identify a system for licensing purposes. I have chosen the computer’s on-board network adapter’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 “Win32_NetworkAdapterConfiguration” ManagementClass, I can get a whole lot of MAC Addresses, including th

  • Nailuj
    c# reflection attributes tdd assert
    I have an example classpublic class MyClass{ActionResult Method1(){….} [Authorize]ActionResult Method2(){….}[Authorize] ActionResult Method3(int value){….}}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

  • Martin Brown
    windows datetime formatting batch-file
    In 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

  • Neil D
    datetime ssis conditional dataflow dataflowtask
    I have an SSIS data flow conditional split transformation that is returning a >= result when it should be returning a > result.From the beginning… 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 > @[User::max_date]. The result set is always a single row which has th

  • Soner Gönül
    c# .net winforms datetime type-conversion
    I need to store DateTime in int. So I tried below codesInt64 n = Int64.Parse(DateTime.Today.ToString(“dd-MM-yyyy”));orInt64 twoday_date=Convert.ToInt64(System.DateTime.Today.ToString(“dd-MM-yyyy”));but its showing error:Input string was not in a correct format.Where is the error?

  • anonymous coward
    php datetime
    Using PHP 5.2.5 I was working with some DateTime objects and noticed a time that seemed off. The problem I’m having may be related to timezones, but I’m not sure – I’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 “issue”: $timezone = new DateTimeZone(‘America/Chicago’); $now = time(); $now_datetime = new DateTime(‘@’ . $now, $timezone); echo phpversion() . “\n\n”; echo $now .

  • Dolfa
    php datetime db2 timestamp
    After upgrade to PHP 5.3 my application is returning DB2 columns with Timestamp type as “2010-12-15-10.23.22.716000”. This is causing problem for PHP DateTime function , as it fails with$time = new DateTime(“2010-12-15-10.23.22.716000”);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

  • Bohemian
    datetime delayed-job
    I’m not sure if you guys test like this, but I’m a TDD guy and keep stumbling into wierd stuff. The timestamps are converted somehow by DJ, or the time zone… I don’t know. Test example followsI’m using delayed_job 2.0.3 data = {:value => 0.856, :timestamp => 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

  • Sarfraz
    php mysql datetime date
    In 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[‘FlowerOpen’],’%W, %M %e, %Y’);I keep getting the following error:Warning: date_format() expects parameter 1 to be DateTime, string given in C:\xampp\htdo

  • Glench
    python django datetime
    Basically 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’s datetime, no results are returned. However when I try to do the reverse and query the other by the first’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

  • Brian Rogers
    jquery-ajax datetime asp.net-web-api json.net
    I’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: “POST”,contentType: “application/json; charset=utf-8”,url: “#UrlToService”,dataType: “json”,data: JSON.stringify(args),success: function (data) {callSucceeded(data);},error: function (jqXHR, textStatus, errorThrown) {BJ.GenericWebAPIFailMethod(jqXHR);}});error: is

  • banditKing
    ruby-on-rails ruby datetime
    Im trying to get the current date inside my rails model like this:Inside Photo.rbPaperclip.interpolates :prefix do |attachment, style|:today_date => Date.today.to_s”#{:today_date}/#{attachment.instance.image_file_name}”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 “Date” functionServer Console:Started POST “/photos.json” for 127.0.0.1 at 2013-02-20 13:47:35 -080013:47:35 web.

  • 13 revsTim Schmelter
    .net vb.net linq compiler linq-to-dataset
    Edit: Here is a much more simpler example of this issue (i’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′ no warning ‘Dim contains = numbers2.Contains(n1) Next For Each n1 In numbers1’ warning on n1’Dim contains = (From num In numbers2 Where num = n1).Any NextSo i still don’t understand why the compiler thinks that i may get unexpected results in the second iteration whereas i’m safe with the f

  • O.O
    c# generics linq-to-dataset
    I 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 => m.Field<double>(valueColumnName));var max = data.AsEnumerable().Max(m => m.Field<double>(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 =&g

  • julien
    c# linq dataset strongly-typed-dataset linq-to-dataset
    Here 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 : – Imbalance- ImbalanceDetailForRealTime * dep_pos_imbalance_detail.xsd:Contains 1 datatable : – TableIn the code below, the problem lies in the 2 lines “deal_date = b.deal_date”. Indeed, when I retrieve from the database b.deal_date that has a

  • Jay Stevens
    c# datetime linq-to-dataset
    I 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’t know the name of that column until runtime. Here is code I’ve got that doesn’t work…private DateTime GetStartDateFromCSV(string inputFile, string date_attr) {EnumerableRowCollection<DataRow> table = CsvStreamReader.GetDataTableFromCSV(inputFile, “input”, true).AsEnumerable();DateTime dt = table.Select(record => record.Field<DateTime>(dat

Web site is in building