clr

Throwing Exceptions in SQL CLR Stored Procedures

Is it good design to throw exceptions from SQL CLR stored procedures? Since we are in the context of SQL Server, do any special considerations need to be made? Is this bad design? [Microsoft.SqlServer.Server.SqlProcedure] public static void MyStoredProcedure(string foo) { if (string.IsNullOrEmpty(foo)) { throw new Argum...

Have you ever used ngen.exe?

Has anybody here ever used ngen? Where? why? Was there any performance improvement? when and where does it make sense to use it? ...

Is there an updated version of "Writing Faster Managed Code: Know What Things Cost"?

The MSDN "Writing Faster Managed Code: Know What Things Cost" is pretty nice, but it was written for CLR v1 in 2003. Is there an updated version of this somewhere? ...

How to detect which .NET runtime is being used (MS vs. Mono)?

Hi, I would like to know during execution of a program whether it is being executed using the Mono runtime or the Microsoft runtime. I'm currently using the following code to determine whether I'm on a MS CLR: static bool IsMicrosoftCLR() { return RuntimeEnvironment.GetRuntimeDirectory().Contains("Microsoft"); } However, this ...

Why Must I Initialize All Fields in my C# struct with a Non-Default Constructor?

I would like to try this code: public struct Direction { private int _azimuth; public int Azimuth { get { return _azimuth; } set { _azimuth = value; } } public Direction(int azimuth) { Azimuth = azimuth } } But it fails on compilation, I understand that struct need to init all its fields...

Multidimensional arrays do not implement IEnumerable<T>, or do they?

For the reasons that I still do not understand (see this SO question) multidimensional arrays in CLR do not implement IEnumerable<T>. So the following does not compile: var m = new int[2,2] {{1, 2}, {3, 4}}; var q = from e in m select e; Then how come that this works just fine in VB.NET? Sub Main() Dim m(,) As Integer = {{1, 2}, ...

Is it possible to restrict rights of invoked external program to read only file operations?

I use the next code: ... ProcessStartInfo processStartInfo = new ProcessStartInfo(); ... Process process = new Process(); process.StartInfo = processStartInfo; bool processStarted = process.Start(); ... Is it possible in .Net to restrict rights of invoked external program to read only file operations? ...

After implementing fmod Visual C++ test strange behavior - All tests fail - Unable to get type.... Error: System.IO.FileNotFoundException - if certain line of code in one test

Ok, I've figured out what caused the problem but I still don't know why - it happened when I started using fmod, and it must have something to do with how the linker decides to bring in and execute static libraries and dll's. My code under test is a static lib; it refers to fmodex_vc, another static lib, which at some point (though I k...

What is a fault clause in the CLR exception system?

I was reading this article on handling corrupted state exceptions and I came across something that puzzled me. What is a fault clause? See quote from article below: An error condition can only pass from the function containing the unexpected condition to that function's caller. Exceptions have the power to pass the result...

Question(s) on implementing check constraints with SQL CLR integration.

I'm implementing 'check' constraints that simply call a CLR function for each constrained column. Each CLR function is one or two lines of code that attempts to construct an instance of the user-defined C# data class associated with that column. For example, a "Score" class has a constructor which throws a meaningful error message when...

.Net Web Service Memory Pressure Error

I have a web service I'm trying to use on one of my sites. When I call the web service (which is created in C#) I get an error on several lines where try to execute an SP, which was created as an assembly. This web service works on our development environment but not on live. Our live and dev environments run on the same server, but diff...

Why does the C# compiler explicitly declare all interfaces a type implements?

The C# compiler seems to explicitly note all interfaces it, and its base classes implement. The CLI specs say that this is not necesary. I've seen some other compilers not emit this explicitly, and it seems to work fine. Is there any difference or reason the C# does this? The MSIL that the C# at the bottom generates for B is: .class pr...

How to stop C#'s switch statement from generating the CIL switch instruction

C#'s switch statement can compile to a CIL switch instruction, or if/else's, depending on the cases in the statement as mentioned here. Is there a way to force the compiler to always generate the if/else variant in a block of code? ...

How can I add, delete, and update resources in CLR assemblies?

I've taken a long look around and can't find any information on altering managed resources in assemblies (note that I'm already familar with Win32 resources and the APIs for altering those). My application has resources that need to be updated by the end user and the application will be distributed as a single executable (so I can't jus...

.NET: with respect to AssemblyVersion, what defines binary compatibility?

What changes to a strong-named assembly necessitate a change in AssemblyVersionAttribute? Clearly, changing the public api in a way that could require a client to have to make a code change requires an increase in AssemblyVersion. But what about changes to the public API that don't require code changes in the client? For instance: the ...

How can I use the SqlFunctionAttribute in a database project to generate the SQL to deploy the functions myself? Visual studio fails.

Background: Visual studio fails at deploying a database project. It tries to drop functions that are already referenced (e.g. in a check constraint), rather than just adding the new ones and updating the existing ones, so the deployment always fails. As a result, I'm writing my own code to update the assembly and add/update any functi...

Erlang on a JVM/CLR

I've just started reading Joe Armstrongs book on Erlang and listened to his excellent talk on Software Engineering Radio. Its an interesting language/system and one whose time seems to have come around with the advent of multi-core machines. My question is: what is there to stop it being ported to the JVM or CLR? I realise that both vi...

Is it ok to load .net dlls into SQL Server as UNSAFE?

When creating a SQL Server CLR stored procedure, I noticed that I couldn't reference anything in the .net framework as I would normally. After some reading around, I realised that assemblies needed to be loaded into the database first. Therefore, I loaded in the ones I need but due to P/Invoke had to use the UNSAFE permission set. I...

Why doesn't SQL Server come preinstalled with .net Framework for CLR Integration?

If I want to reference something in the .net framework for use in my CLR stored proc, for example, I have to first load it into the Sql server database. Why isn't it preinstalled? Is it performance related or for security issues or what else? thanks. ...

Resolve CLR Type from DataContract.Namespace?

Hello, I'm a newbie whitebelt with WCF. I have a namespace: http://schemas.datacontract.org/2004/07/System/ArgumentException. I'm looking to take that string and convert it into a CLR type so that I end up with typeof(ArgumentException). Is this possible? :) Thank you, MichaelD ...