447 questions
0 votes
0 answers
112 views
How to set script prerequisites
A while ago I created a small Use-ClassAccessors script and uploaded that to the PowerShell Gallery. Now I am creating another script that has a dependency on the Use-ClassAccessors script. Is there ...
0 votes
1 answer
454 views
Stop xunit from generating global usings
I'm testing with xunit on multiple frameworks (.Net 8 & .Net Core 3.1). The problem is that it keeps auto-generating this GlobalUsings file in my obj folder: // <auto-generated/> global ...
2 votes
1 answer
591 views
Should I wrap new HttpRequestMessage() in a using statement?
I found the following code: using (var requestMessage = new HttpRequestMessage(HttpMethod.Delete, endpoint)) { ... HttpResponseMessage response = await _client.SendAsync(requestMessage); .....
2 votes
1 answer
182 views
Why type aliases in C# cannot be used in another alias? [duplicate]
After C# 12 (.NET 8), all types can be aliased: using A = int; using B = string; using C = Dictionary<int, string>; However, it cannot be written as using A = int; using B = string; using C = ...
1 vote
0 answers
47 views
A "using" statement gets moved automatically outside of the namespace
A file within a custom VS project template is getting altered automatically by VS when the template is used to create a project. Code in the template zip file: using Enterprise.Utilities.ServiceBase....
1 vote
1 answer
79 views
C# Razor using statements inconsistently require explicit curly brackets
I have a .NET Framework 4.7.2 web application. I am receiving the following yellow screen error from some of my Views and Partial Views but not all of them: Expected a "{" but found a "...
0 votes
1 answer
95 views
is it necessary to use using Dispose the connection , open and close connection if using DbContext dapper in MS access database on vb.net
is it necessary to use using Dispose the connection, open and close connection if using DbContext dapper in MS access database on vb.net. This is my first time using dapper, please guide me so that ...
1 vote
1 answer
35 views
Identify the encompassing using block
How can I identify down the call chain the encompassing using block? I mean without saving in a static or global the object created by using block nor passing it around. If I have: using(new Foo()) { ...
-1 votes
1 answer
115 views
C# setting members from using statement
class A { TypeX PropertyX; void SomeMethod() { using (DisposableType y = new DisposableType()) { PropertyX = y.GetX(); } } } What happens to PropertyX when Y is being ...
1 vote
2 answers
1k views
How to properly separate API calls from File Storage Service in a Clean Architecture Pattern?
I am working on a .NET Core project in which I need to implement a Clean Architecture Pattern. The Task is to: make an HTTP request to a third-party API service read the response content as a Stream ...
0 votes
1 answer
52 views
Does using statement close all kinds of streams in it?
I have using statement to close the OleDbConnection and then I'm working with the reader. I'm wondering if I have to close the reader at the end or I can rely on the using statement to close it. I've ...
11 votes
3 answers
9k views
When is a `using var` disposed? Is it out-of-scope as soon as possible or at the end of the block?
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/using#using-declaration The lifetime of a using local will extend to the end of the scope in which it is ...
-1 votes
3 answers
273 views
why we use nested using statement in c#?
using (StreamReader outFile = new StreamReader(outputFile.OpenRead())) { StreamReader resFile = new StreamReader(resultFile.OpenRead()) { //Some Codes } } Why does the above ...
2 votes
1 answer
239 views
using statement with fluent api will not call dispose if throw occurs in fluent method chain
When combining a using statement with a fluent api that can potentially throw, the lowered code will never call dispose correctly. If I have the following class that exposes a fluent interface: public ...
0 votes
2 answers
194 views
C# What is the point of the using statement? [duplicate]
I'm not talking about references to assemblies, rather the using statement within the code. For example what is the difference between this: using (DataReader dr = .... ) { ...stuff involving data ...