|
After 7 and a half years and over 400 pages, it's time for a new .NET megathread! The old thread is here. What is .NET? Wikipedia posted:[The] .NET Framework ... is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large class library known as Framework Class Library (FCL) and provides language interoperability (each language can use code written in other languages) across several programming languages. Programs written for .NET Framework execute in a software environment (as contrasted to hardware environment), known as Common Language Runtime (CLR), an application virtual machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute .NET Framework. What languages can I use write to fancy-pants .NET applications?
What's awesome about .NET languages? First off, Microsoft is constantly improving the framework and languages -- there's usually a new .NET release every 1-2 years, which brings new versions of C#, VB, F#, etc. Since our last megathread in January 2007, dozens of new features have come along, several of which changed the way we write code on a day-to-day basis. The big ones are:
Plus, Microsoft has created some of the best tooling around. Visual Studio is the IDE that every other IDE wishes it could be, and the .NET framework is huge and has built-in classes and methods to do just about everything. I want to develop using Visual Studio, but I'm not paying for it! That's fine, Microsoft has Visual Studio Community for you. Microsoft retired the rather limited "Express" edition of Visual Studio in 2014 in favor of a "Community" edition, which is free to use and full-featured. Should I be using source control? Yes! If you want to stay within the Microsoft stack:
TFS is the all in one ALM solution for the Microsoft world -- it has project planning, source control, automated build, and automated release. It's a solid product, but it requires some forethought when setting it up. The standard source control model is centralized, but it also supports distributed version control by way of native Git support as of TFS2013. If you don't care about the Microsoft stack:
Really, the important thing is to use some kind of source control, even for hobbyist projects. It'll save you a lot of pain in the long-run, and possibly even in the short-run. It's entirely possible to switch source control systems if you don't like the one you're using, although the amount of pain in migrating your change history may be prohibitive, depending on where you're going from/to. I want to make a website. What should I do? ASP .NET MVC. Don't use ASP .NET WebForms. WebForms was an interesting attempt by Microsoft to make developing web applications closer to developing desktop applications. It didn't really accomplish that, and at this point it really just gets in the way of writing modern, dynamic sites. I want to make a desktop application. What should I do? WPF. Make sure you follow the Model-View-ViewModel (MVVM) pattern. Don't use WinForms. The WinForms architecture practically forces you to mix your presentation logic with your business logic, which is never a good thing. I want to make a "Modern UI"/Metro/Windows Store application! See above, but also look at Microsoft's Windows Store site. I want to write a mobile app for iOS or Android! Xamarin I want to do some sort of stuff involving a database! Manually writing queries is for suckers! Use an ORM, but not LINQ to SQL. LINQ to SQL is dying/dead. Microsoft's replacement is Entity Framework. Personally, I prefer NHibernate, but both are better than LINQ to SQL. Also, ShaunO posted:If you absolutely have to write ad-hoc queries, your queries don't map well to a full-blown ORM, your application is so small can't justify using a full-blown ORM, or you want to query some other IDbConnection provider. Friends don't let friends use DataTables or reinvent the wheel, use dapper. I want to run my .NET stuff on a non-Windows OS! Mono is an open-source implementation of the CLR for non-Windows OSes. Should I be writing unit tests? Yes! There are some links to a few different unit testing frameworks in this post, but don't worry too much about which one you choose. Writing testable code is harder than writing test code, and the frameworks are all pretty similar to one another. Books/References General Unit Testing
Frameworks/Tools
Visual Studio Plugins
Thanks to Drastic Actions, mortarr, Dust!!!, ShaunO, Dr. Poz, Knyteguy, GrumpyDoctor, and Destroyenator, wwb, and other people I probably forgot to include here for suggestions and links! New Yorp New Yorp fucked around with this message at 00:08 on Apr 17, 2015 |
# ¿ Jun 20, 2014 19:46 |
|
|
# ¿ May 2, 2024 08:03 |
|
Update: 11/12/2014: VS2015, C#6/VB14, .NET 2015ljw1004 posted:Plug: New Yorp New Yorp fucked around with this message at 17:50 on Nov 12, 2014 |
# ¿ Jun 20, 2014 19:47 |
|
crashdome posted:I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects. I'm not a fan of Git, but every time I talk about why I don't like Git I get dogpiled by people telling me I'm stupid, so I won't get into it. The Git tools in VS2013 are solid. They're not great, but they're usable and getting better with every update. Doesn't hurt to try it... just open up the Team Explorer and add a new repo, and you should be off and running. If you have any TFS questions, you can PM me or ask here... I know TFS like the back of my hand.
|
# ¿ Jun 20, 2014 20:48 |
|
Malcolm XML posted:async/await introduces just as many issues as it solves imo What issues does it introduce?
|
# ¿ Jun 20, 2014 23:33 |
|
ATM Machine posted:Visual Studio question: I'm curious as to whether there is a productivity extension that replicates Sublimes' features like line duplication, control+d selection searching, or multiple editing locations. ReSharper does that kind of stuff.
|
# ¿ Jun 21, 2014 07:06 |
|
RICHUNCLEPENNYBAGS posted:What's wrong with Task.RunSynchronously or even just Result? Well, I mean, what's wrong that some other syntax would fix? If you have async code and try to use it synchronously, Bad Things can happen in the form of deadlocks; the async code just waits for something that's never going to happen because everything else is held up waiting for the task to complete. Of course it all depends on the synchronization context... a console app will be fine because it has no synchronization context, it just passes it off to the task scheduler. [edit] Even though Stephen Cleary irks me on a personal level, he knows this poo poo inside and out and explains it really well: http://msdn.microsoft.com/en-us/magazine/jj991977.aspx New Yorp New Yorp fucked around with this message at 07:48 on Jun 21, 2014 |
# ¿ Jun 21, 2014 07:37 |
|
Deus Rex posted:Let's be clear about what you're saying here - TFS is free up to 5 developers until you have to purchase a support contract from some TFS consultant to figure out how to make it work. No?
|
# ¿ Jun 23, 2014 03:06 |
|
wwb posted:As for the OP, there really should be some other SCM options. Here is my rewrite: Thanks, I'll update the OP tonight. I was focusing on Microsoft tooling because this is the catch-all Microsoft development thread. Come to think of it, I'll add a build and release section while I'm at it, and a cloud section.
|
# ¿ Jun 27, 2014 16:45 |
|
Dietrich posted:Holy poo poo why does build time on the Hosted Build Controller cost $.05 a minute? If you're doing true CI, I strongly recommend hooking up an on-prem CI solution. Team Build will of course work just peachy with VSO, as will Jenkins and TeamCity.
|
# ¿ Jun 30, 2014 16:28 |
|
shrughes posted:Why the gently caress doesn't the OP have a link to the old thread? I updated the OP with the link, thanks for the perplexingly hostile reminder.
|
# ¿ Jul 6, 2014 07:25 |
|
GrumpyDoctor posted:Can I thank you for making the great OP and suggest adding Sandcastle/SHFB to it Sure, write up a description and give me links because I'm lazy.
|
# ¿ Jul 6, 2014 07:37 |
|
PapFinn posted:I'm not sure if this is the place to ask, but I'm working on picking up some job specific skills to make myself more useful with my company. We are using Classic ASP with Visual Basic. My understanding is that this is a significantly different environment that a ASP.Net/VB.Net environment. If you're familiar with modern languages and frameworks already, there's nothing much to pick up. It's your standard unmaintainable "presentation and business logic mushed together in one place" mess. Avoid working on it if you can, it sucks and no one hires classic ASP developers anymore.
|
# ¿ Jul 8, 2014 20:39 |
|
Newf posted:More trouble in ASP land. I think that my goal should be obvious from the code, but I'm having a lot of trouble googling the right answers. I'm working with a ListView. Use a databound control, as suggested? This should be in a repeater, it looks like. Or, better yet, don't use webforms if you don't have to.
|
# ¿ Jul 9, 2014 19:14 |
|
Bognar posted:DateTime precision only goes down to the 100 nanoseconds. If you just want to use the built-in formatting DateTime formatting options, then I would say to make a class that wraps DateTime (e.g. PreciseDateTime) to delegate .ToString() calls and use whatever level of precision you need. It might be worth looking at NodaTime, too. I don't know if it has that level of precision, but since it's maintained by a notorious calendar nerd, I wouldn't be surprised if it does. [edit] Actually, nevermind. It doesn't... yet. https://twitter.com/jonskeet/status/484436917602516994
|
# ¿ Jul 12, 2014 03:25 |
|
Ochowie posted:Does anyone have any good SignalR resources? Or has anyone used SignalR and can provide some feedback? I'm trying to send messages with different subsets of a dataset to different clients and I'm not seeing any good guides on how to do that. As an example, I'd like to update stock quotes only for stocks in a given clients portfolio rather than just send all stock quotes and have the client decide which ones to display. I'm not sure that SignalR is the right method for this task but I wanted to play around with it and this seemed like a decent learning application to try. I've only played with SignalR a little bit, but you should be able to create groups, then send messages to just members of that group. http://www.asp.net/signalr/overview/signalr-20/hubs-api/working-with-groups
|
# ¿ Jul 14, 2014 18:01 |
|
gently caress them posted:So I finally felt like playing with LINQ It isn't. It works fine in an arbitrary console application. What's this "Dump" extension method? BTW, the idiomatic way to do this in VB would be with query syntax: code:
New Yorp New Yorp fucked around with this message at 19:26 on Jul 15, 2014 |
# ¿ Jul 15, 2014 19:18 |
|
gently caress them posted:Do you think that the hyphens that I'm taking as input might be different from the hyphens I'm using in the inlined defined list for my linqpad? Entirely possible. – is a different character from -.
|
# ¿ Jul 15, 2014 19:33 |
|
Newf posted:What method does HashSet<> use in order to determine whether an element is already a member of the set? So, you want to quickly store and retrieve key-value pairs. Why are you not using a dictionary?
|
# ¿ Jul 16, 2014 14:56 |
|
Newf posted:That had occurred to me, but wouldn't a dictionary's default action be to overwrite the data associated with an existing key with the new data? I want to keep the original. In particular, the only thing that changes with the new inserts is a timestamp, but I'm only interested in knowing the earliest timestamp. Can you describe the initial problem in a little bit more detail? I'm always wary of the XY Problem rearing its head.
|
# ¿ Jul 16, 2014 15:34 |
|
chippy posted:Bear in mind that it's also recommended that if you override Equals(), you should also override GetHashCode(), to ensure that in any case where Equals() returns true for a pair of objects, GetHashCode() would return the same hash, and vice versa. You're correct.
|
# ¿ Jul 16, 2014 15:43 |
|
Bognar posted:Personally, I'd use a Dictionary and check .ContainsKey before insertion, but I don't think there's a functional difference. It just seems more appropriate to me to use a Dictionary when you're working with keys and values. I'm with you. And I've seen too many bad GetHashCode overrides.
|
# ¿ Jul 16, 2014 16:34 |
|
Ciaphas posted:I have a List<DataRecord> dataRecords that I want to display in a WPF DataGrid. DataRecord is defined more or less as follows: You can either define a template column to display the additional stuff, or let part of your viewmodel's behavior be to transform and project the data into a type intended for display. Option 1: code:
|
# ¿ Jul 16, 2014 22:09 |
|
Yeah, the Option #2 I was talking about was more along these lines: You have your collection of DataRecords. Those obviously aren't intended for display as-is -- it's some sort of DTO. It represents the raw data you got back from something. You should be, at some point prior to that object hitting your view, transforming it into a model intended for actual display. Automapper can help here, or you can do it by hand. Once you have a nice, simple model of the data that's intended for display, you just bind that to your data grid and you're golden.
|
# ¿ Jul 17, 2014 17:18 |
|
wwb posted:Ran headlong into a windows thing that someone here might have ran into -- it seems that Visual Studio 2013 installed HyperV with Update 2 because of windows phone. Unfortunately hyperv breaks networking on VirtualBox and I need that function a lot more than I need to be able to emulate windows phone. Anyhow, I didn't figure this out until after I tried to upgrade virtualbox and ended up with a bunch of screweyness in the network stack somewhereas I can't seem to uninstall or reinstall it. Moreover, I can't remove hyperv at all -- I can uncheck the box, it runs the uninstall, reboots and then hangs at about 36% before rolling back my changes. I've looked in a few of the obvious places but I haven't found any rhyme or reason to this, is there some other tree I should bark up? Or has anyone run into this at all -- everything from google seems to be about people having problems installing hyperv not removing it. Can you uninstall virtualbox entirely?
|
# ¿ Jul 18, 2014 15:39 |
|
gently caress them posted:Is there any rule of thumb as far as MessageBox.show vs actually throwing up some markup and code-behind if you're doing something in WPF? I'm displaying what amounts to a list of "YO these numbers are invalid or were entered wrong" and would rather avoid mucking with markup whenever possible. It's your call, really. If you need styling and flexibility, use a WPF control. If you don't, use a regular old messagebox. One thing to keep in mind: Displaying messageboxes (either framework-provided or custom) is not a viewmodel concern. I usually tackle it by raising an event in my viewmodel, then having the view handle displaying it. The reason is, as always, separation of concerns. If you want to test your viewmodel, you'll can't test it if it's popping up new views or messageboxes. If you raise an event, you can hook something up to the event to simulate results.
|
# ¿ Jul 18, 2014 19:25 |
|
gently caress them posted:Also since it's, uh, terrible, and huge, and crossposting is something I'd rather not do (unless truly warranted) I'm trying to go through some threaded stuff: the old worker thread and wait window idiom! Is it Winforms?
|
# ¿ Jul 18, 2014 20:17 |
|
gently caress them posted:I honestly don't know In WinForms, assuming you just have a stupid form that has a textbox that shows whatever text you set with the "SetText" method: code:
|
# ¿ Jul 18, 2014 20:29 |
|
gently caress them posted:I feel like I haven't adequately explained what the real problem is. The XY problem also just left me a voice mail. No, I understand the problem. The root cause is that the approach the code is taking is dumb. Instead of keeping the UI responsive and doing the work on a different thread, it locks the UI thread doing the work and makes its own temporary special snowflake UI thread to report progress.
|
# ¿ Jul 18, 2014 20:45 |
|
Scaramouche posted:This might be an algorithmic question instead of a .NET question, but I'm doing it in VB.NET so I figured I'd ask here. You might want to look into NUML (http://numl.net/) for this one. It's pretty neat. Basically, you give it a bunch of examples of clean data, a bunch of examples of unclean data, and then run it against your real dataset and let it sort things into two buckets. You'll still have to clean it up manually, but at least it'll help you identify the items that need human love. New Yorp New Yorp fucked around with this message at 21:30 on Jul 18, 2014 |
# ¿ Jul 18, 2014 21:26 |
|
Newf posted:My knowledge of F# has now increased from nothing to "it's like C# except you use two semicolons". I'm confident that this is accurate. This is entirely inaccurate.
|
# ¿ Jul 25, 2014 15:03 |
|
Nevett posted:Get LINQPad! The free version will let you do this (and almost everything else except intellisense) Or just use Powershell, which is already installed on every modern version of Windows. Syntax is a bit different, but it's easy to learn: [System.IO.Path]::GetInvalidFilenameChars()
|
# ¿ Jul 25, 2014 16:04 |
|
Does anyone have any good resources for how to build a modern SPA that leverages MVC5/WebAPI and SignalR and whatever JS frameworks are hot right now? I haven't done any webdev in the past few years, and I really want to put something modern together to keep my skills sharp. Part of the fun is that I'm absolutely terrible at HTML and CSS. I have to resist the urge to use tables for layout.
|
# ¿ Jul 25, 2014 17:31 |
|
Just wanted to thank everyone for the web app advice. I ended up saying "gently caress it" and starting out with just MVC, jQuery, and SignalR. I hacked a tech demo together last night, then spent today redoing it using knockout because the JS was turning into a big mess of random DOM manipulation. I'll probably revisit everything with bootstrap when I have some free time, since the HTML is pretty hideous. Then I can actually start building real functionality!
|
# ¿ Jul 28, 2014 04:56 |
|
Neat, I'll check out react when I have some time! Knockout is serving my purposes well enough; it's close enough to XAML databinding that it doesn't hurt my brain too much.
|
# ¿ Jul 28, 2014 14:35 |
|
RangerAce posted:Well, here's how we do it. Not that this is the One True Way, or anything, but maybe it will give you some ideas. That's how I've always done any sort of service, FWIW.
|
# ¿ Jul 28, 2014 17:52 |
|
Knyteguy posted:How do you guys save little reusable blurbs of code to use through various projects? A class library would work with static methods but that seems like a pain to maintain. Does VS have something like this built in? Code snippets, but a common library makes a lot more sense. Especially if you version it and reference it in dependent projects out of Nuget.
|
# ¿ Jul 29, 2014 00:48 |
|
I fell into a JS framework hole... I threw out knockout and redid my thing in angular. Knockout is more familiar to me as an MVVM user, but Angular is a lot easier.
|
# ¿ Jul 30, 2014 12:55 |
|
Essential posted:I have a data upload process I need to run at a certain point and I need to check every 30 seconds if it's time to upload. Then when I am uploading data I don't want to check again until the process is complete. Once complete I need to start checking every 30 seconds again. This sounds like a case for a separate data-uploading service. You put a message in a queue saying "i need to upload some data". The uploader takes care of business, and when it's done puts a message in a different queue saying "task is done" that your source application will read from. New Yorp New Yorp fucked around with this message at 17:50 on Aug 9, 2014 |
# ¿ Aug 9, 2014 17:38 |
|
Essential posted:Thank you for the suggestion Lucian! Is there a similar async thing I can do with the 4.0 framework? We have to support Win XP machines so I cannot get above 4.0 framework Async BCL on NuGet should work assuming you're developing on VS2012 or later.
|
# ¿ Aug 9, 2014 20:47 |
|
|
# ¿ May 2, 2024 08:03 |
|
Scuzzywuffit posted:So I'm attempting to track down a memory leak that I believe is related to an event handler, and I have a dumb question that shouldn't be that difficult to Google but apparently is (or maybe I am just bad at it). If I do the following: Have you run a profiler? Red Gate's profiler (ANTS, I believe) is excellent at hunting this kind of thing down, and there's a free trial.
|
# ¿ Aug 12, 2014 20:12 |