.status-msg-wrap { display: none; }
Thursday, May 31, 2018
no image

C# method runs in Visual Studio; crashes in Code Wars

I wrote a C# method to solve this Code Wars problem:

Write a method for strings. All words must have their first letter capitalized without spaces. For instance: camelCase("hello head case") => "HelloHeadCase" camelCase(" camel case word") => "CamelCaseWord" 

My code works correctly in Visual Studio; however, when I run it in Code Wars, it throws an IndexOutOfRangeException. I'm thinking the problems must be how the web site handles loops but otherwise I'm baffled.

C# method runs in Visual Studio; crashes in Code Wars Click here
no image

Where to log in ASP.NET Core?

In the interest of performance, what's the best place to log errors at? For example, I could log a sql error in the controller, the repository, or lower if I had more depth. I am thinking it's best to log at the highest level, but I'm not sure. Let me know your thoughts. Thanks!

Where to log in ASP.NET Core? Click here
no image

(x-post /r/AskProgramming ) Design help for new app

I'm trying to come up with the best way to do this. I'm designing an app (the idea is .NET Core for the back and Quasar for the front, btw) that'll be used to organize workout programs. The model goes like this:

Each PROGRAM consists of one or more WORKOUTS -> for example, a month long program with weekly workouts on MON, WED, FRI will consist of 3 x 4 = 12 workouts

Each WORKOUT consist of one or more SETS, given a SET as the smallest unit of work possible in a WORKOUT -> for example, if WORKOUT A has you do 3 sets of 10 repetitions of squats, that would mean that you'd have 3 SETS, each pointing to (FK) WORKOUT = A, (FK) EXERCISE = Squat, REPS = 10

It'll get a bit more complicated than this, but this should suffice to understand the issue I'm having in my head right now. Users should be able to not only download other users uploaded programs, but upload their own too. Thing is, users should also be able to MODIFY programs they've downloaded as they see fit, and this WILL happen pretty consistely. For example, let's say that you found a program that you really love but you can't do one specific exercise in a specific workout... you'll just download that program, edit it, and substitute that exercise in that workout for a different one that you can actually do. Question is, how do you deal with this without duplicating a whole lot of data in your DB?

These are the options I can think of:

  • Duplicate everything. As soon as you download a program from the "program store", that'll create a new record in the PROGRAM table... and a record for each workout in that program in the WORKOUT table, together with a SET record for each set in each workout... basically, duplicating a shit load of info right away after you download a program. If you download 10, that's a lot of data you're saving to the DB each time. Of course, this method gets rid of any complacations regarding updates in the programs, as if you change anything in any program you've downloaded, you'll just update the records you created when you downloaded it and not the original.

  • Only keep in the DB common info for every user (uploaded programs, users, master tables such as EXERCISE, etc), and for absolutely everything else keep a "local" database or maybe a JSON with every single piece of data / info a user can need, including every program they download and any changes they make to it.

Any opinions? I'm sure there's gotta be an "optimal" way of doing this without over complicating things too much.

(x-post /r/AskProgramming ) Design help for new app Click here
no image

Can I combine ASP.Net Core MVC with Angular?

Does anyone know any good resources for sending back angular templates through MVC, or if this is even possible? Can I make sure of ViewComponents and partial views with angular? Sending back full angular templates seems like it should be possible but are there big complications when trying to use partial views? I would have thought there would be issues with the compiler and errors showing through intellisense but I've never tried this, nor how to implement it properly.

Any advice is appreciated!

Can I combine ASP.Net Core MVC with Angular? Click here
no image

ASP.NET Core SignalR compatible with .NET Framework?

I've seen a lot of mention around the net about a lot of .NET Core targeting .NET Standard 1.6/2.0. With the release of .NET Core 2.1 today I'm curious what I would actually be able to get away with running on, let's say, a .NET Framework 4.7 website or application. How do I know what can and can't be used? I'm namely interested in knowing whether I'll ever be able to use the new SignalR in my existing WebAPI projects or if I'll have to completely transition over to Core to have any part in it.

