|
Ithaqua posted:It isn't. It works fine in an arbitrary console application. What's this "Dump" extension method? I can confirm that it works fine. It outputs "H012345678901" twice. gently caress them what are you expecting as output? You have a NullReferenceException in your Where clause. You should check String.IsNullOrWhiteSpace first and then run the Regex on your string. The Dump extension is something in LinqPad to know what to output.
|
# ¿ Jul 15, 2014 19:28 |
|
|
# ¿ May 7, 2024 01:04 |
|
gently caress them posted:Just what exactly are ALL of the places one can change how requests are returned in .NET? I've gone through every single decorator I can find for my methods in .svc and .asmx and .whatever files, and I want to return JSON, and I keep either returning a single XML string which itself contains JSON, or I return JSON in a SOAP envelope. Stop using ASMX. It's really freaking old. If you are starting fresh today you want to use Web API. That's the easiest way to send json or XML over HTTP to a client. If you can't use Web API use WCF.
|
# ¿ Jul 27, 2014 06:27 |
|
Newf posted:I've got a class with some static and some non-static methods, and I'd like to lazily check the existence of system setup / default configurations whenever the class is referenced. Is the following a bad idea for any reason? InitClass will be called at startup because the runtime wants to create the variable initialized. It sounds like you want Lazy<T>. Without a better sample it's hard to say if this is good or bad. I'd lean toward not doing it because it's hard to mock out or hide static anything during a unit test.
|
# ¿ Aug 8, 2014 17:01 |
|
ljw1004 posted:In practice, the JIT compiles a method only at the first time the method is invoked. At that moment it first chases down every type that's touched by the method, and ensures they're all loaded. The type-load process will invoke all static constructors (hence, will initialize all static variables). You are correct. I was dumb. I create a console application and put the static items in the class Program so InitClass is called before application startup because the .NET runtime create the Program class. Creating another non-static class and putting in the static member and method has the creation wait until you touch the class. EDIT: Was the initialization changed since Skeet's blog post? I tried the "Eager initialization: .NET 3.5" example and it printed out "Type initialized" when the class was touched. Changing the targeted .NET version didn't help. I don't have VS2008 installed and I'm too lazy to grab it gariig fucked around with this message at 18:36 on Aug 8, 2014 |
# ¿ Aug 8, 2014 18:13 |
|
You can but I'd setup a server that you push to for integration. That way you can bring your local IIS Express up and down and your co-workers don't need to worry if you left the API up or not. If you can't get another box deploy to your local IIS instance and leave that running over port 80.
|
# ¿ Sep 6, 2014 19:26 |
|
RICHUNCLEPENNYBAGS posted:So for people for do this how do you handle different branches working with modified database schemas? I'd spin up a VM for each branch to deploy to. What problem are you trying to solve? EDIT: VVVV That's another way to do it. Also, deploying to Azure/AWS/etc would work gariig fucked around with this message at 17:56 on Sep 7, 2014 |
# ¿ Sep 7, 2014 17:19 |
|
Can you post a code sample of what you are doing?
|
# ¿ Sep 8, 2014 16:58 |
|
What is the value of the parameters passed in? I'm guessing you are getting a negative number for Take/Skip. Also, have you tried doing a ToList() on the query to force the query to be executed earlier?gently caress them posted:Edit: Naturally if I just put my "make an empty string having object and return that thang" logic into the catch block of a try catch It Just Works! What? gariig fucked around with this message at 18:33 on Sep 8, 2014 |
# ¿ Sep 8, 2014 18:31 |
|
gently caress them posted:That if else statement? I made it a Try/Catch And Now It Just Works™. Is the Try/Catch working because you are catching the Exception and returning a good value or the Exception doesn't occur because of the try/catch? What part of it "And Now It Just Works™"? Well what are the values? Although that makes sense is that the root cause?
|
# ¿ Sep 8, 2014 18:41 |
|
Knyteguy posted:
What is happening is the Task you are creating from the Task.Factory is starting to run and you are immediately returning null. You need to capture the Task<T> created from the Task.Factory and await it. EDIT: That also means GetJsonValueFromServer should return a Task<JsonObject>. Once you go async/await it will spread through your code like a virus.
|
# ¿ Sep 9, 2014 19:24 |
|
Since so many people have asked about asynchronous and parallel programming this week I'll plug Concurrency in C# as a great book to go over modern (.NET 4+) concurrency techniques. It's in a cookbook style approach where each chapter has a theme (async/await, TPL, Rx) and a bunch of examples that build on each other. Excellent book.
|
# ¿ Sep 12, 2014 20:15 |
|
GrumpyDoctor posted:Was the old behavior originally intended, or was it a bug? That behavior seems incredibly counterintuitive to me, especially because, if I understand right, there's no way to explicitly request it anywhere in the language. C# code:
I'm glad Microsoft "fixed" this behavior to do what a normal human being would expect. Which is to have each Where clause capture the value of keyword by using the temporary variable. Also, I didn't realize multiple Where clauses were cumulative (is that the right term?). I learned something new. EDIT: VVVV It totally makes sense. I just never thought of it that way. At least Ithaqua didn't realize it. I take solace in that gariig fucked around with this message at 17:12 on Sep 16, 2014 |
# ¿ Sep 16, 2014 17:04 |
|
A Tartan Tory posted:Ah right, let me try again. No, I still don't understand what you are trying to do. Pretend I don't know what you are trying to calculate and describe the process. Also, add a couple of small examples of input and output. Maybe even the manual steps to get your input to be output
|
# ¿ Sep 18, 2014 00:54 |
|
You are (probably) overestimating how slow a database trip is. If this database is close to your web server (same host) you are looking at a couple of milliseconds per call. I would start with the database and then see what you need to do to optimize the process. I'm also unsure of what you mean you were "doing it badly"? Just appending everything with a StringBuilder sounds OK to me (until it's not)
|
# ¿ Oct 2, 2014 00:56 |
|
wwb posted:I'll just be contrarian here and note that while the concept of using a database makes a lot of sense you might not want an actual database server involved -- if it is just a key-value lookup then using a static Dictionary<string, GemInfo> isn't the most horrible thing in the world. Said "database" could be hydrated from an xml or json file which gets compiled in as a static resource. The key advantage here is that the app can travel with the data internally so you don't need to stand up the gem DB to do testing / developing. Downside is you've got a big object in memory but RAM is cheap these days. The biggest problem for Scaramouche is it the data isn't 100% static. Like if someone updates a description do you have to recycle the app pools to get Application_start to rehydrate your Dictionary? I would start with a database, it could even be a SQL Server Express hosted on the web server. A database is nice in that it gives you a point of integration. Later you might need to do allow updating of descriptions or adding new gems not in the original dump of data. If you are constantly hitting the database you don't need to worry about caching. Quite honestly, with a fairly low volume (like 8-17 items/second) there's not really a "bad choice". I doubt you could add measurable latency to your process when the whole thing takes 40 minutes. What's another 1-2 seconds in the pipeline? Really the whole process should probably take 10ms to lookup a database, transform the data into a description, and pass the work item and description to the next process.
|
# ¿ Oct 3, 2014 17:06 |
|
Have you tried the Import/Export data feature in SSMS or use SQL Server Integration Services? I'm not sure how much manipulation is required for moving the data from MySQL to SQL Server but either tool should be able to do it.
|
# ¿ Oct 4, 2014 06:33 |
|
How would a fake DbContext know that your relationship should fail? It's just going to let your code call into it, return pre-recorded behavior (Setup/Returns), and to allow you to Verify calls. If you want to test what happens when your code gives a bad relation you can have Moq throw an exception. What you want is an integration test where you aren't mocking your DbContext but using a MyContext against a real database. The Art of Unit Testing is a great book that goes over unit testing and touches on integration testing.
|
# ¿ Oct 7, 2014 20:46 |
|
RICHUNCLEPENNYBAGS posted:Do you? Frankly I think a mocked out DbContext is pretty useful in a lot of cases and with the integration test you run into consistency problems. It depends on what you want to test. I've honestly not done much EF. Can you mock a DbContext and still get information like invalid FK like Ochowie wanted? I'm too lazy to go look up the information. To your point about integration tests being hard. They are and might not be worth the effort. Depends on the code base
|
# ¿ Oct 8, 2014 20:16 |
|
Try updating your nuget packages. Microsoft pushed a new version of the MVC4 dll today that is breaking things. StackOverflow Microsoft bulletin EDIT: Rereading this probably won't help. However, this might be good information for other developers
|
# ¿ Oct 16, 2014 23:52 |
|
ljw1004 posted:We launched "VS2015 Preview" today: download Can I run this side-by-side with VS2013/2012 or should I stick it on a VM still? EDIT: I didn't read the KB article quote:Although this release is intended to be installed side-by-side with earlier versions of Visual Studio, complete compatibility is not guaranteed.
|
# ¿ Nov 12, 2014 17:31 |
|
With all of this unit testing talk if you want a book on it The Art of Unit Testing is excellent and I highly recommend it.
|
# ¿ Dec 16, 2014 18:55 |
|
mastersord posted:I noticed you create a new connection and other ADO objects every time you connect. I set up a connection pool (we have multiple databases) and reuse oledbconnection objects. I am not sure which is better, as I am in no way an expert in how ADO works. Don't do this. ADO.Net is already doing connection pooling. The only reason to do your own object pooling is if you are having trouble with GC and creating/destroying a new object is too expensive (generally not). A "General network error. Check your network documentation" is something of a legend. Every person who has solved this has a different way. I think Richard Campbell from .NET Rocks/Runas Radio once said it was a bad keystone jack. You can check out Polly about handling and retrying because of the transient error
|
# ¿ Jan 22, 2015 22:15 |
|
GrumpyDoctor posted:If I need to kick off a long-running, CPU-bound task and not care about the results, is just calling Task.Run(whatever) the right way to do it? Yes but don't have the implementation call Task.Run have the caller (here's why). Just remember you won't get any exception messages unless the code in the Task handles it. It's truly fire and forget if the task isn't awaited. If you are in ASP.NET you are sucking up a thread from your thread pool that is used to handle requests and IIS might shut down your app while it's running. You can use QueueBackgroundWorkItem to get around that or ship it off the box. gariig fucked around with this message at 22:05 on Jan 23, 2015 |
# ¿ Jan 23, 2015 21:25 |
|
Newf posted:Can anyone here tell me about discount options for hosting an extremely low traffic MVC site with a very small database? I'm looking to make a quick and dirty attendance/merit tracking webapp for someone managing the homework room of a Boys and Girls Club, but the local network isn't accessible for me to host the thing due to national Boys and Girls club bureaucracy which I'd rather sidestep. If you are in school you can do Dreamspark (or Githubs pack which includes Dreamspark) or BizSpark. I'm pretty sure BizSpark has very little requirements to join, I think you just need to sign up.
|
# ¿ Jan 28, 2015 15:49 |
|
Easy Mac posted:So this system worked because I didn't have to resize images all the time for specific parts of the website. However, it is kind of slow sometimes, especially for the first time it pulls the images from the database. So what I'd like to know is, how would you handle images? If storage isn't a problem I would put them into a queue and have some other process resize them and store them into the database. That way when the user goes to access the product the image is already resized. The queue is used so that you can have multiple workers resizing images in case volume increases. It's slightly YAGNI but I think the extra effort up front is worth it even if you keep it at one worker.
|
# ¿ Jan 29, 2015 21:58 |
|
Space Whale posted:Also, in general, how much of a PITA is it to finally whip a solution into building properly and using NuGet correctly? Not that bad. If you have Resharper if you right click on the reference and pick Project Hierarchy it will show you all of the projects referencing the assembly. You can then right click on the solution, manage Nuget packages for solution, and add the package to your projects. I recheck the references to make sure they are correct because I've had Nuget not do the right thing. If your build system doesn't restore nuget packages automatically you'll have to check nuget.org for instructions. For internal assemblies you can run your own nuget server if needed. I'm literally in the process of doing this at work for some of our external dependencies. Someone added a new project with log4net through Nuget, but other projects had references to the assembly in a lib folder. Everything compiled but programs crashed, very annoying.
|
# ¿ Feb 10, 2015 18:13 |
|
GrumpyDoctor posted:Ok, I guess I should provide the entire problem description so I'm not X/Ying this. It's kind of gnarly to explain, though. I was trying to originally only ask about one piece of it, but I guess I should put it all on the table. I don't understand where the ConcurrentDictionary comes into play. I would do some sort of Producer-Consumer model (basically use queues). Where one part of the pipeline is sticking in data and the next part is doing work on it to push it into the next part. How to implement this depends on how much parallelization you need. Do you need cores on a machine or 50 machines? You could look into MSMQ or another message queue system for coordination across process boundaries. You can use a disk as transactional storage but it's definitely a tough problem. You have to make sure files are written completely or you'll get locking issues. I would look into something else to coordinate between steps 2 and 3 (could be queues again that handles the transaction, IE write to file then insert work into queue)
|
# ¿ Feb 13, 2015 16:50 |
|
GrumpyDoctor posted:I've got a desktop application that runs through a loop in which each loop iteration creates a directory, uses it for some scratch work, and then deletes it. On some loop iterations the call to Directory.CreateDirectory fails with an UnauthorizedAccessException, but this makes no sense to me, because the directory name doesn't change, and nothing else uses it. (I know that nothing uses it because it's a temp directory.) What could be going on here? Can you post some code? Could be a logic error in the code. If it's a transient error you could use something like Polly to retry. EDIT: Anyone here use OzCode? I'm wondering if it's worth the cash
|
# ¿ Feb 25, 2015 19:04 |
|
bobua posted:If you have the property set to nullable, yes. Properties like datetime can't be set to nullable though. Can you stop using DataTable? It's a very leak abstraction and I think you are having trouble because you are using three different technologies, DataTable, EF, and LINQ-to-objects. My suggestion is to make a POCO (Plain Old CLR Object) model, have each step project the data into your POCO model, do your model mutations, then project that into the database. At the very least dumping DataTable will probably help out. Also, posting more code could be helpful but I think is more of an architecture problem than a coding error problem. You could also move to something like SSIS (SQL Server Integration Services) or some other ETL (Extract, Transform, Load) system.
|
# ¿ Mar 3, 2015 15:56 |
|
crashdome posted:App.Config question: Building doesn't merge the app.configs. However, you can have one app.config reference an external file (example).
|
# ¿ Mar 4, 2015 02:19 |
|
I'd probably post it to StackOverflow and hope Jon Skeet answers it. You can also check out Nodatime (from Jon Skeet)
|
# ¿ Mar 5, 2015 01:01 |
|
enthe0s posted:I'm using DateTime to get the day of the month as a number, but I haven't been able to find a good way to format the day with suffixes. For instance, if the date is 5, I want to format the string to output "5th", 1 becomes "1st", etc. Use Humanizr (pulled from The Hanselman)
|
# ¿ Mar 11, 2015 22:01 |
|
Boz0r posted:Yeah. I know C# too from programming in Unity3D. I'm just got my master's in computer science, so I'm into all that OOP and poo poo, so I just need a quick and dirty version, I think. If you know programming but want to learn what makes C# standout I suggest C# In Depth. It goes over all of the changes in .NET 2/3/4/4.5 (generics, LINQ, async/await) which is what makes .NET standout from Java/C++. It also goes into a lot of the things that can be odd unless someone told out like LINQ being lazy evaluated. As far as learning WinForms, WCF, WebForms, MVC, Web API, etc. you are screwed but the employer knows that. Also, the Microsoft Virtual Academy has some hit or miss classes. I wouldn't dismiss all of them if you didn't like the one you saw.
|
# ¿ Mar 13, 2015 17:11 |
|
Calidus posted:I have a MVC webpage which is used to add items to an order. Think of it like a stupid version of those design your own car webpages every manufacture has now. It has 3 sections, the first section is html form with some inputs used to select and add an single item to the order. The second section is a preview image rendered by the server based on uses current order. The third section is a second html form which is used to remove a previously added part from the order. This is clunky as hell with two different html forms being posted. No one really answered you but I would go with a SPA (Single Page App) approach. I think that's the kind of UI that users are expecting today. Post backs work best as a work flow (view -> edit -> view update) but this sounds like a very iterative approach on this page. If you are able I would go with a more traditional SPA approach of using DOM manipulation on the front end and sending JSON to the server. The Ajax partial stuff doesn't seem to be in vogue at Microsoft so could be dropped in a version or two (pure speculation).
|
# ¿ Mar 18, 2015 20:04 |
|
I found this http://forums.iis.net/post/1992357.aspx which sounds like what you wanted
|
# ¿ Apr 1, 2015 18:06 |
|
Scaramouche posted:Then I parse them, and move them to here: I wouldn't worry about the File.Exists taking too long. It's going to just ask the file system if the file exists or not. If you want to test this just make a bunch of fake "invoices" (like 100,000) and see what happens. I think you should save this in a database so there is some history the work was done.
|
# ¿ Apr 2, 2015 19:03 |
|
Brady posted:Yeah I tried the multi-threading thing and didn't really know what I was doing so I abandoned that route. I want to make a button that, when clicked, will pause the operation after the current block has been executed, and not pause it in the middle of the loop, so I don't think the mutli-threaded thing would suit me anyway. Basically I'm just relocating files from one server to another and renaming them along the way and I want the user to be able to pause at their leisure, but only after the current file rename is completed to avoid any issues. I'm checking out Await but I'm lost when it comes to attaching it to a button click, especially since the UI is locked during execution... which in that case, is making the application double-threaded is the only way to go then? I know this is what ASync is for kind of but I can't find any example online that actually uses Await to pause anything completely until the button is clicked again, but instead all I can find are examples of a wait timer. All code in .NET is executed on a thread. When you are in a GUI by default everything runs on the UI thread. The UI thread is what is responsible for listening to UI events (button click, window drag/drop) and coordinating repaints of the UI. Since it's handling button clicks if you don't move long running work to another thread it will consume all of CPU time of the UI thread and the UI thread can't listen to UI events and schedule repaints. If you want to do long running work and have a responsive UI you need to do the work on another thread. The best options right now are BackgroundWorker, Task Parallel Library (using Task.Run, or async/await if the library exposes Async (Task returning) methods like HttpClient. Those options are from worst to best. Allowing the user to stop the action requires the programmer to allow it without the user killing the Process. This is a more advanced scenario that requires use of a CancellationToken. I found a Console application example. The same process will apply to the UI. I would have Start and Cancel buttons. When you Start create a CancellationToken and pass it into your long running job that is probably spawned from Task.Run. Now the Cancel button is clickable and will cancel the CancellationToken. You can control when the CancellationToken is observed in your long running process and stop when you finish a unit of work. Combine this with ljw1004 IProgress example and you have an awesome application! If you want to learn more about writing concurrent programming I suggest Concurrency in C# Cookbook. It skips Threads which you should 99.99% never use if you are in .NET 4+ but goes into everything I mentioned above plus Reactive Extensions. gariig fucked around with this message at 15:41 on Apr 14, 2015 |
# ¿ Apr 14, 2015 15:39 |
|
A read through the Roslyn Contribution Guide might help some. A lot of this stuff will make your code harder to read. There's also LinqOptimizer which will compile your LINQ queries down to IL. I have not used LinqOptimizer but I think someone on SA had
|
# ¿ Apr 17, 2015 22:06 |
|
Can you post more code? I'm still not sure what is going on. You saying "multicast delegate holding 2 old filewriter's and the one current one" has me worried. A Bitmap is not very threadsafe (SO) and it's possible you are getting into a dead lock. For the code Ithaqua mentioned having unbraced loops and if statements can be a "bad" thing (see goto fail SSL exploit). I would at least change it to a LINQ statement so that it's more declarative. Really, I would have the constructor find the ImageCodecInfo and cache it or wrap it in a Lazy<T>. Just to reduce the amount of work needed when saving a JPEG and it's one less call within saveJpeg plus null checking. I would also want to throw an exception if no ImageCodecInfo is found instead of silently giving up or at least log it.
|
# ¿ Apr 21, 2015 17:06 |
|
|
# ¿ May 7, 2024 01:04 |
|
bobua posted:Sorry, I meant more from a best practices\what are the pitfalls point of view. The pitfall is you are munging your business logic and data access into one spot. There's no separation of concern so testing this without firing up a database impossible. For a small application creating your DbContext in the constructor or injected in via IoC isn't that bad.
|
# ¿ Apr 25, 2015 00:24 |