Context.CurrentMiningModel returns null in UDF

Freelance Jobs

I migrated Mining Structures from a 2008 server to a 2012 server. When I try my CLR UDF (which is working fine on SQL server 2008) in a DMX query on the 2012 server, I am getting this error:

Exception has been thrown by the target of an invocation. Object reference not set to an instance of an object.

My original goal was to get the GetNodeDescription(...) method running. While debugging the problem, I could isolate the problem to this UDF which fails on my SQL server 2012

public static string test()
  return Context.CurrentMiningModel.Name;

My guess is that CurrentMiningModel is null because the following code works fine

public static string testUser()
 return Context.CurrentConnection.User.Name;

Any Idea on how to solve this? Is somebody out there who can reproduce this?



UPDATE: A contact at Microsoft confirmed this behaviour as desired due to a "Metadata-Refactoring" (whatever this means...). However, the website still pends to be updated appropiately.

2012-04-02 10:40:28 Scores:2

1 answer

Answer 1

This is not the ultimate answer but it's a workaround to get Microsoft's GetNodeDescription working (by explicitly providing the mining model):

public static string GetNodeDescription(string MiningModel, string nodeUniqueName)  
  if (Context.ExecuteForPrepare)  
    return string.Empty;  
  return Context.MiningModels[MiningModel].GetNodeFromUniqueName(nodeUniqueName).Descript‌​ion;  
jahu H
2012-04-24 10:11:41
Share |
View original post at

Related topics

c#: PropertyInfo.GetValue(null, null) returns null

i have a class with a static public property called "Info". via reflection i want to get this properties value, so i call: PropertyInfo pi myType.GetProperty("Info"); string info = (string) pi.GetValue(null, null); this works fine as long as the property is of type string. but actually my property is of type IPluginInfo and ...

MethodInfo.Invoke sometimes returns null and sometimes returns value

I'm working on an MVC application. I have a class that wraps a repository that fetches data from a db using simple linq statement. I've written a decorator class to add caching logic (using caching application block). since I have several methods that I want to decorate, and the logic is ...

How can this Ambient Context become null?

Can anyone help me explain how TimeProvider.Current can become null in the following class? public abstract class TimeProvider { private static TimeProvider current = DefaultTimeProvider.Instance; public static TimeProvider Current { ...

Socket.bind() returns "The requested address is not valid in its context." on Win7

I am trying to use the Socket.bind() function this way: Bind(new IPEndPoint(myInternalAddress, myPort)); The error I am getting is "The requested address is not valid in its context.", but this only happens on Windows 7 (I am using 64 bit). Befor my upgrade a few days ago this was working fine, and I ...

C# XPathSelectElement returns null

I am trying to use the XPathSelectElement method of the System.Xml.XPath namespace but for some reason it always returns null, and I have no idea why. Here is the code: TextReader stream = new StreamReader("config.ini"); XmlReader reader = XmlReader.Create(stream); XElement xml = XElement.Load(reader); XElement file = xml.XPathSelectElement("Config/File"); Here is the XML file it is trying to ...

Why Control.FromHandle(IntPtr) returns null in one hooked process and returns valid object of "Form"? in another hooked process?

I am facing a problem related to get out all the controls from some hooked process. My SpyDll launched into hooked process sucessfully, But when I check the statement Control control = Control.FromHandle(MainWindowHandle), it returns null into control object where "MainWindowhandle"is just a native main window handle of that ...

what is meaning of (model!=null) and (db!=null) in this context

public bool SetupEmpty(UserViewModel model, SimsContext db) { if (model != null && db != null) { // Setup the User model.User = new T2.Models.User(); ...

ExtractAssociatedIcon returns null

I'm using the ExtractAssociatedIcon method to retrieve the icon for the file. My hope is to retrieve the same icon that a user would see in their explorer window. public static Icon GetIcon(string fileName) { try ...

Testing for null reference always returns false... even when null

If I compile the following code snippet with Visual C# 2010 I ALWAYS get false: object o = null; Console.WriteLine("Is null: " + o == null); // returns false Does anybody know why??? ...

Entity Framework returns null object when row has null values

I have an existing database (which I cannot modify in any way) that I'd like to use EF to code against. There are no primary keys, foreign keys or actual relationships between tables - everything seems to be handled by applications using the DB. For most of the tables/entities, ...