|
-
June 29th, 2010, 12:26 PM
#1
Problem with Read method in dll
Hi, I have problem with the List in Read method, in this line: sum += intermediateResult[i]; I have error:
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException:
at Concatenate.Terminate()
My list is still empty, I do not know how to properly write read method for the list:
Code:
[Serializable]
[SqlUserDefinedAggregate(
Format.UserDefined,
MaxByteSize = 8000)
]
public class Concatenate : IBinarySerialize
{
private List<double> intermediateResult;
private int count;
public void Init()
{
count = 0;
this.intermediateResult = new List<double>();
}
public void Accumulate(double? value)
{
if (value != null)
{
this.intermediateResult.Add((double)value);
count++;
}
}
public void Merge(Concatenate other)
{
}
public SqlDouble Terminate()
{
double sum = 0.0;
for (int i = 0; i < this.count; i++)
sum += intermediateResult[i];
return new SqlDouble(suma);
}
public void Read(BinaryReader r)
{
count = r.ReadInt32();
// for(int i=0; i<14; i++)
// intermediateResult[i] = r.ReadDouble();
}
public void Write(BinaryWriter w)
{
w.Write(count);
w.Write(intermediateResult.Count * sizeof(double));
}
}
In sql server :
Code:
CREATE ASSEMBLY zzz AUTHORIZATION dbo
FROM 'C:\library.dll'
WITH PERMISSION_SET=SAFE
GO
CREATE AGGREGATE aaa(@value float) RETURNS float
EXTERNAL NAME zzz.Concatenate
GO
SELECT dbo.aaa(height) as height FROM People
-
June 29th, 2010, 03:55 PM
#2
Re: Problem with Read method in dll
Why dont you have your "Init" Method called in the constructor. From the code I see init will never be called, and therefore intermediateResult will always be null, which is exactly what the exception is telling you.
Why dont you put a break point on that line then hover your mouse over that variable and see that it is indeed null, it must be since it is the only thing there that can possibly be null.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|