Using mathnet-numerics as CLR assembly in SQL Server - sqlclr

Has anyone successfully used MathNet.Numerics as a CLR assembly in SQL Server?
Using SQL Server 2012 on Windows 8, I've managed to do a CREATE ASSEMBLY pointing at the DLL but when I try to do
CREATE TYPE Normal EXTERNAL NAME MathNetNumerics.[MathNet.Numerics.Distributions.Normal]
I get an error message:
"does not conform to the UDT specification: missing custom attribute
Microsoft.SqlServer.Server.SqlUserDefinedTYpeAttribute".

It seems that you cannot use arbitrary .Net code in SQL CLR but have to develop specifically for it, by decorating your code with attributes like SqlFunction and using its own special types like SqlDouble instead of just System.Double.
Nevertheless, I'd expect you can write a small wrapper/adapter .Net library and then reference and call Math.NET Numerics routines from there.

Related

Referencing Microsoft.AspNetCore.Http.Abstractions causes a higher version referenced exception on System.Runtime

I'm trying to reference AspNetCore.Http.Abstractions in a .Net Standard 2.1 library with version=3.1.0 being the latest as of writing, however, I'm getting a higher version than referenced exception thrown at compile-time.
I have tried explicitly stating the FrameworkRuntimeVersion in my project file, added a reference to the latest System.Runtime on nuget, even tried to force an update in the app.config. I can't believe it's this difficult to explicitly force the .Net Standard library to use a higher version.
The exception:
The solution was simple.
I changed the class library to rather target the full .Net Core 3.1 rather than relying on .Net Standard 2.1

Word-VBA Functions "Method Saveas2 of object failed"

I have an access-vba application that also makes use of word-vba. While running the application on my local machine, it functions well. Once it is moved to others (same versions of access and word) it will crash when it comes to the vba portion of word. Commands such as document.open or .saveas2 fail: Method 'SaveAs2' of object failed for example.
I've also noticed that libraries that I've referenced in the application are required by any other end user. I'm used to just compiling with the libraries and from that point they are always included in the .jar/.exe/etc, but, it seems when you move the application to other's computers it's always trying to recompile?
I'm not well versed in VBA so I'm speculating that my failing word-vba functions are because of a referencing error, any other ideas?
The "libraries" that VBA can reference are actually COM objects, usually packaged as DLL files. They are objects which are dynamically instantiated at runtime (if they aren't already) when requested. They are loaded by Windows into memory and your program uses the COM standard to interact with them, calling methods and getting or setting properties (interprocess communication). There are generally two ways of interacting with them: early binding and late binding.
With early binding, you add a reference to the library while you are still writing code, which allows the VBA IDE to provide autocompletion and some compile-time error checking. You instantiate objects with the "new" keyword and by directly typing the object name. However, early binding requires that you select a specific dll and possibly a specific version of the interface. This can lead to issues if you reference a specific interface version which one of your users doesn't have.
With late binding, you instantiate objects using CreateObject or GetObject, requesting them by name from Windows. Windows will look the name up and return a reference to the object. The variables in your code are simply objects and calling methods is a bit dangerous because the compiler allows you to type in whatever method name you want and provides no compile-time warnings. This has the advantage that as long as you are calling well established methods and nothing new or deprecated, the code will work regardless of the user's version.
As for the error you are getting, you may want to check the version of Office on the user machines - SaveAs2 was added in Office 2010.

WebGetAttribute what should I reference

I'm building a WCF WindowsService in .NET 4.0. I'd like to make it RESTfull and change the response and request type to JSON. To do that I need to use the WebGetAttribute under the OperationContract in the interface. But I can't find the System.ServiceModel.Web assembly (which is supposed to be in a System.ServiceModel.Web.dll according to MSDN). There's no trace of that DLL in the Add Reference form and if I try "using System.ServiceModel.Web;", it's not working either.
Do you have any idea what my problem is ?
Starting with .NET Framework 4, you should no longer need to reference System.ServiceModel.Web.dll at all. The article is outdated, as starting with .NET Framework 4, all classes in System.ServiceModel.Web.dll simply forward to classes in System.Runtime.Serialization.dll and System.ServiceModel.dll.
So, my point is -- as long as you're NOT using the Client Profile of the .NET Framework -- just refer to System.Runtime.Serialization.dll and System.ServiceModel.dll, and you should be set.
Well, turned out I was targeting ".NET Framework 4 Client Profile" which doesn't exposes all the DLLs. Thanks to this post. Changed it to ".NET Framework 4" and everything's OK.

Rails ActiveSupport::JSON causes Illegal Instruction error

I'm trying to encode something in my rails project into JSON, but it seems like any call to any JSON API in Rails causes WEBrick to throw a "Illegal Instruction" error.
My code was:
#nodes = Node.all
j = ActiveSupport::JSON
#json = j.encode(#nodes)
I don't understand why I get this error. Can someone please help?
Not sure if this is relevant, but I'm also using mysql2spatial adapter because my Node class contains a field with type GEOMETRY (mysql spatial extensions).
Thanks!
The JSON gem requires compiled extensions, so it's possible that your version isn't compiled for the architecture or OS you're currently using. You may want to re-install it and see if that resolves the problem.
Ruby itself rarely throws exceptions, but compiled extensions do this much more frequently, especially if compiled against a different set of system libraries.

Missing Linq namespaces (Linq to sql, compact framework)

I spent this morning in trying to figure out where the system.linq.expressions namespace is. The following is what I did:
In VS 2008, Create a new C#/Smart Device/Windows Mobile 6 Professional SDK/.NET CF v3.5/Class Library
Used SqlMetal (in Program Files/Microsoft SDKs/Windows/v6.0A/Bin) to generate the data context.
Added the data context .cs file into the project.
Compile and many errors for missing namespaces: System.Data.Linq, System.Data.Linq.Mapping, System.Linq.Expressions
After some research added System.Data.Linq.dll in c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 (The dll was not directly listed when I choose to add reference and I used "browse" tab to finally located the one, which is for normal framework)
Compile again, less errors, but still System.Linq.Expressions namespace is missing.
The document says System.Linq.Expressions is in System.Core.dll but it seems my System.Core.dll (located in Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE) contains much less namespace than document says.
Thanks in advance!
The Compact Framework does not support LINQ to SQL. All objects in the documentation for System.Data.Linq confirms this by being completely devoid of the "supported in the CF" icon. For example, look over at the docs for DataTable, which is supported. You'll see a little icon by each supported method/property.
You cannot "add" support by simply referencing a desktop assembly like you did in your step 5. The CF cannot consume full framework assemblies, for a variety of reasons.
Dynamic code generation (Reflection.Emit) is not available in NETCF. What this means is that a lot of features that depend on this is not available, this includes DLR (dyanmic language runtime and hence languages like IronRuby), Linq-to-SQL/
If you just want the Linq.Expressions and you are doing your own stuff with it i.e. not trying to get linq to sql working then you can use the System.Linq.Expression stuff from the db4o guys.
I am using it on my project using linq to objects.
db4o linq implementation