ASP.NET Core SignalR compatible with .NET Framework? Click here
Wednesday, May 30, 2018
no image

What are some good tutorials for a newbie to learn ASP.NET

I'm mostly a JS guy which have experience in (undergraduate, but doing my side projects and learning) JS, React, Node mainly. So I have basic understanding on OOP which I can get things done.

I need suggestions on some good tutorial/tutorials to follow on ASP.NET MVC + Entity Framework and stuff. I got pluralsight 3 months subscription. I started a tutorial series in pluralsight called ASP.NET MVC5 Fundamentals , but the tutor saying that it's for people who already had worked with ASP.NET (as what he's doing is only covering the new stuff on MVC5) . So it's not working for me. Can anyone suggest me a good tutorial to follow from scratch. I prefer project based tutorials ?

Thanks in advance.

What are some good tutorials for a newbie to learn ASP.NET Click here
no image

.NET Framework or .NET Core for a newcomer

I used to develop with Classic ASP back in the day. I always intended to get into .NET but a career change made it no longer necessary and a lack of time meant I never got around to learning.

Over the years I've still used Classic ASP to knock up productivity tools for myself and I still maintain an application for a friend's business. Rather embarrassing using such dated tech from my point of view but from the user perspective it works well and you wouldn't even know the back end was coded with tech your grandfather used to use.

I've had a couple of projects knocking around in my head for a while and a bit more time now so I'd like to finally take the plunge and jump into .NET. Given my background with VBScript I'd like to go with VB to keep some familiarity as the seeming necessity to use C# early on was one of the things that put me off learning.

My question is if you were starting from my position now would you go with .NET Framework or .NET Core?

My gut instinct is telling me to go with Framework, fully mature with plenty of documentation, third party support and help out there. Framework seemed to change so much from early versions I'm worried about the same happening with Core, where I might as well just wait until Microsoft decide where they want to take it before I make the switch.

The other party of me worries that with Framework I'll be learning tech that's already getting on in years and it won't be long until I'm in the position I'm in now using outdated tools. Looking around opinion seems to be divided on the remaining lifespan of Framework.

Any opinions or advice would be greatly appreciated!

.NET Framework or .NET Core for a newcomer Click here
Tuesday, May 29, 2018
no image

CQRS + DDD for .NET Standard (C#)

I have created a set of lightweight and easy-to-use libraries that aims to help in building applications that are grounded upon the CQRS and DDD patterns.

The libraries are open source and are under MIT license. Anyone is free to contribute! Please feel free to send me a message. :)

Email: joeljeremy.marquez@gmail.com.

Slack: https://xerprojects.slack.com

GitHub Organization: https://github.com/XerProjects

Superset of other smaller CQRS and DDD libraries: https://github.com/XerProjects/Xer.Cqrs

CQRS libraries: https://github.com/XerProjects/Xer.Cqrs.CommandStack https://github.com/XerProjects/Xer.Cqrs.EventStack https://github.com/XerProjects/Xer.Cqrs.QueryStack

DDD library: https://github.com/XerProjects/Xer.DomainDriven

