Is this the right usage of using?

Issue I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> DeleteClub_IsOpening([FromRoute] string ClubId) { using (_db_ClubIsOpen) { var result = _db_ClubIsOpen.ClubIsOpen_TBL.Where(x => x.FK_Club == ClubId); foreach (var item

Continue reading

Is this the right usage of using?

Issue I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> DeleteClub_IsOpening([FromRoute] string ClubId) { using (_db_ClubIsOpen) { var result = _db_ClubIsOpen.ClubIsOpen_TBL.Where(x => x.FK_Club == ClubId); foreach (var item

Continue reading

Is this the right usage of using?

Issue I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> DeleteClub_IsOpening([FromRoute] string ClubId) { using (_db_ClubIsOpen) { var result = _db_ClubIsOpen.ClubIsOpen_TBL.Where(x => x.FK_Club == ClubId); foreach (var item

Continue reading

Is this the right usage of using?

Issue I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> DeleteClub_IsOpening([FromRoute] string ClubId) { using (_db_ClubIsOpen) { var result = _db_ClubIsOpen.ClubIsOpen_TBL.Where(x => x.FK_Club == ClubId); foreach (var item

Continue reading

Is this the right usage of using?

Issue I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> DeleteClub_IsOpening([FromRoute] string ClubId) { using (_db_ClubIsOpen) { var result = _db_ClubIsOpen.ClubIsOpen_TBL.Where(x => x.FK_Club == ClubId); foreach (var item

Continue reading

Is this the right usage of using?

Issue I am not sure how to use using statement correct. I try like this: [HttpDelete("{ClubId}", Name = "DeleteOpenings_Club")] public async Task<IActionResult> DeleteClub_IsOpening([FromRoute] string ClubId) { using (_db_ClubIsOpen) { var result = _db_ClubIsOpen.ClubIsOpen_TBL.Where(x => x.FK_Club == ClubId); foreach (var item

Continue reading

Using a returned instance?

Issue I have a hierarchy of classes that perform API requests. In the base class, I build the request object, and in some subclasses, this method is overridden. Base class: protected virtual HttpRequestMessage BuildRequest(HttpMethod method, Uri uri, HttpContent content =

Continue reading

XamlParseException: Could not load file or assembly 'ResourceLibrary, …' or one of its dependencies. The system cannot find the file specified

Issue System.Windows.Markup.XamlParseExceptionoccurred A first chance exception of type ‘System.Windows.Markup.XamlParseException’ occurred in PresentationFramework.dll Additional information: ‘Set property ‘System.Windows.ResourceDictionary.Source’ threw an exception.’ Line number ’21’ and line position ‘6’. “Could not load file or assembly ‘ResourceLibrary, Culture=neutral’ or one of its dependencies.

Continue reading

C# 8 understanding await using syntax

Issue I have next method: public async Task<IEnumerable<Quote>> GetQuotesAsync() { using var connection = new SqlConnection(_connectionString); var allQuotes = await connection.QueryAsync<Quote>(@”SELECT [Symbol], [Bid], [Ask], [Digits] FROM [QuoteEngine].[RealtimeData]”); return allQuotes; } Everything fine and clear, connection will be disposed at the

Continue reading

'ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.' – C#

Issue The code: private void btnSave_Click(object sender, EventArgs e) { using (con = new SqlConnection(connectionString)) { SqlCommand cmd; switch (action) { case ‘a’: cmd = new SqlCommand("INSERT INTO tbl_User (userName, userPass) Values (@username, @userpass)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@username", txtUN.Text.Trim());

Continue reading

How to naming namespaces for product that have sub-products/modules?

Issue I read that carefully. And yes very helpful! https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-namespaces Assuming you have following products and namespaces Microsoft.Dynamics.Inventory is a DLL Microsoft.Dynamics.Bank is a DLL Each of above have (Views, Reports, Utils, etc) Microsoft.Dynamics.Inventory.DLL Should I go for that? Microsoft.Dynamics.Inventory.Sales.Reports

Continue reading

Does a C# using statement perform try/finally?

Issue Suppose that I have the following code: private void UpdateDB(QuoteDataSet dataSet, Strint tableName) { using(SQLiteConnection conn = new SQLiteConnection(_connectionString)) { conn.Open(); using (SQLiteTransaction transaction = conn.BeginTransaction()) { using (SQLiteCommand cmd = new SQLiteCommand(“SELECT * FROM ” + tableName, conn))

Continue reading

C# – getting out of using with return doesnt work

Issue This method works: HttpResponseMessage responseMessage = await GetResponseMessage(pathWithParams: $"https://api.webasd.com/crm/v3565/objects/contacts?&limit=100&after={afterValue}&archived=false"); private Task<HttpResponseMessage> GetResponseMessage(string pathWithParams = null, HttpRequestMessage requestMessage = null) { var httpClient = new HttpClient(); var bearerToken = _configuration["BEARER_TOKEN"]; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken); if (pathWithParams != null) {

Continue reading

Combining foreach and using

Issue I’m iterating over a ManageObjectCollection.( which is part of WMI interface). However the important thing is, the following line of code. : foreach (ManagementObject result in results) { //code here } The point is that ManageObject also implements IDisposable,

Continue reading

Error logging in C#

Issue I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#. In my C++ source I can write LOGERR(“Some error”); or LOGERR(“Error with inputs

Continue reading

NLog seems to be writing incorrect value in database

Issue I’m using NLog for logging into database. It seems to me its misplacing value in columns. For instance, it writes StackTrace in Message column and Exception information in StackTrace column Configuration: <nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwConfigExceptions="true" throwExceptions="true"> <targets> <target name="database" type="Database"

Continue reading

How to log the request url when an error occurs in asp net core?

Issue Why does this code only gets executed when no error has occurred? app.Use(async (context, next) => { Console.WriteLine(context.RequestAborted.IsCancellationRequested); if(context.Response.StatusCode < 200 || context.Response.StatusCode > 299) { Console.WriteLine(); Console.WriteLine(context.Request.Method); Console.WriteLine(context.Request.Path); } await next.Invoke(); }); Is there an easy way to

Continue reading