.net

Math.IEEERemainder returns negative results. Why?

The .net framework includes Math.IEEERemainder(x, y) in addition to the standard mod operator. What is this function really doing? I dont understand the negative numbers that this produces. Example: Math.IEEERemainder(0, 2) = 0 Math.IEEERemainder(1, 2) = 1 Math.IEEERemainder(2, 2) = 0 Math.IEEERemainder(3, 2) = -1 ...

Windows Forms: A modal form that gets opened/closed by the application rather than the user?

I have what I believe to be a fairly well structured .NET 3.5 forms application (Unit Tests, Dependency Injection, SoC, the forms simply relay input and display output and don't do any logic, yadda yadda) I am just missing the winforms knowledge for how to get this bit to work. When a connection to the database is lost - a frequent occu...

What would cause the current directory of an executing app to change?

I have a C# application that includes the following code: string file = "relativePath.txt"; //Time elapses... string contents = File.ReadAllText(file); This works fine, most of the time. The file is read relative to the directory that the app was started from. However, in testing, it has been found that if left alone for about 5 h...

.NET enterprise application platform (same as JBoss to Java)

As a .NET developer I'm asking whether JBoss alternatives exist to be "more suitable for .NET development" as an enterprise application platform. Please do not make any suggestions, such as "make JBoss to expose WebServices"... Thanks. ...

Is there an easy way to implement LINQ to object with a DataContext?

I have a working LINQ to SQL model. I want to be able to use the same model but with a connection to a DataSet object, instead of SQL Server. I need to be able to query the model, modify fields, as well as do insert and delete operations. Is there an easy way to accomplish this? I noticed another question mentions a similar scenario,...

Setting Focus on a Control within a ControlTemplate in WPF

In an application I'm working on, we have a bunch of custom controls with their ControlTemplates defined in Generic.xaml. For instance, our custom textbox would look similar to this: <Style TargetType="{x:Type controls:FieldTextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Ty...

Best practices: .NET: How to return PK against an oracle database?

With SQLServer, it seems to be generally accepted that adding a SELECT SCOPE_IDENTITY() to the end of your insert is the best way to return the PK of the newly-inserted record, assuming you're using an auto-increment field for the pk. However, I can't seem to find the equivalent for Oracle. Best practice seems to be to use a sequence...

Simple .net portal. Easy to add new modules

I am writing a simple database with web access. I have previous experience with microsoft's (very!) old IBuySpy portal system. I am sure there must be something a bit more up to date I could use now! I want a simple light weight system that will allow my friend to have tabs with news and pictures etc, and it be easy for me to add tabs ...

MainSoft Grasshopper, .Net to Java

I just stumbled upon MainSoft's Grasshopper, which claims to cross-compile .Net ILM to Java bytecode. It seems to use the Mono implementation of the .Net libraries. All of the samples refer to web apps, but my requirement would be to cross-compile a .Net API (class library) to a Java API so that Java clients can use the API. Does anyone ...

Marshal C++ "string" class in C# P/Invoke

I have a function in a native DLL defined as follows: #include <string> void SetPath(string path); I tried to put this in Microsoft's P/Invoke Interop Assistant, but it chokes on the "string" class (which I think is from MFC?). I have tried marshaling it as a variety of different types (C# String, char[], byte[]) but every time I eit...

Doing a Cast Within a LINQ Query

Is it possible to do a cast within a LINQ query (for the compiler's sake)? The following code isn't terrible, but it would be nice to make it into one query: Content content = dataStore.RootControl as Controls.Content; List<TabSection> tabList = (from t in content.ChildControls selec...

Is it OK to use HttpRuntime.Cache outside ASP.NET applications?

Scott Hanselman says yes. Adding System.Web to your non-web project is a good way to get folks to panic. Another is adding a reference to Microsoft.VisualBasic in a C# application. Both are reasonable and darned useful things to do, though. MSDN says no. The Cache class is not intended for use outside of ASP.NET applications. I...

What information has been released regarding the .NET Framework 4.0?

As Microsoft seems to have started their trickle feed of information regarding .NET 4.0, I thought I'd ask the question as I'm sure there's more out there than I've spotted! What information has been released regarding the .NET Framework 4.0? ...

C# Windows Service - Handle Exception on Startup

I'm writing a series of Windows services. I want them to fail if errors are thrown during startup (OnStart). I had assumed that merely throwing an error in OnStart would do this, but I'm finding that instead it "Starts" and presents me with a message stating "The service has started, but is inactive. Is this correct?" (Paraphrase). H...

Is there a way to override ConfigurationManager.AppSettings?

I really want to be able to have a way to take an app that currently gets its settings using ConfigurationManager.AppSettings["mysettingkey"] to actually have those settings come from a centralized database instead of the app.config file. I can make a custom config section for handling this sort of thing, but I really don't want other d...

Create JSON with .net

First off, let me start off that I am not a .net developer. The reason why I am asking this question is that we rolled out our REST-API and one of our first integration partners is a .net shop. So basically we assumed that .net would provide some sort of wrapper to create JSON, but the developer in question created the string by hand. I...

Managed C++ Assembly Attributes

Is there a way to add assembly attributes to a Managed C++ assembly? IE, specifically in C# in the AssemblyInfo.cs file, you'd typically have something like this: [assembly: AssemblyTitle("Some Assembly")] I have a private assembly attribute that I want to add (not one of the version attributes that could be added through a resource f...

How to make a Windows Forms .NET application display as tray icon?

What needs to be done to have your .NET application show up in Window's system tray as icon? And how do you handle mousebutton clicks on said icon? ...

How to relate objects from multiple contexts using the Entity Framework

I am very new to the entity framework, so please bear with me... How can I relate two objects from different contexts together? The example below throws the following exception: System.InvalidOperationException: The relationship between the two objects cannot be defined because they are attached to different ObjectContext o...

Issue with XDocument and the BOM (Byte Order Mark)

Is there any way to output the contents of an XDocument without the BOM? When reading the output with Flash, it causes errors. ...