text
stringlengths
46
37.3k
title
stringlengths
12
162
C_sharp : I am trying to build an ASP.NET Core docker image with following Dockerfile : The build fails , and it gives the following error : /app/MyPCL/MyPCL.csproj ( 70,3 ) : error MSB4019 : The imported project `` /usr/share/dotnet/sdk/1.0.1/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets '' was not found ....
Ca n't build ASP.NET Core app that references PCL in docker
C_sharp : I 'm trying to zip and unzip data in memory ( so , I can not use FileSystem ) , and in my sample below when the data is unzipped it has a kind of padding ( '\0 ' chars ) at the end of my original data . What am I doing wrong ? <code> [ Test ] public void Zip_and_Unzip_from_memory_buffer ( ) { byte [ ] origina...
Unzipped data being padded with '\0 ' when using DotNetZip and MemoryStream
C_sharp : Just wondering if this is considered a clear use of goto in C # : I feel like this is ok , because the snippet is small and should make sense . Is there another way people usually recover from errors like this when you want to retry the operation after handling the exception ? Edit : That was fast . To answer...
Is this a clear use of goto ?
C_sharp : I have an entity collection of Readings.Each Reading is linked to an entity called Meter . ( And each Meter holds multiple readings ) .each Reading holds a field for meter id ( int ) and a field for time.Here is some simplified code to demonstrate it : Given a specific period and list of meterids , what would...
Efficient LINQ to Entities query
C_sharp : I 'm having trouble understanding how to render a collection as a drop down list.If I have a model like : I would like the string collection to render as a drop down list . Using the html page helper InputFor does n't seem to work . It simply render 's a text box . I 've noticed that InputFor can reflect on t...
fubumvc - rendering a collection as a drop down list
C_sharp : I 'm using EntityFramework ( EF V6 ) with Asp.Net for creating one website , In that I 've Created the .edmx and .tt and DBContext.I 'm trying to create an objects for each table to summoner it later with aspxI do n't know if I 'm writing my LINQ Queries in the right way ! , that 's why I need your help on th...
How to write LINQ Queries for CRUD using Entity Framework ?
C_sharp : I 've started using Swashbuckle with Web API . None of my types are getting rendered correctly in my Swagger UI . On every method , I see something like this ( unrendered ) : So I investigated , and found this in my Swagger definitions file for many of my methods : typeName exists in the definitions listing ....
Can not find type name in schema definitions
C_sharp : I have a constant flow of certain items that I need to process in parallel so I 'm using TPL Dataflow . The catch is that the items that share the same key ( similar to a Dictionary ) should be processed in a FIFO order and not be parallel to each other ( they can be parallel to other items with different val...
Hashed/Sharded ActionBlocks
C_sharp : I created a simple WPF application for enable and disable the aero shake behavior . My code is like this : Why my code does not function ? What this application do now : When I shake my window , the others windows are minimized.What I want to do : When I shake my window , or I shake any window , no window sho...
How to disable the aero shake for whole system ?
C_sharp : Situation : Say we are executing a LINQ query that joins two in-memory lists ( so no DbSets or SQL-query generation involved ) and this query also has a where clause . This where only filters on properties included in the original set ( the from part of the query ) . Question : Does the linq query interpreter...
Does `` where '' position in LINQ query matter when joining in-memory ?
C_sharp : I am getting the error in my log . I spent most of my day finding the solution but could not find the one which meets my requirement.Here is the log errorseverity= [ ERROR ] , ipaddress=xxxx , subprocess=Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery , description=An exception was thrown while d...
An exception was thrown while deserializing the token.The antiforgery token could not be decrypted in .Net Core 2.2 application
C_sharp : Consider the following , at first glance absurd , pattern match : Both is will return false . However if we use var the behavior changes completely : If you hover over var in VS2017 , the type is string but the behavior of is is completely different . The compiler is doing something radically different even t...
Different behavior in pattern matching when using var or explicit type
C_sharp : I have some working code that retrieves data from data base . It is interesting for me to get some better code for my solution . Are there some ways to combine two queries into one or something like this ? Same code with C # ( hope no syntax errors occurred ) : SCustomerInfo represented by folowing Structure ...
How merge two sequences into one ?
C_sharp : Say , I have an array of lists , and I want to get a count of all of the items in all of the lists . How would I calculate the count with LINQ ? ( just general curiosity here ) Here 's the old way to do it : How would you LINQify that ? ( c # syntax , please ) <code> List < item > [ ] Lists = // ( init the ar...
What 's the LINQ'ish way to do this
C_sharp : With the new readonly instance member features in C # 8 , I try to minify unnecessary copying of struct instances in my code.I do have some foreach iterations over arrays of structs , and according to this answer , it means that every element is copied when iterating over the array.I thought I can simply modi...
Can I foreach over an array of structs without copying the elements in C # 8 ?
C_sharp : When working with Domain Objects , how do you typically unit test a method that calls another method in the object ? For example : Unit testing GetTotalAmt ( ) is easy , but with GetExtendedTotalAmt ( ) I 'd have to use stub/mock InvoiceLine objects to make it work , when all I really want to do is test that ...
How to test methods that call other methods in a domain object
C_sharp : I 've been writing things like this in my implementations : However , I do n't know exactly what 's happening here ... Maybe everything was `` copied '' to the delegate . Or maybe , like reference types , all value types will have a copy associated to the Task delegate until it exists ? I 'm just trying to un...
How local variables are handled when referenced in another scope ?
C_sharp : Possible Duplicate : What is the C # Using block and why should I use it ? My question : Is using using ( a ) { do something with a } better than declaring ' a ' and using it that way . ie : more secure , faster , ... see examples for clarification.Example 1 : ( without using ) Example 2 : ( with using ) <cod...
Is using using Better ?
C_sharp : I 'm using an API call to return some XML data from a web server . The XML data is in the following format : I can retrieve the raw XML data successfully , and I want to add the < quoteText > and < quoteAuthor > node values to strings but seem to be unable to do this . My current code : My program bombs out w...
C # - Setting XML Node values as Stings from StreamReader result
C_sharp : Can I simplify this statement with a lambda expression ? <code> var project = from a in accounts from ap in a.AccountProjects where ap.AccountProjectID == accountProjectId select ap ;
Lambda Expression
C_sharp : Some programmers argue that it is better to pass IEnumerable < T > parameters over passing implementations like List < T > , and one of the popular reasons to do this is that the API is immediately usable in more scenarios because more collections will be compatible with IEnumerable < T > than any other speci...
Is T [ ] not better than IEnumerable < T > as parameter type ? ( Considering threading challenges )
C_sharp : I added 3 optional boolean parameters to a method found within a VB6 DLL . The class that houses it is MultiUse ( public ) , and the method itself is Private . The class implements a specific interface from a TLB , allowing for public calls to this method.After adding the 3 optional parameters on the VB6 side...
Is it possible that C # has problems calling VB6 methods that have optional parameters ?
C_sharp : I have a class that holds on to a delegate , in order to lazily evaluate something later.Once I 've evaluated it , by calling the delegate , I clear out the reference to the delegate , hoping that it would be eligible for collection . After all , it might hold on to a world of local variables if it was constr...
GC of delegates , what am I missing ? ( my delegate is not collected )
C_sharp : It 's not unusual to want a limit on the interval between certain events , and take action if the limit is exceeded . For example , a heartbeat message between network peers for detecting that the other end is alive.In the C # async/await style , it is possible to implement that by replacing the timeout task ...
Task-based idle detection
C_sharp : I have a solution of three projects : CoreOutlook Add-InASP.NET WebsiteBoth , the Outlook Add-In and the Website use the same methods from Core project to get data from SQL Server . When I write my data into database , I convert all DateTime values of two tables into UTC time : andWhen I get the data in my Ou...
Converting UTC to local time returns strange result
C_sharp : How to intentionally crash an application with an AccessViolationException in c # ? I have a console application that use an unmanaged DLL that eventually crashes because of access violation exceptions . Because of that , I need to intentionally throw an AccessViolationException to test how it behaves under c...
How to make C # application crash with an AccessViolationException
C_sharp : I am working with two C # stream APIs , one of which is a data source and the other of which is a data sink.Neither API actually exposes a stream object ; both expect you to pass a stream into them and they handle writing/reading from the stream.Is there a way to link these APIs together such that the output ...
How to link two C # APIs that expect you to provide a stream ?
C_sharp : I have 1 line with 2 known points : I 'd like to iterate through 10 pixels to the left ( or right ) to 1 line ( at x1 , y1 ) .The red dots are the ones that I 'd like process . Example : How do I iterate through these coords ? <code> PointF p2_1 = new PointF ( ) ; p2_1.X = 100 ; // x1p2_1.Y = 150 ; // y1Point...
Iterate through N points that are perpendicular to another line
C_sharp : I have a method that I want to be `` transactional '' in the abstract sense . It calls two methods that happen to do stuff with the database , but this method does n't know that.Because in real terms the TransactionScope means that a database transaction will be used , we have an issue where it could well be ...
Method knows too much about methods it 's calling
C_sharp : I have been asked at interview ( C # 3.0 ) to provide a logic to remove a list of items from a list.I responded1 ) The interviewer replied that the algorithm i had employed will gradually take time if the items grow and asked me to give even better and faster one.What would be the efficient algorithm ? 2 ) Ho...
C # Improved algorithm
C_sharp : I 'm working with some generics in C # . I have an abstract generic class : and the type parameter is specified when other classes inherit from the base class.I 'm also trying to write some code for another abstract class that needs to store one of these base classes , but it wo n't know the parameter of the ...
C # Equivalent of Java 's GenericType < ? >
C_sharp : I 've just installed the .NET 4.5 reference source from Microsoft as I 'm trying to debug an issue I 'm seeing and I stumbled across the following in HttpApplication.cs.Notice the next-to-last line private bool _ [ ... . ] ; // per call.Is _ [ ... . ] a valid identifier ( at any level of compilation , includi...
Is ` _ [ ... . ] ` a valid identifier ?
C_sharp : I am planning to use Auto reset Event Handle for Inter Thread communication.My producer thread code look like below In the consumer thread , I have to download data for every one minute or when producer is called Set methodMy question is if consumer thread is running doSomething function and producer calls se...
.NET Thread Synchronization
C_sharp : If I look at the IL that is created in Linqpad for the two following code snippets , I wonder what happens here.In c # results in the following IL codewhereas in VBit isApparently , the c # compiler understands the the value is never used and thus simply returns nothing . In VB.NET the actual code is translat...
Is the c # compiler smarter than the VB.NET compiler ?
C_sharp : I am beginner with programming in c # and i am just doing a pingpong game . I am using threads - one for collision , one for move , one for painting.My question is why the program run faster , when i open steam : D to me it seems like a nonsense.Witch slower i mean - ball is slower and the pads too . It looks...
pingpong game run faster when i open STEAM - why ?
C_sharp : I have the following code : The following statements works fine and the program compile despite i did n't implement the interface : So my first question is : Why did it work ? Then , i add the following interface implementation to Calculator class : When trying again the following statement : The method overr...
Code work despite the interface is not implemented
C_sharp : I tried the following code to enable some kind of not null checking for retrieved entities to ensure they are exist before doing some concrete business : But in compile time I 'm getting : After contract block , found use of local variable 'obj ' defined in contract blockAm I using Contract.Requires in the wr...
CodeContracts `` Required '' understanding
C_sharp : I 'm reading a book about C # for beginners and I 'm at the part `` Understanding Values and References '' , but there is something I do n't understand . What I 'm seeing is that the books tries to explain this to me ( and I 've seen this happening in a couple of tutorial video 's on Youtube as well ) that th...
Point of initializing a class ?
C_sharp : I have created a custom Attribute to decorate a number of classes that I want to query for at runtime : Each of these classes derive from an abstract base class : Do I need to put this attribute on each derived class , even if I add it to the base class ? The attribute is marked as inheritable , but when I do...
Attribute Inheritance and Reflection
C_sharp : What does a syntax like this mean in C # ? <code> public abstract class HostFactory < TApp > : ServiceHostFactory where TApp : IFoo
What does a syntax like this mean in C # ?
C_sharp : I am facing some problems using GalaSoft 's RelayCommand.I have a NextCommand property that works , but only several times.Afterwards , it stops working completely . You can try this out with the sample project : http : //s000.tinyupload.com/ ? file_id=65828891881629261404The behaviour is as follows : NextCom...
RelayCommand stops working after a while
C_sharp : I am developing a portable class library in C # and I want to bit convert a double to a long . The most straightforward solution to this issue would be to use the BitConverter.DoubleToInt64Bits method , but unfortunately this method is not available in the Portable Library subset of the .NET class library.As ...
.NET Portable library missing BitConverter.DoubleToInt64Bits , replacement very slow
C_sharp : I am using the Roslyn feature of generating version number from current date/time.I can see the auto generated date/time based version number gets stamped correctly as AssemblyVersion , and I can read it at runtime using API . Question : How do I get the same auto generated date time based version number stam...
How do I get AssemblyVersion stamped as FileVersion on the binary
C_sharp : Let 's say I have 3 DLLs ( BlueCar , RedCar , YellowCar ) that each have a named class ( BlueCarClass , etc ) that also all implement the same interface , Car , and are all built from the same namespace ( Car_Choices ) . So a DLL looks something like this before compiled : And the DLL 's name would be `` Blue...
How to dynamically load a DLL and use a class in it ( that implements a known interface ) [ C # ]
C_sharp : I have the following entitiesWhat I 'm trying to do is to get Active Auctions with Auctions loaded and Auction also have Departments loadedI know that I should write Include for every object to be loaded so the generated SQL by EF will have join statement to select there object for mebut this is the existing ...
Entity-Framework Join Explanation
C_sharp : I have this code which gets the value from the Test class and then converts it to the type it is . It prints correctly as `` Int32 '' but when I test the equality with another variable with the same value , it prints `` false '' . I suspect it is because it is testing reference equality and that the 2 variabl...
How can I compare value-types acquired from Reflection 's `` GetValue '' ?
C_sharp : I need to implement SO like functionality on my asp.net MVC site.For example when user go to https : //stackoverflow.com/questions/xxxxxxxxafter loading the subject line is concatenated with the url and url becomes like this https : //stackoverflow.com/questions/xxxxxxxx/rails-sql-search-through-has-one-relat...
how to implement url rewriting similar to SO
C_sharp : From what I understand , records are actually classes that implement their own equality check in a way that your object is value-driven and not reference driven.In short , for the record Foo that is implemented like so : var foo = new Foo { Value = `` foo '' } and var bar = new Foo { Value = `` foo '' } , the...
Custom Equality check for C # 9 records
C_sharp : I tried to use C # DI method to implement something . following is my code snippet.and code that creates a ServiceLocator : now , I create a test code with but , it looks like , I always get null returned by GetService ( ) function . Instead I expect to get EmailService object via GetService ( ) function , so...
Regarding to Type in C #
C_sharp : As stated here , the PropertyChangedEventManager class Provides a WeakEventManager implementation so that you can use the `` weak event listener '' pattern to attach listeners for the PropertyChanged event.There are two ways to subscribe for property changes : They both end up calling the same method : with e...
PropertyChangedEventManager : AddHandler vs AddListener
C_sharp : When I have a IEnumerable < SomeClass > from which I do n't know wheter its a list or not ( in terms of List < T > ) , and I have to enumerate that IEnumerable to make sure that I dont enumerate that enumerable twice ( such as looping over it twice , or something like that ) .Resharper warns me about possible...
Is casting to IList and then calling ToList ( ) when null better than plain ToList ( ) ?
C_sharp : I 'm writing a WinForms app in C # . I need to ensure no two Datarows in my Datatable are more than 100 km apart . Each row has a UTM Zone , Easting , and Northing in separate DataColumns . All coordinates use the same datum , but some have different zones ( otherwise , I would just use pythag math since UTMs...
Parsing UTM coordinates to DBGeography in C #
C_sharp : I 'm writing a Tiger compiler in C # and I 'm going to translate the Tiger code into IL.While implementing the semantic check of every node in my AST , I created lots of unit tests for this . That is pretty simple , because my CheckSemantic method looks like this : so , if I want to write some unit test for t...
Writing unit tests in my compiler ( which generates IL )
C_sharp : I 'm on learning for C # .I heared C # is one of the most constructible language . so would you guys make my code more elegant and efficient ? Here is a my class ISO639 . This class provides enum for ISO639 code , but I need a type conversion on from ISO639 enum to plain string . ( ex . ISO639.ISO639Code.Ital...
more elegant design about enum
C_sharp : I am writing an application to capture the screen using the CopyFromScreen method , and also want to save the image I capture to send over my local network.So , I am trying store the captured screen on one bitmap , and save another bitmap , which is the previously captured screen , on two threads . However , ...
InvalidOperationException while saving a bitmap and using graphics.copyFromScreen parallel-y
C_sharp : I got a scenario to create the anonymous list from the anonymous types , and i achieved that using these are the error messages System.Collections.Generic.List.Add ( AnonymousType # 1 ) ' has some invalid arguments Argument ' 1 ' : can not convert from 'AnonymousType # 2 ' to 'AnonymousType # 1'whats the reas...
is order of field important in anonymous types automatic initialization ?
C_sharp : Possible Duplicate : C # Why can equal decimals produce unequal hash values ? I 've come across an issue in my .NET 3.5 application ( x86 or x64 , I 've tried both ) where decimals with a different number of trailing zeros have different hash codes . For example : Outputs the following on my machine : I presu...
Decimal.GetHashCode Depends On Trailing Zeros
C_sharp : I create an entry usingIt is inside a ListView > ItemTemplate > DataTemplate > ViewCellThe thing is I need a way once a user clicks the submit button in that ViewCell it gets the text for the entry in that cell . I am using Binding to set the values so I do n't how to get the text . <code> < Entry Placeholder...
How to get text from entry
C_sharp : Let 's say we have two interfaces with conflicting method signatures : and now we create a class like this : The method named as IB.F looks like a private method , however you can do something like this : So my question is : how does the C # compiler know that IB.F can be called outside the class scope ? I gu...
Class implementing interfaces with conflicting method signatures
C_sharp : First things off , I had no idea what to title this question - I 'm even confused how to state it . Now for the question . Let 's take the System.IO.FileSystemWatcher class where you set it 's NotifyFilter property : That 's quite a bit of code to set a single property . Inspecting NotifyFilter , it is an enu...
Is there a way to set an Enumerated Property in a class to All available enums ?
C_sharp : I am using this code to extract a chunk from file Is there any way to speed up this process ? Currently for a 530 MB file it takes around 4 - 5 seconds . Can this time be improved ? <code> // info is FileInfo object pointing to filevar percentSplit = info.Length * 50 / 100 ; // extract 50 % of filevar bytes =...
Improve speed of splitting file
C_sharp : I have the following class : Can someone explain why they Customer information is coded with virtual . What does it mean ? <code> public class Delivery { // Primary key , and one-to-many relation with Customer public int DeliveryID { get ; set ; } public virtual int CustomerID { get ; set ; } public virtual C...
Why would I need to use a virtual modifier in a c # class ?
C_sharp : I think I 'm missing something obvious here , but how do I update the GUI when using a task and retrieving the value ? ( I 'm trying to use await/async instead of BackgroundWorker ) On my control the user has clicked a button that will do something that takes time . I want to alert the parent form so it can s...
How do I update the GUI on the parent form when I retrieve the value from a Task ?
C_sharp : I have an application that has a concept of a Venue , a place where events happen . A Venue has many VenueParts . So , it looks like this : A Venue can be a GolfCourseVenue , which is a Venue that has a Slope and a specific kind of VenuePart called a HoleVenuePart : In the future , there may also be other kin...
How do I organize C # classes that inherit from one another , but also have properties that inherit from one another ?
C_sharp : This question is not about managing Windows pathnames ; I used that only as a specific example of a case-insensitive string . ( And I if I change the example now , a whole bunch of comments will be meaningless . ) This may be similar to Possible to create case insensitive string class ? , but there is n't a l...
How can System.String be properly wrapped for case-insensitivy ?
C_sharp : I hava a mvvm wpf application that worked properly all until one moment when it freezes and causes massive memory leak.Solution files : Google Disk Solution LinkThe application uses local mdf file , uses Mahhaps , and some additional references ( for example one for displaying gifs ) This is the method call i...
Wpf application freezes - massive memory leak puzzle
C_sharp : The docs show this for a POST : But what about a GET : The problem is the ampersand in this line : /// GET /Todo ? iscomplete=true & owner=mike . The compiler complains : warning CS1570 : XML comment has badly formed XML -- 'Expected an end tag for element 'owner ' . ' I also tried & amp ; .I actually have n'...
Querystring with ampersand in Swashbuckle xml comments
C_sharp : Currently I have I want to make the path relative to the original path.For example if Tenant1/PageThatThrowsError then app.UseExceptionHandler ( `` Tenant1/Home/Error '' ) ; but if Tenant2/PageThatThrowsError then app.UseExceptionHandler ( `` Tenant2/Home/Error '' ) ; I thought I would be able to dobut this t...
How to handle dynamic error pages in .net MVC Core ?
C_sharp : This is a somewhat obscure question , but after wasting an hour tracking down the bug , I though it worth asking ... I wrote a custom ordering for a struct , and made one mistake : My struct has a special state , let us call this `` min '' .If the struct is in the min state , then it 's smaller than any other...
Why does failing to recognise equality mess up C # List < T > sort ?
C_sharp : Using NUnit 2.6.4 & FakeItEasy 1.25.2 to unit test a C # code in Visual Studio 2013 Community EditionThe following test fragment executes as expectedhowever as soon as I decorate my fake with a CallTo/Returns ( ) or ReturnsLazily ( ) statement ... fakeStream.Read ( ) throws a System.InvalidOperationException ...
A.Fake < Stream > ( ) .Read ( ... ) throwing InvalidOperationException
C_sharp : I use the following razor code to generate some javascript to produce markers on a Google map.In development , this correctly becomes : However , on our production server , it becomes : Which is producing just a grey Google map . What is causing this strange ToString behavior ? editThe Point class is a custom...
Invalid Double.ToString ( ) result in razor code generating javascript
C_sharp : Its a well known fact that a static method can work only on static members.Here the Main method is static , but I have n't declared t1 as static . Is it implicitly static ? <code> public static void Main ( ) { Test t1 = new Test ( ) ; }
Are variables in the main methods static
C_sharp : In short , I am looking for guidance on which of the following two methods should be preferred ( and why ) : Argument in favour of DistinctA : Obviously , the constraint on T is not required , because HashSet < T > does not require it , and because instances of any T are guaranteed to be convertible to System...
When to specify constraint ` T : IEquatable < T > ` even though it is not strictly required ?
C_sharp : I 've been asking questions on hex and bitwise manipulation ( here and elsewhere ) for the past week trying to wrap my head around their representation in Java . After much Googling and chagrin I must ask one final time how to perform logical arithmetic on bits that ought to be unsigned , but are represented ...
Performing bitwise left shifts on `` signed '' data in Java -- better to move to JNI ?
C_sharp : I was asked today if there was a library to take a list of strings and to compute the most efficient regex to match only those strings . I think it 's an NP Complete problem by itself , but I think we can refine the scope a bit.How would I generate and simplify a regex to match a subset of hosts from a larger...
Simplifying regex OR patterns
C_sharp : I 'm trying to get to the bottom of an entity Framework issue when using it with a TableControllerI 've created the following setup.The basic TodoItem example provided with a new Mobile Web API which leverages EntityFramework , TableController & the default EntityDomainManagerA vanilla Web API 2 controller.I ...
Why is Entity Framework generating the following nested SQL for Azure Mobile Services Table Controllers
C_sharp : I am rendering my game in a Winform in the same way as done in this sample : WinForms Series 1 : Graphics Device In my game I have some object , for example a rectangle that I can already put and move , in my game world , once created . My project here is a level-editor.What I want to do is to make every obje...
How to make an object `` scalable '' while rendered in a form
C_sharp : Consider the following example : This compiles well.I wonder why can not I remove < string > generic argument ? I get an error that it can not be inferred from the usage.I understand that such an inference might be challenging for the compiler , but nevertheless it seems possible.I would like an explanation o...
`` Two-level '' generic method argument inference with delegate
C_sharp : A fairly common idiom in C is for functions taking a polymorphic closure to represent this as two arguments , a function pointer and void pointer ( which is passed as one of the arguments to the function pointer . An example taken from the GPGME library : Conceptually , the function pointer plus void pointer ...
P/Invoke - Marshaling delegate as function pointer + void*
C_sharp : I run into this frequently enough that I thought I 'd see what others had to say about it . Using the StyleCop conventions , I find that I often have a property name that is hard to make different than the class name it is accessing . For example : It compiles and runs , but seems like it would be an easy way...
What is a good naming convention to differentiate a class name from a property in C # ?
C_sharp : A few years back , I got an assignment at school , where I had to parallelize a Raytracer.It was an easy assignment , and I really enjoyed working on it.Today , I felt like profiling the raytracer , to see if I could get it to run any faster ( without completely overhauling the code ) . During the profiling ,...
Why is a simple get-statement so slow ?
C_sharp : I am working on a runtime composite resource library for ASP.NET WebForms/MVC . I support both standard ASP.NET WebForms via WebControls and have also recently added support for ASP MVC Html Helpers . One feature that I currently support with the WebForms WebControls is the concept of `` Partial '' resource d...
Help with ASP.NET MVC HtmlHelper API Design
C_sharp : I 've been working with DDD for a few months now and I 've come across a few things I 'm unsure of . Take the simplistic example of adding a Product to an Order object . From our Controller , we 'd have an int passed via the UI which represents a Product in the database . Which of the following two examples i...
Which of these examples represent correct use of DDD ?
C_sharp : A colleague has passed me an interesting code sample that crashes with an InvalidProgramException ( `` CLR detected an Invalid Program '' ) when run.The problem seems to occur at JIT time , in that this compiles fine but throws the exception just before the method with the `` offending '' line is called - I g...
`` CLR detected an Invalid Program '' when using Enumerable.ToDictionary with an extension method
C_sharp : I 'm working on a project that needs to support both async and sync version of a same logic/method . So for example I need to have : The async and sync logic for these methods are identical in every respect except that one is async and another one is not . Is there a legitimate way to avoid violating the DRY ...
How to avoid violating the DRY principle when you have to have both async and sync versions of code ?
C_sharp : I have an empty list defined to hold 120 values , I want to insert an element at index ( 45 ) , even though the list is currently empty . Is this possible ? <code> public List < Ticket > Tickets = new List < Ticket > ( 120 ) ; Tickets.Insert ( 45 , ticket ) ; // Here I am getting the ArgumentOutOfRangeExcepti...
How to Insert an object in a list at custom index
C_sharp : I upgraded ReSharper and seeing an error that I was not present previously . I checked around , but found nothing about the error or the underlying issue it is flagging . ** Edit ** : as pointed out below , it is actually the 'Heap Allocation Viewer ' plugin , not ReSharper itself that is marking it as an err...
Slow delegate creation
C_sharp : On our application we have a clickable label which will pop up another window . I have been reading through the Microsoft Automation UI documentation , and ca n't find a way in which I 'm able to click a label control.I know that I ca n't use the Invoke Pattern as this only deals with Button controls.Below is...
Is it possible to Click a label control on WPF/WinForm App using Microsoft Automation UI
C_sharp : For the purpose of learning , I 'm trying to understand how C # strings are internally stored in memory.According to this blog post , C # string size is ( x64 with .NET framework 4.0 ) : A string with a single character will take ( 26 + 2 * 1 ) / 8 * 8 = 32 bytes .This is indeed similar to what I measured.Wha...
How many bytes does a string take up in x64 ?
C_sharp : I am tring to open memory mapped file in the system volume information subfolder . I know and see in explorer that it is exists there , and path is correct ( it is copy-pasted from explorer ) , moreover File.Exists for that path returns true , but MemoryMappedFile.OpenExisting fails with DirectoryNotFoundExce...
File.Exists returns true and OpenExisting fails with DirectoryNotFoundException
C_sharp : Ca n't find simple way to convert double to string . I need to convert large numbers without distortion . Such as : How to get string value from double value exactly the same as user enter.11111111111111111111111 = > `` 11111111111111111111111 '' 1.111111111111111111111 = > `` 1.111111111111111111111 '' Any i...
Get string from large double value ( C # )
C_sharp : I 'm hoping for a concise way to perform the following transformation . I want to transform song lyrics . The input will look something like this : And I want to transform them so the first line of each verse is grouped together as in : Lyrics will obviously be unknown , but the blank line marks a division be...
Tricky string transformation ( hopefully ) in LINQ
C_sharp : I was wondering if it is possible to reference a dynamic generic class name in a comment and have it conditionally resolved in the IDE ? Simple base class example : If I now inherit from this class and happens to be class User then I 'd like to have IntelliSense show my comment as `` Retrieves all User member...
Reference generic comment
C_sharp : Question : given IEnumerable < > , how to check what sequence contains more than x items ? MCVE : The problem here is what Count ( ) will run complete sequence and that 's 1E6+ items ( ToList ( ) is also bad idea ) . I am also not allowed to change consumer code ( it 's a method accepting complete sequence ) ...
Optimize LINQ Count ( ) > X
C_sharp : I 'm writing a filter function to return the specific type specified out of a larger collection of supertypes ( objects for example ) . The idea is I give you an enumerable and you return me all the strings for example . you can write it this way without generics : if we want to return generics there are a fe...
What is the appropriate way to strongly type the return of a generic function ?
C_sharp : Can someone explain to me why I can not seem to throw an exception from inside the AppDomain.Assembly load event ? For example : When I execute this , the output is as follows : Can anyone explain this behavior to me ? Thank you.EDIT To clarify a couple things : The assembly load event runs fine , when I expe...
Throw exception from AppDomain.AssemblyLoad event
C_sharp : i tried this code but it takes so long and I can not get the resultplease help <code> public long getCounter ( [ FromBody ] object req ) { JObject param = Utility.GetRequestParameter ( req ) ; long input = long.Parse ( param [ `` input '' ] .ToString ( ) ) ; long counter = 0 ; for ( long i = 14 ; i < = input ...
how many numbers between 1 to 10 billion contains 14
C_sharp : Suppose we have a nested generic class : Here , typeof ( A < int > .B < > ) is in essence a generic class with two parameters where only the first is bound.If I have a single class with two parametersIs there a way to refer to `` AB with T=int and U staying open '' ? If not , is this a C # limitation , or a C...
Does .Net support curried generics ?
C_sharp : I have a dll wich expose a type like inside this library I also have an IPackage implementation which register the MyDbContext in the container like This assembly is then referenced from two different types of applications : - a web api project - an asp.net mvc applicationThis is the initialization of the web...
DbContext creation into message handler
C_sharp : I 'm trying to create a shortcut ( .lnk ) on my windows filesystem.The code I have is working fine . However , when I run the same console application on a Windows 2008R2 Server , it acts differently.So I have my console application and here is what happens : My program simply creates a shortcut on the deskto...
Creating shortcut modifies the path to target