CQRS + DDD for .NET Standard (C#) Click here
Monday, May 28, 2018
no image

Binding to Run.TextProperty goes back to old value after the Text has been changed, then completely breaks

I am trying to create a RichTextBox with a Run object inside that has it's Text property bound to a string property in my custom-made object. Here's how I create the binding:

 Paragraph paragraph = new Paragraph(); Run run = new Run(); Binding bodyBinding = new Binding("Body"); PresentationTraceSources.SetTraceLevel(bodyBinding, PresentationTraceLevel.High); bodyBinding.Source = OpenedFiles[index]; bodyBinding.Mode = BindingMode.TwoWay; bodyBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; run.SetBinding(Run.TextProperty, bodyBinding); paragraph.Inlines.Add(run); FlowDocument flowDocument = new FlowDocument(paragraph); RichTextBox rtb = new RichTextBox(flowDocument); 

This is the debugging info when creating the binding:

System.Windows.Data Warning: 56 : Created BindingExpression (hash=27037160) for Binding (hash=32830290) System.Windows.Data Warning: 58 : Path: 'Body' System.Windows.Data Warning: 62 : BindingExpression (hash=27037160): Attach to System.Windows.Documents.Run.Text (hash=42007851) System.Windows.Data Warning: 67 : BindingExpression (hash=27037160): Resolving source System.Windows.Data Warning: 70 : BindingExpression (hash=27037160): Found data context element: <null> (OK) System.Windows.Data Warning: 78 : BindingExpression (hash=27037160): Activate with root item OpenedFile (hash=42526340) System.Windows.Data Warning: 108 : BindingExpression (hash=27037160): At level 0 - for OpenedFile.Body found accessor RuntimePropertyInfo(Body) System.Windows.Data Warning: 104 : BindingExpression (hash=27037160): Replace item at level 0 with OpenedFile (hash=42526340), using accessor RuntimePropertyInfo(Body) System.Windows.Data Warning: 101 : BindingExpression (hash=27037160): GetValue at level 0 from OpenedFile (hash=42526340) using RuntimePropertyInfo(Body): 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 80 : BindingExpression (hash=27037160): TransferValue - got raw value 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 89 : BindingExpression (hash=27037160): TransferValue - using final value 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' 

And this is how the OpenedFile class looks like:

public class OpenedFile : INotifyPropertyChanged { //Implementation of INotifyPropertyChanged interface public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } private string _name; private string _body; private string _prevbody; private string _path; private bool _modified; public string Name { get { return _name; } set { _name = value; NotifyPropertyChanged();} } public string Body { get { return _body; } set { _body = value; NotifyPropertyChanged(); } } public string Path { get { return _path; } set { _path = value; NotifyPropertyChanged();} } public bool Modified { get { return _modified; } set { _modified = value; NotifyPropertyChanged(); } } public OpenedFile(string name, string body, string path) { Name = name; Body = body; Path = path; Modified = false; } public OpenedFile() { Name = "New File"; Body = ""; Path = ""; Modified = true; } } 

This binding works at first (the RichTextBox displays the correct file's contents when it is created), but as soon as I type something into the RichTextBox, it gives me following info (in this example, I typed 'x' at the end of the RichTextBox):

System.Windows.Data Warning: 90 : BindingExpression (hash=27037160): Update - got raw value 'nikjodfewsanioudawnuidwanuidwniuainudwsodfx' System.Windows.Data Warning: 94 : BindingExpression (hash=27037160): Update - using final value 'nikjodfewsanioudawnuidwanuidwniuainudwsodfx' System.Windows.Data Warning: 102 : BindingExpression (hash=27037160): SetValue at level 0 to OpenedFile (hash=42526340) using RuntimePropertyInfo(Body): 'nikjodfewsanioudawnuidwanuidwniuainudwsodfx' System.Windows.Data Warning: 95 : BindingExpression (hash=27037160): Got PropertyChanged event from OpenedFile (hash=42526340) System.Windows.Data Warning: 101 : BindingExpression (hash=27037160): GetValue at level 0 from OpenedFile (hash=42526340) using RuntimePropertyInfo(Body): 'nikjodfewsanioudawnuidwanuidwniuainudwsodfx' System.Windows.Data Warning: 80 : BindingExpression (hash=27037160): TransferValue - got raw value 'nikjodfewsanioudawnuidwanuidwniuainudwsodfx' System.Windows.Data Warning: 89 : BindingExpression (hash=27037160): TransferValue - using final value 'nikjodfewsanioudawnuidwanuidwniuainudwsodfx' System.Windows.Data Warning: 90 : BindingExpression (hash=27037160): Update - got raw value 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 94 : BindingExpression (hash=27037160): Update - using final value 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 102 : BindingExpression (hash=27037160): SetValue at level 0 to OpenedFile (hash=42526340) using RuntimePropertyInfo(Body): 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 95 : BindingExpression (hash=27037160): Got PropertyChanged event from OpenedFile (hash=42526340) System.Windows.Data Warning: 101 : BindingExpression (hash=27037160): GetValue at level 0 from OpenedFile (hash=42526340) using RuntimePropertyInfo(Body): 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 80 : BindingExpression (hash=27037160): TransferValue - got raw value 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' System.Windows.Data Warning: 89 : BindingExpression (hash=27037160): TransferValue - using final value 'nikjodfewsanioudawnuidwanuidwniuainudwsodf' 

So, it first correctly catches the change and updates it, but then reverts it back to the old value. Moreover, after that happens, the Binding completely breaks - it doesn't update on any text input, but it also doesn't display any info in debugging.

Does anyone know how to fix it? Please, I'm desperate at this point, I've been trying to debug it for hours. I tried removing the INotifyPropertyChanged implementation from OpenedFile class and setting the binding to a different mode.

Binding to Run.TextProperty goes back to old value after the Text has been changed, then completely breaks Click here
no image

VS 2017 Extension to Refresh browser when CSS file or HTML content changes?

Hi, I usually use Brackets to do front-end development work but it's more convient to use VS 2017 to be able to use tag helpers and all the other features. Does VS 2017 have an extension, or in-built setting, to refresh the web browser when I alter and save the CSS file, or even just the HTML file like Brackets does?

VS 2017 Extension to Refresh browser when CSS file or HTML content changes? Click here
Sunday, May 27, 2018
no image

Auth for users with Asp.Net Identity and WebAPI

I want to create a SPA, and also mobile apps with a .net core backend...

I want authentication and authorization in my backend, but not sure what to do. There seems like lots of different options, and its all a bit confusing.

From my reading I think Asp.net Identity is needed for storing user details/roles etc... But as it is using API's will need JWT authentication rather than cookie based?...

I am planning on using asp.net core...

Any guidance on how to authenticate and authorize users for this scenario (SPA, mobile apps) appreciated

Auth for users with Asp.Net Identity and WebAPI Click here
no image

preparing for interviews: how do I approach design patterns?

I'm self-taught and preparing for interviews. My primary focus is to study/learn data structures and algorithms since they seem standard for most programming interviews. I'm pretty comfortable with C#/.NET "trivia" questions, and also javascript and sql.

What types of design pattern questions are typically asked? Are the questions mostly discussion-oriented or are interviewees expected to code and/or draw the UML diagrams?

My approach right now is to focus on the ones that I can easily identify and/or have used. This boils down to the factory, singleton, decorator, mediator, iterator, observer, and a few others. So maybe one-half of the original GOF plus a few widely-used non-GOF patterns (repository, dependency injection, MVC, etc.)

preparing for interviews: how do I approach design patterns? Click here
no image

A proper way to use HttpClient

Hello, I am building a little project of mine to scrape website that's built on JSF viewstates and scraping single information requires about 6 requests for that reason (If I understand it correctly). If the whole program runs on a single thread it runs abruptly long and stalls for quite some time after let's say 20 requests, If I do it multithreaded it's not working. I am currently trying to debug it but when I was wandering through the internet I found two approaches of how to use the HttpClient in a proper that are totally different.

Here is the first one: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

Second one: https://www.codeproject.com/Articles/1194406/Using-HttpClient-as-it-was-intended-because-you-re

Basically, do you dispose HttpClient after each request or not? If I do understand it correctly, in my case it would be better to keep one instance of HttpClient per thread?

A proper way to use HttpClient Click here
no image

ASP.NET Website VS Web App

Is the difference between asp.net website and asp.net web application is that web app is based on web api or MVC 5 so it can actually make one request per page, and website can contain several forms? And can I implement a website (or a site with several forms on a page) in a .net core?

ASP.NET Website VS Web App Click here
no image

EntityFramework 6 + SQL View DML Triggers

I have a number of SQL views with triggers on them to write to the underlying tables. I was running into all sorts of EntityFramework runtime errors until I manually edited the .edmx to redefine the views as tables. Full details here.

This is messy and I'll never be able to auto-update these models without having to re-apply this hack. Does anyone have a better solution?

EntityFramework 6 + SQL View DML Triggers Click here
no image

DevExpress subscription discount

So I recently won up to 999$ in DevExpress subscriptions but I have no use for this. All my software is decided and paid for by my bosses. So I was wondering if anyone would be interested in getting a discount on DevExpress products.

DevExpress subscription discount Click here
no image

Theming Razor Pages in DNC2.1

I'm trying to create a mutitenant themeable site using the new Razor Pages in dotnet core 2.1. I have the middleware to identify tenant and set the tenant theme in the context based on host, so that on each request I can extract the information for the tenant.

I have all the default pages under /Pages but also another folder /Themes which is also top level.

I have created a view location expander which sets the view locations to /Themes/{theme name}/{1}/{0}.cshtml but it doesn't load the page.

It does work however for the shared layout page under /Themes/{theme_name}/shared/_Layout.cshtml

Anyone have any idea why it will load shared pages but not anything else?

Theming Razor Pages in DNC2.1 Click here
Saturday, May 26, 2018
no image

Companies that focus on F# development?

Aside from Microsoft itself, I only know of an oil company called Tachyus that heavily focus on F# development.

Curious to know if you're aware of any others?

Companies that focus on F# development? Click here
no image

Looking for advice on how best to prepare for a new job.

Previous work includes a set of ASP.NET Core 2.0 API services comprised of authentication and a few business services that serve a JS app. Within the scope of that project I was the lead back end guy, and authored most of the service layer and the database schema myself.

I'm starting up a job as a senior back-end .NET developer and will primarily be working on an as-of-now non-existent mesh of services that will consume APIs, transform and store data, and serve a front end.

I am wondering if anyone here has recommendations other than C# In Depth for firming up weak areas, as well as any that focus on domain driven design and distributed microservices (think Docker swarm or Kubernetes). I love reading and following others' code online, and am open to any and all suggestions you might have.

Looking for advice on how best to prepare for a new job. Click here
no image

Where is NET Standard 2.1 after installing 2.1 SDK?

So I installed .NET 2.1.300-rc1. I can now build projects that target netcoreapp2.1 but changing the .csproj's <TargetFramework>netstandard2.0</TargetFramework> to have netstandard2.1 gives the following error ...

The current .NET SDK does not support targeting .NET Standard 2.1. Either target .NET Standard 2.0 or lower, or use a version of the .NET SDK that supports .NET Standard 2.1. C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets

Please MSFT ... don’t make net core, net standard and net framework versioning more complex than it needs to be.

Where is NET Standard 2.1 after installing 2.1 SDK? Click here
no image

SignalR Core Microsoft tutorial not working for me

The tutorial here says it was created/updated 4 days ago. I'm having trouble executing it.

https://docs.microsoft.com/en-us/aspnet/core/signalr/get-started?view=aspnetcore-2.1&tabs=visual-studio

The error I get is that the line that initializes SignalR on the client side gets an error that "The 'protocol' argument is required.

const connection = new signalR.HubConnection("/chathub", { logger: signalR.LogLevel.Information });

I tried adding a variable inside the second parameter

transport: signalR.TransportType.WebSocket

But it says signalR.TransportType is undefined. I can't find any other suggestions on how to fix this.

https://imgur.com/a/BSnkG0m

The only other warning I get is from NPM when installing the signalr client files.

PM> npm install @aspnet/signalr + @aspnet/signalr@1.0.0-rc1-update1 updated 1 package in 1.161s npm : npm WARN Projects@1.0.0 No description At line:1 char:1 + npm install @aspnet/signalr + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (npm WARN Projects@1.0.0 No description:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError

npm WARN Projects@1.0.0 No repository field.

SignalR Core Microsoft tutorial not working for me Click here
no image

Why alternative languages for .NET died out?

There were a lot of cool languages, that were compiling to MSIL back then like Cobra, Boo, Nemerle, IronPython, IronRuby and etc. But all of them are barely supported these days. Only C#, VB.NET and F# seems to be alive. What happened to all those cool languages?

Why alternative languages for .NET died out? Click here
Friday, May 25, 2018
no image

Upgrading from webforms, how can I accomplish this in MVC using Dapper?

I have an old webforms site that it just reading data from couple of databases. I have many queries and a function the the gets the DB data.

I have this function that returns a datatable with the data based on passed query and parameteres.

 public static DataTable ExeConnectds(string command_text, string connstring, params OracleParameter[] parameters) { DataTable tmp = new DataTable(); using (var ORAconnection = new OracleConnection(ConfigurationManager.ConnectionStrings(connstring).ConnectionString)) { using (var ORAcommand = new OracleCommand(command_text, ORAconnection)) { if (parameters != null && parameters.Length > 0) { foreach (var p in parameters) ORAcommand.Parameters.Add(p.ParameterName, p.OracleDbType, p.Size).Value = p.Value; } ORAcommand.Connection = ORAconnection; ORAconnection.Open(); tmp.Load(ORAcommand.ExecuteReader()); } } return tmp; 

}'

Basically I can call this function from any page.

I've been working with Dapper and MVC and looks like I need to create a model/type for each query?

is there a way with dapper to create generic queries and pass generic parameters like in the webforms example above?

Upgrading from webforms, how can I accomplish this in MVC using Dapper? Click here
no image

[WPF] How to populate a Richtextbox with a content of a file in a nice way?

I have a following problem:

I have a TabControl with it's ItemsSource set to a Binding with an ObservableCollection object. Inside the Content property of TabControl I put a RichTextBox, to which I want to load a text file. Here is the XAML snippet:

 <TabControl Grid.Column="0" x:Name="openFiles" ItemsSource="{Binding OpenedFiles}"> <TabControl.ItemTemplate> <!-- this is the header template--> <DataTemplate> <TextBlock Text="{Binding name}" /> </DataTemplate> </TabControl.ItemTemplate> <TabControl.ContentTemplate> <!-- this is the body of the TabItem template--> <DataTemplate> <RichTextBox x:Name="fileTextBox"/> </DataTemplate> </TabControl.ContentTemplate> </TabControl> 

With each new file, I want to be able to load the contents of the file to the RichTextBox using TextRange and FileStream objects like so:

if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK ) { TextRange range; System.IO.FileStream fStream; if (System.IO.File.Exists(openFile1.FileName)) { range = new TextRange(RichTextBox1.Document.ContentStart, RichTextBox1.Document.ContentEnd); fStream = new System.IO.FileStream(openFile1.FileName, System.IO.FileMode.OpenOrCreate); range.Load(fStream, System.Windows.DataFormats.Rtf ); fStream.Close(); } } 

However, I don't know how to reference the RichTextBox in the ContentTemplate from code-behind level.

OpenedFiles is an ObservableColletion<OpenFile> object, where OpenFile is a class that contains the files' path, stream etc.

I kinda figured out a workaround. I created a MyTabItem class that derives from standard TabItem. This class puts a RichTextBox as it's Content in the constructor, so that I can populate it in code-behind. But I don't like that solution. I think it's ugly and there must be a better way. Sorry if that's a noob question - I am just learning this for my uni course and want to learn good practices, not flaky workarounds.

[WPF] How to populate a Richtextbox with a content of a file in a nice way? Click here
no image

Powershell WPF Application

I have a xaml UI which in background does some powershell operations. I am just starting to do this, but i am not able to run the application with the default template itself. It runs in IE(Windows Presentation Host) by default, and throws this error. Please Help.

Startup URI: C:\Users\BizTalk360\source\repos\PowershellApplication\PowerShellProject1\WpfWindow1.xaml Application Identity: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 

https://i.redd.it/emc8zqu2myz01.jpg

https://i.redd.it/skaf7vi3myz01.jpg

Powershell WPF Application Click here
The webdev Team