Hi there,
A simple question I hope. I have got a textbox on a report and I'm trying to populate it by calling a custom assembly. I know I can reference it directly in the textbox (this works) but I am trying to do this from the code block. The following code didn't work:
Protected Overrides Sub OnInit()
ReportItems!textbox2.Value = POCCustomAssembly.CustAssembly.Hello()
End Sub
The TextBox is called textbox2 and the custom assembly simply returns a string.
I get an error message "The is an error on line 1 of custom code: [BC30469] Reference to a non-shared member requires an object reference".
What am I doing wrong?
Hi,
I know you submitted this months ago...but I was wondering if you found the solution to your problem? I essentially am trying to do the exact same thing and can't figure out the error. I would appreciate any help.
|||The error message you're getting suggests that the code wouldn't even work in the textbox value property, although the message could be wrong and misleading.
Is the method you have in your assembly "Shared" (VB) or "static" (c#)?
If not, try to make it shared/static. If that's not possible to do,
you can add objects to the report in Report > Report Properties > References > Classes
add the class name and your desired instance name for the object. Then you can use this instance name in your custom code.
|||Thank you for the responose. Here is my code:
I basically wrote an assembly to calculate percentages and handle situations to divide by zero.
namespace Calculations
{
public class calcPercentage
{
public decimal Percentage(decimal decValueOne, decimal decValueTwo)
{
decimal decPercentage = 0;
if (decValueOne == 0 || decValueTwo == 0)
{
decPercentage = 0;
}
else
{
decPercentage = (decValueOne - decValueTwo) / decValueOne;
}
return decPercentage;
}
}
}
Then in my textbox I put:
=Calculations.CalcPercentage.Percentage(SUM(Fields!PreviousYTDExpenseAmount.Value, "Template_OutputData_Sales"), SUM(Fields!PreviousYTDExpenseAmount.Value, "Template_OutputData_CGS"))
I referenced the assembly and added it to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies and I still get that error message so I do not know what the problem is.
Then after carefully reading your response, I realized I didn't write "static" in my method even though that's what I meant it to be. Now the program builds successfully but when I run it and try to produce the PDF file it catches on error when it tries to render it as a PDF. Now to figure out that error...which I will save for tomorrow....I must have screwed something up in the process.
Thanks so much for you help! If you have any suggestions about my next error...i'm all ears!
|||Also, when I removed the assembly from my report and reran it they worked fine...so if you have any suggestions let me know.|||
I cannot get the report to render to design mode while using a custom assembly. As soon as I remove the assembly, it works just fine. can anyone suggest what might be the problem? All my code is listed above and what steps I have already taken.
Thanks!
|||Any custom assemblies used for SSRS must be declared SHARED for VB or STATIC for C#.
So for instance:
vb sample:
Public Class Class1
Public Shared Function CallMeIshmal() as string
Return "Call Me Ishaml"
End Function
Any other functions or subs must also be declared as Shared or Static.
You also need to either add the compiled dll to the GAC or copy it to the reportserver and reportbuilder directories.
You may also need to modify the reportserver.config file for permissions.
this link:
http://support.microsoft.com/default.aspx/pwebcst
has a list of webcasts, the first one is about using custom assemblies in SSRS>
Daryl
No comments:
Post a Comment