text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : I have a .Net library supplied by a third party . I did reflection on one of their classes and found a member method . The signature was ... So , I wanted to call this method through reflection and got the exception `` ByRef return value not supported in reflection invocation . `` Here is what I 've tried ......
How do I work around the error `` ByRef return value not supported in reflection invocation '' in C # ?
C_sharp : I 'm trying to write a simple program that would connect to remote machines and query the indexing status.Here 's the code that does it on my machine . This works OK.However , when I call GetCatalog on `` mycomputername.SystemIndex '' instead of `` SystemIndex '' , I get An unhandled exception of type 'System...
Ca n't query SystemIndex on my own machine when I specify the machine name
C_sharp : I have been through the Identity Server 4 QuickStart for using Entity Framework for persistent storage of configuration and operational data . In the QuickStart , the ApiResources are loaded into the database in code . The Api secret is set with in the ApiResource constructor . When , in Startup.InitializeDat...
How to insert Identity Server 4 persisted ApiSecret values using T-SQL
C_sharp : We have a Web Service using WebApi 2 , .NET 4.5 on Server 2012 . We were seeing occasional latency increases by 10-30ms with no good reason . We were able to track down the problematic piece of code to LOH and GC.There is some text which we convert to its UTF8 byte representation ( actually , the serializatio...
Extensive use of LOH causes significant performance issue
C_sharp : I 'm writing a library which includes scheduling functionality ( not the standard TaskScheduler , IScheduler ... ) based on .Net Tasks . I 'm using TaskCompletionSource , and Task.Status is critical for representing the status of underlying operations , including TaskStatus.Created , i.e . created but not yet...
Create ice cold TaskCompletionSource ?
C_sharp : Background : In the spirit of `` program to an interface , not an implementation '' and Haskell type classes , and as a coding experiment , I am thinking about what it would mean to create an API that is principally founded on the combination of interfaces and extension methods . I have two guidelines in mind...
`` Program to an interface '' using extension methods : When does it go too far ?
C_sharp : I have a Report object that has Recipients property ( of String datatype ) . The Recipients property will hold all the recipients ’ email address in comma separated string . I need to create a “ Collection ” of Email objects from the comma separated string . I have the following code that uses a List of strin...
How to avoid redundant List using LINQ
C_sharp : Reference : How can a dynamic be used as a generic ? This enters with CheckEntity ( 16 , '' Container '' ) ; . After the first line runs , AnyObject becomes a blank Assembly.Models.DbModels.Container when inspected with the debugger . If var AnyType = AnyObject.GetType ( ) ; is used , then AnyType shows as As...
GetOriginalTypeParameterType throws Object reference not set to an instance of an object exception
C_sharp : Here comes a silly question . I 'm playing with the parse function of System.Single and it behaves unexpected which might be because I do n't really understand floating-point numbers . The MSDN page of System.Single.MaxValue states that the max value is 3.402823e38 , in standard form that isIf I use this stri...
Parsing floats with Single.Parse ( )
C_sharp : I am seeking some advice on what is the recommend way to use 'constant ' strings within my classes , e.g.The reason I would like to implement these , i.e . either via a const or via a getter , is because throughout my class ( es ) , I have methods and constructors that use these strings as parameters and I wa...
Design Advice on Getter or Const for String in Classes - what are others doing ?
C_sharp : My following C # code is obviously a hack so how do I capture the index value in the Where method ? <code> string [ ] IntArray = { `` a '' , `` b '' , `` c '' , `` b '' , `` b '' } ; int index=0 ; var query = IntArray.Where ( ( s , i ) = > ( s== '' b '' ) & ( ( index=i ) ==i ) ) ; // '' & '' and `` ==i '' onl...
Is there a way to capture the index value in a LINQ Where method in C # ?
C_sharp : I have no other developers to ask for advice or `` what do you think - I 'm thinking this '' so please , if you have time , have a read and let me know what you think.It 's easier to show than describe , but the app is essentially like a point of sale app with 3 major parts : Items , OrderItems and the Order....
Should I incorporate list of fees/discounts into an order class or have them be itemlines
C_sharp : Can someone help me to understand following codeIs it valid to assign a disposing object to MyFont property ? <code> public Font MyFont { get ; set ; } void AssignFont ( ) { using ( Font f = new Font ( `` Shyam '' ,2 ) ) { this.MyFont = f ; } }
C # using statement more understanding
C_sharp : Consider this MCVE class : When I evaluate and print such an object in C # Interactive , it looks like this : That 's not useful . I 'd like it to look like this : How do I do that ? I 've tried overriding ToString like this : This does n't produce quite what I 'd like : There 's at least three issues with th...
Custom print of object in C # Interactive
C_sharp : I 'm trying to deep clone an object which contains a System.Random variable . My application must be deterministic and so I need to capture the the random object state . My project is based on .Net Core 2.0.I 'm using some deep clone code from here ( How do you do a deep copy of an object in .NET ( C # specif...
Deep clone of System.Random
C_sharp : I want to create a simple ASP.Net form , that will get birth dates.I have a model with this property : and in my view ( is using the datepicker ) : The only one setting on my javascript datepicker is : because I want show dates without times.Now , I ca n't save , because of the validation error : The value '1...
Posting valid DateTimes from anywhere
C_sharp : I 'm using VS2017 on Windows 10 to work on a C # project . It is a really small console app that does nothing but require administrator privileges and then runs an HTA.The code references only these .NET assemblies : Since all of these exist in .NET since 2.0 and forward , it seems it should be possible to cr...
Create a .NET app that works on any .NET version if only basic requirements
C_sharp : Using Entity Framework one often writes queries such asWhat really makes my stomach churn is the `` Customer '' string argument . I have a hard time believing that EF does not generate table names as constants somewhere . Does anyone know a better approach than to using a string ? for the Include fetch option...
Entity framework autogenerated table names
C_sharp : Somehow EF disposes the ObjectContext in between two queries , without any further notice , but apparently not randomly and not due to a timeout.I added the using so the example is self contained but it does the same with the DbContext used in the whole application.Notice db is not yet disposed by using so th...
ObjectContext has been disposed throwed by EnsureConnection ( ) in consecutive queries ( No navigation properties used and no using ( ) )
C_sharp : I have a UWP project with two monitors that I want to use to open a new window on a secondary monitor . The application includes three parts : Open Main Page on first monitorCreate new pageOpen on secondary monitorI wrote the first and second parts correctly , but I ca n't find a solution for the third part.P...
Open new window on secondary monitor in UWP
C_sharp : Here 's a little LinqToSql GOTCHA : Guess what - if you pass a null State object to this method , you get a null reference exception ! It seems that LinqToSql does n't use the || shortcut operator as a shortcut ! Answer credit goes to whoever proposes the best explanation & workaround for this . <code> // Ret...
Conditional shortcuts in LinqToSql query
C_sharp : I am modifying the default analyzer project that comes from the code analyzer template to try and get it to report at all of the declarations for a partial class.I have modified the code to : In two separate files , I have partial classes like this : I put breakpoints on the ReportDiagnostic and am seeing it ...
ReportDiagnostic on Partial Classes
C_sharp : I have a CheckBoxList control that contains dynamically generated checkbox items . This checkboxlist will contain usernames . I am using Gravatar control from AjaxControlToolkit to allow users to have their own profile pictures . What I want is that when a checkbox with username as a text is added to the Chec...
How to add AjaxControlToolkit 's Gravatar Control before or after checkbox in checkboxlist control
C_sharp : I was investigating some strange object lifetime issues , and came across this very puzzling behaviour of the C # compiler : Consider the following test class : The compiler generates the following : The original class contains two lambdas : s = > hashSet.Add ( s ) and ( ) = > File.OpenRead ( file ) . The fir...
Is this closure combination behaviour a C # compiler bug ?
C_sharp : I 'm trying to create a method which returns a list of whichever type the user wants . To do this I 'm using generics , which I 'm not too familiar with so this question may be obvious . The problem is that this code does n't work and throws the error message Can not convert type Systems.Collections.Generic.L...
Can use IList but not List in generic method
C_sharp : We 'll start with a standalone story , just so you understand why : I want to treat any actions that change data against the same interface : ICommandThere are things that exist out there called ICommandHandlers that handle any command I want.So , if I want a CreatePersonCommand I 'd need a CreatePersonComman...
RegisterOpenGeneric with SimpleInjector resolves incorrect type
C_sharp : Related question : Accessing a Class property without using dot operatorI 've created a class called MyDouble looks like thisI am able to do all kinds of operations on MyDouble . Examples : However , this still throws an errorHow can I define it such that an operation like ( Int64 ) a automatically converts t...
Casting my Class to Int64 , Double etc
C_sharp : Hopefully someone can explain this to me . Sorry if it 's a repeat , the keywords to explain what I 'm seeing are beyond me for now..here is some code that compilesand here is some code that does notBy adding the constructor overload , this apparently creates ambiguity but I 'm not sure why . Math.Sqrt is not...
C # Call is Ambiguous when passing a method group as delegate
C_sharp : In the example below , is there a way for a method of the implementing class to explicitly tell the compiler which interface member it implements ? I know it 's possible to resolve ambiguity between interfaces , but here it is within one interface . <code> interface IFoo < A , B > { void Bar ( A a ) ; void Ba...
How to resolve ambiguous interface method signatures , occuring when multiple generic type arguments are identical
C_sharp : I have this code : When I run the code in a Console Application , everything works fine , stream.IsAuthenticated and stream.IsMutuallyAuthenticated return true and stream.LocalCertificate contains the correct certificate object.However when running the exact same code in a Windows Service ( as LOCAL SYSTEM us...
SslStream Authentication fails under LOCAL SYSTEM account
C_sharp : I have a simple question for you ( i hope ) : ) I have pretty much always used void as a `` return '' type when doing CRUD operations on data.Eg . Consider this code : and then considen this code : It actually just comes down to whether you should notify that something was inserted ( and went well ) or not ? ...
CRUD operations ; do you notify whether the insert , update etc . went well ?
C_sharp : I 'm trying to figure out how to properly pass properties through multiple classes . I know I can just implement INotifyPropertyChanged in each class and listen for changes on the property , but this seems to be quite a lot of unnecessary code.The situation : I have a class ( let 's call it Class1 ) with two ...
Propagate property changes through multiple classes
C_sharp : I have a collection of variables in my viewmodel : The ObservableVariable class has two properties : string Name , and bool Selected ; the class implements INotifyPropertyChanged , My goal is to have this collection bound to a checklist in a WPF view , and to have a 'select all ' checkbox bound to that list i...
WPF Multibinding not Updating Source when Expected ; Checkboxes with 'Select All '
C_sharp : I am binding DataGrid.ItemsSource property to the List < PersonDetails > object . I am getting datas through Silverlight-enabled WCF Service . So the PersonDetails class is implemented in Web Project . Each DataGrid 's header text is changing as i want if the class is located in Silverlight project . But then...
DisplayAttribute name property not working in Silverlight
C_sharp : From my recent question , I try to centralize the domain model by including some silly logic in domain interface . However , I found some problem that need to include or exclude some properties from validating.Basically , I can use expression tree like the following code . Nevertheless , I do not like it beca...
What 's the best way to define & access selected properties in C # ?
C_sharp : I 'm trying to get a list of items to update whenever a message is received from a message queue.This only seems to work every other time a message is received though . It 's definitely hitting the anonymous method inside the SubscribeAsync call each time , and I ca n't work out why it 's not updating every t...
Update list of items in Blazor from another thread
C_sharp : So I have run into an interesting problem where I am getting duplicate keys in C # Dictionary when using a key of type PhysicalAddress . It is interesting because it only happens after a very long period of time , and I can not reproduce it using the same code in a unit test on a completely different machine ...
Duplicate keys in Dictionary when using PhysicalAddress as the key
C_sharp : Hello fellow StackOverflow users ( or Stackoverflowers ? ) : I 'm learning-by-coding WPF . I read several articles/saw several screencasts , and coming from a WEB dev background , I fired up VS2010 and started doing a sample application that would help me learn the basics.I read some about MVVM too , and star...
WPF MVVM Doubts
C_sharp : Given the following class , how would you go about writing a unit test for it ? I have read that any test that does file IO is not a unit test , so is this an integration test that needs to be written ? I am using xUnit and MOQ for testing and I am very new to it , so maybe I could MOQ the file ? Not sure . <...
How do you test code that does file IO ?
C_sharp : I have an SQL connection service that I 'm trying to build . I essentially do this : DoStuffWithSqlAsync operates like this : And RunQueryAsync operates like this : The problem I 'm running into is that DoStuffWithSqlAsync continuously fails with a System.InvalidOperationException stating that conn is in a cl...
SqlConnection closes unexpectedly inside using statement
C_sharp : In C # 5 , they introduced the Caller Info attributes . One of the useful applications is , quite obviously , logging . In fact , their example given is exactly that : I am currently developing an application and I am at the point where I would like to introduce the usage of the caller info in my logging rout...
How I can I do TDD with Caller Info attributes ?
C_sharp : I read that when in a catch block , I can rethrow the current exception using `` throw ; '' or `` throw ex ; '' .From : http : //msdn.microsoft.com/en-us/library/ms182363 % 28VS.80 % 29.aspx '' To keep the original stack trace information with the exception , use the throw statement without specifying the exc...
Why do `` throw '' and `` throw ex '' in a catch block behave the same way ?
C_sharp : I have a kind a simple question but I 'm surprised.This code works : Why do n't I have to do itemID.ToString ( ) in this case ? <code> int itemID = 1 ; string dirPath = @ '' C : \ '' + itemID + @ '' \abc '' ;
int to string without explicit conversion ?
C_sharp : The problem is this : I have a form that accepts a TextBox text and 2 buttons , one to save the text into the database and the other one to cancel and close the form . The form also has an ErrorProvider that 's used in the TextBox.Validating event like this : It does what is expected , to not let the user to ...
In a textbox validating event , how to ignore clicks to a certain button ?
C_sharp : Disclaimer : It is well known that catch ( ex ) { throw ex ; } is bad practice . This question is not about that.While digging through Microsoft reference sources , I noticed the following pattern in a lot of methods : No logging , no debugging code—just a plain simple catch { throw ; } .Since , obviously , t...
Is there any technical reason to write a catch block containing only a throw statement ?
C_sharp : I 'm trying to create a not in clause with the NHibernate Criteria API using NHLambdaExtensions . Reading the documentation I was able to implement the in clause by doingHowever , when I wrap it around SqlExpression.Not I get the errorI 'm using this piece of codeHow can I accomplish this ? Using the regular ...
How do I express “ not in ” using lambdas ?
C_sharp : For a dynamic binary translation simulator , I need to generate collectible .NET assemblies with classes that access static fields . However , when using static fields inside collectible assemblies , execution performance is by factor of 2-3 lower compared to non-collectible assemblies . This phenomen is not ...
Static field access in collectible dynamic assemblies lacks performance
C_sharp : This is something I encountered while using the C # IList collectionsAs far as I know , in C # ( on the contrary of C++ ) when we create an object with this syntax , the object type get the right side ( assignment ) and not the left one ( declaration ) .Do I miss something here ! EDITI still do n't get it , e...
Object assignment in C #
C_sharp : I 've been at this for a few days now . My original ( and eventual ) goal was to use CommonCrypto on iOS to encrypt a password with a given IV and key , then successfully decrypt it using .NET . After tons of research and failures I 've narrowed down my goal to simply producing the same encrypted bytes on iOS...
iOS & .NET Produce Different AES256 Results
C_sharp : I need help with GDAL . The string value with Chinese symbols is not readed/saved correctly ( C # ) .For SAVING grid value we using : private static extern void GDALRATSetValueAsString ( IntPtr handle , int row , int field , [ In ] [ MarshalAs ( UnmanagedType.LPStr ) ] string value ) ; method ( c # ) to save ...
GDAL GDALRATSetValueAsString ( ) how to save Chinese characters ( c # ) ?
C_sharp : I am currently using Visual Studio Express C++ 2008 , and have some questions about catch block ordering . Unfortunately , I could not find the answer on the internet so I am posing these questions to the experts.I notice that unless catch ( ... ) is placed at the end of a catch block , the compilation will f...
Questions regarding ordering of catch statements in catch block - compiler specific or language standard ?
C_sharp : I have a bunch of methods that take the WPF 's WriteableBitmap and read from its BackBuffer directly , using unsafe code.It 's not entirely clear whether I should use GC.KeepAlive whenever I do something like this : On the one hand , there remains a reference to bmp on MyMethod 's stack . On the other , it se...
Is GC.KeepAlive required here , or can I rely on locals and arguments keeping an object alive ?
C_sharp : I want to have an enum as in : How to achieve this ? Is there a better way to do this ? It 's gon na be used for an instance of an object where it 's gon na be serialized/deserialized . It 's also gon na populate a dropdownlist . <code> enum FilterType { Rigid = `` Rigid '' , SoftGlow = `` Soft / Glow '' , Gh...
Possible to have strings for enums ?
C_sharp : I have a class that calls out to an internet service to get some data : Currently I have two providers : HttpDataProvider and FileDataProvider . Normally I will wire up to the HttpDataProvider but if the external web service fails , I 'd like to change the system to bind to the FileDataProvider . Something li...
programmatically change a dependency in Castle Windsor
C_sharp : I have an interface called Identifiable < TId > that contains a single property Id of the given type . I want to create a generic class that takes one of these as a type parameter . It should be generic because I want to return concrete type , call other generic methods from within it and use things like type...
Is it possible to implement this interface generically so that it can be passed only one type parameter ?
C_sharp : The MSDN recommends putting any instantiation of classes that implement IDisposable into a using block . Or alternatively , if it is being instantiated within a try-catch block , then Dispose in Finally.Are there any problems with using a using block within a try-catch block like so ? Of course I can just cal...
Are there any issues with using block for an IDisposable within a try catch block ?
C_sharp : Can anybody shed any light on why this unit test is failing in Visual Studio 2013 ? <code> [ TestMethod ] public void Inconceivable ( ) { int ? x = 0 ; Assert.AreEqual ( typeof ( int ? ) , x.GetType ( ) ) ; }
Is the C # compiler optimizing nullable types ?
C_sharp : I 'd like to ensure that two interfaces are never found on the same class at compile-time , similar to how AttributeUsage checks custom Attributes at compile-time.e.g . : I can obviously do this at runtime with reflection , but I 'm interested in a compile-time solution.I 'd imagine that one probably does n't...
Ensure mutually exclusive interfaces at compile-time ?
C_sharp : Suppose I have a collection of strings : And I would like to generate a comma separated values from the list into something like : Notice the lack of `` , `` at the end.I am aware that there are dozens of ways to generate this : use for-loop and string.Format ( ) or StringBuilder.use integer counter and remov...
Generating Comma Separated Values
C_sharp : I 'm getting quite annoyed with a feature of Resharper that I just can not find how to disable independently.With Resharper turned off , whenever I type prop in VS2015 and press TAB , I get the following auto-generated code : and I 'm then able to switch between int and MyProperty repeatedly by pressing TAB a...
Resharper - Disable 'help ' when using `` prop '' shortcut in C #
C_sharp : I create objects by initializing the fields in this way : Is it always for field `` a '' to be initialized before field `` b '' ? Otherwise , an unpleasant error can occur when the values from the stream are subtracted in a different order . Thanks ! UPD : In the comments , many did not understand what I mean...
C # The order of fields initialization
C_sharp : I want to put all the signatures of Windows API functions I 'm using in programs in one class , such as WinAPI , and in a file WinAPI.cs I will include in my projects . The class will be internal static and the methods public static extern . ( Something like the huge NativeMethods.cs from the .NET Framework s...
Big C # source file with Windows API method signatures , structures , constants : will they all be included in the final .exe ?
C_sharp : I generated a .cur file to use it in my WPF application , the pointing position by default is left top corner , and I want to set it to the center.I found some threads here that help resolve that problem by setting the HotSpots , where you can do stuff like this : The problem is that is in WindosForms . In WP...
How to change the pointing position of a mouse cursor in WPF
C_sharp : This is a question based on the article `` Closing over the loop variable considered harmful '' by Eric Lippert.It is a good read , Eric explains why after this piece of code all funcs will return the last value in v : And the correct version looks like : Now my question is how and where are those captured 'v...
How|Where are closed-over variables stored ?
C_sharp : The following piece of C # code does not compile : This behaviour is correct according to the C # 4.0 specification ( paragraph 10.1.4.1 ) : While determining the meaning of the direct base class specification A of a class B , the direct base class of B is temporarily assumed to be object . Intuitively this e...
Why ca n't the meaning of a base class specification recursively depend on itself in C # ?
C_sharp : Microsoft 's documention of Parallel.For contains the following method : In this method , potentially multiple threads read values from matA and matB , which were both created and initialized on the calling thread , and potentially multiple threads write values to result , which is later read by the calling t...
Memory barriers in Parallel.For
C_sharp : For methods where ... there exists a static one-to-one mapping between the input and the output , andthe cost of creating the output object is relatively high , andthe method is called repeatedly with the same input ... there is a need for caching result values.In my code the following result value caching pa...
Which languages have support for return value caching without boilerplate code ?
C_sharp : I came across a behavior that surprises me . Given the following two classes : I can write code like this : The IDE makes it confusing , too , because , while it allows the assignment , it also indicates that the overridden property is read-only : Furthermore , this override is only allowed when I 'm using th...
Why can a full property in C # be overridden with only a getter but it can still be set ?
C_sharp : I have a question regarding raising base class events . I am currently reading the MSDN C # Programming Guide and I can not understand one thing from the below article : http : //msdn.microsoft.com/en-us/library/vstudio/hy3sefw3.aspxOK , so we are registering the delegate with an event and we 'll be calling t...
Why can a base class event call a private method ?
C_sharp : I have the following classes and I am trying to call Compare method from ExportFileBaseBL class but I get the errorCannot implicitly convert type 'Class1 ' to 'T ' . An explicit conversion exists ( are you missing a cast ? ) Should n't the type conversion be implicit ? Am I missing something ? <code> public a...
C # Generics - Calling generic method from a generic class
C_sharp : I 've been toying with parallelism and I 'm having some trouble understanding what 's going on in my program.I 'm trying to replicate some of the functionality of the XNA framework . I 'm using a component-style setup and one way I thought of making my program a little more efficient was to call the Update me...
C # Tasks not working as expected . Bizarre error
C_sharp : Given a collection of disparate objects , is it possible to find the most-specific base class they all share ? For instance , given objects with these class hierarchies ... ( For fun ... http : //www.wired.com/autopia/2011/03/green-machine-bike-is-a-big-wheel-for-grownups ) Is it possible to write a function ...
How can you programmatically find the deepest common base type from a bunch of subclasses ?
C_sharp : It all started with a trick question that someone posed to me.. ( It 's mentioned in the book - C # in a nutshell ) Here 's the gist of it.The above does n't seem right . a should always be == to itself ( reference equality ) & both should be consistent.Seems like Double overloads the == operator . Confirmed ...
When is Double 's == operator invoked ?
C_sharp : We have a controller which expects some parameters in a get route , but the OData functions like $ top is n't working.According to the docs it ( custom query options ) should work fine just declaring the @ prefix at the custom options but it 's not : Using @ as the prefix ( as suggested at docs ) the paramete...
Get route using OData and custom query options
C_sharp : Somewhere in the back of my head a tiny voice is telling me `` the C # code below smells '' .The constant STR_ConnectionString is used in other places in the code as well.How to get rid of the smell ? <code> private const string STR_ConnectionString = `` ConnectionString '' ; private readonly string upperCase...
C # : better way than to combine StartsWith and two ToUpperInvariant calls
C_sharp : Do C # console applications appear in the task manager ? I 'm trying to get it both to appear , and the Publisher and Process Name columns to be what I expect.In my AssemblyInfo.cs I have done this : But while my console app is running ( ran from command line as the current user ) I do n't see any of these va...
Does a C # ( .NET 4.5 ) application appear in the Windows ' Task Manager ?
C_sharp : Can someone please explain to me the following method ? I do n't quite understand what it does , and how it does it . <code> private List < Label > CreateLabels ( params string [ ] names ) { return new List < Label > ( names.Select ( x = > new Label { ID = 0 , Name = x } ) ) ; }
Help understanding some C # code
C_sharp : This seems odd to me , but I remember a thread where Eric Lippert commented on the inability ( by design , or at least convention , I think ) of C # to overload methods based on return type , so perhaps it 's in some convoluted way related to that.Is there any reason this does not work : But this does : From ...
Is the C # compiler unable to infer method type parameters by expected return type ?
C_sharp : I have a distributed system of actors , some on Windows , and some on Linux machine . Sometimes one actor may need to connect other actor and make some communications . Of course , there are cases when one of them is on Windows , and other is on Linux system.Actors connect each other via ActorSelection . Ther...
Akka.NET Remote between Linux and Windows
C_sharp : I 'm currently working on a website which is being developed using Asp.Net and C # . I 'm making use of Asp.Net Handler to allow users to download files . I can download the files no problem . However I need to log which files were downloaded successfully . This part does n't seem to work correctly for me . E...
Using Handler to keep track of files
C_sharp : I 'm trying to get non-standard-format data from the clipboard using DataPackageView.GetDataAsync . I am stumped on converting the returned system.__ComObject to a string . Here is the code : I am looking for a solution that will work with any non-standard clipboard format . `` FileName '' is an easily testab...
How to get string from dataPackageView.GetDataAsync ( )
C_sharp : So I am looking at this question and the general consensus is that uint cast version is more efficient than range check with 0 . Since the code is also in MS 's implementation of List I assume it is a real optimization . However I have failed to produce a code sample that results in better performance for the...
Code sample that shows casting to uint is more efficient than range check
C_sharp : I am building an ASP.NET Core application which will need to handle large file uploads— as much as 200GB . My goal is to write these files to disk and capture an MD5 Hash at the same time.I 've already gone through and created my own method to identify the file stream from an HTTP client request as outlined i...
How does asynchronous file hash and disk write actually work ?
C_sharp : When I used to develop in C++ , I remember that Visual Studio had an entry in its Autos window whenever returning from a function call . This entry would tell me what value was returned from that function.One might argue that if a function returns a value , then you should set a variable to that value , i.e.B...
Return value in Visual Studio 's Autos window
C_sharp : I 'm implementing some 32-bit float trigonometry in C # using Mono , hopefully utilizing Mono.Simd . I 'm only missing solid range reduction currently.I 'm rather stuck now , because apparently Mono 's SIMD extensions does not include conversions between floats and integers , meaning I have no access to round...
Floating point range reduction
C_sharp : Let 's say I have a method : It 's clear that I should use ArgumentNullException as it shown above to validate that user is not null . Now how can I validate that user.Name is not empty ? Would it be a good practice to do like that : <code> public void SayHello ( User user ) { if ( user == null ) throw new Ar...
ArgumentNullException for nested members
C_sharp : Perhaps a useless question : One of exceptions thrown by the above method is also OverflowException : The sum of the elements in the sequence is larger than Int64.MaxValue.I assume reason for this exception is that sum of the averaged values is computed using variable S of type long ? But since return value i...
Enumerable.Average and OverflowException
C_sharp : Apologies if this is already answered on this site or in the extensive ServiceStack documentation - I have looked , but if it does exist , I would appreciate a pointer ! I 've been trying to knock up an example service stack ( 1.0.35 ) service which demonstrates the usage of OAuth2 using .NET core ( not .NET ...
OAuth2 authentication plugin for ServiceStack .NET Core
C_sharp : I 'm currently making my own very basic generic list class ( to get a better understanding on how the predefined ones work ) . Only problem I have is that I ca n't reach the elements inside the array as you normally do in say using `` System.Collections.Generic.List '' . This works fine , but when trying to a...
generic list class in c #
C_sharp : So I have just caught this bug in our code : Is the order of execution in function invocation specified regarding the order of parameters ? What is written here is : Which means that the first parameter 's reference is saved before the second parameter 's function is invoked.Is this defined behavior ? I could...
What is C # order of execution in function call with ref ?
C_sharp : So , the quote comes from `` Dependency Injection in .NET '' . Having that in consideration , is the following class wrongly designed ? So this FallingPiece class has the responsibility of controlling the current falling piece in a tetris game . When the piece hits the bottom or some other place , raises an e...
`` Classes should never perform work involving Dependencies in their constructors . ''
C_sharp : This example is a simplification of the real problem , but how can I get this to compile ? I would expect the generics constraints to propagate.Since T is a TClass and TClass is a class , why isnt T a class ? EDIT : This actually works . Eric Lippert made me think , thanks.Since T is a TClass and TClass is a ...
C # generics contraints propagation
C_sharp : My colleague keeps telling me of the things listed in comments.I am confused.Can somebody please demystify these things for me ? <code> class Bar { private int _a ; public int A { get { return _a ; } set { _a = value ; } } private Foo _objfoo ; public Foo OFoo { get { return _objfoo ; } set { _objfoo = value ...
C # myths about best practices ?
C_sharp : I get a ProtoException ( `` Possible recursion detected ( offset : 4 level ( s ) ) : o EOW '' ) when serializing a tree structure like so : The tree implementation : Am I decorating with the wrong attributes or have I simply designed a non-serializable tree ? Edit : tried this to no avail : <code> var tree = ...
Serialize prefix tree
C_sharp : I defined this method : For converting Lists of Type 1 to Lists of Type 2.Unfortunately I forgot , that C # compiler can not say at this stage that T1 is convertible to T2 , so it throws error : error CS0030 : Can not convert type T1 to T2Can someone direct me how to do it properly ? I need this method for no...
Generic method and converting : how to define that Type 1 is convertible to Type 2
C_sharp : When using a very simple expression as key to create an ILookup with Enumerable.ToLookup < TSource , TKey > Method ( IEnumerable < TSource > , Func < TSource , TKey > ) I can use a lambda expression : or a local function : I 'm curious if there is a difference in this simple case.In his answer to Local functi...
Performance of assigning a simple lambda expression or a local function to a delegate
C_sharp : The aim is to see the list as a list of 'name's.Here 's the dictionary : Here 's the attribute 'name ' I 'm after : And here 's the problem : I just ca n't think how to make that line work ! Your advice is much appreciated ! Thanks <code> class Scripts { public Dictionary < int , Script > scripts = new Dictio...
C # Can I display an Attribute of an Object in a Dictionary as ListControl.DisplayMember ?
C_sharp : I have a project where I am using C # 7 features . It builds fine locally , but when I build in Visual Studio Team Services , I get errors . All the errors point to this one project and they all look related to C # 7 : The project targets.NET 4.6.1 and references Microsoft.CodeDom.Providers.DotNetCompilerPlat...
Deploying C # 7 code to VSTS
C_sharp : I am calling a function which returns a string containing XML data . How this function works is not important but the resulting xml can be different depending on the success of the function.Basically the function will return either the expect XML or an error formatted XML . Below are basic samples of what the...
Checking XML for expected structure
C_sharp : I 'm trying to write a generic method that supplies parameters and calls a function , like this : The last line fails to compile with CS0411 . Is there any workaround to get type inference to work here ? Use case : using AutoFixture to generate function call parameters . <code> class MyClass { public int Meth...
C # method group type inference