Groups | Blog | Home
all groups > sql server reporting services > january 2005 >

sql server reporting services : How to display an image from custom assembly


billd
1/22/2005 5:55:02 PM
I am trying to display a chart from the Dundas chart library via a custom
assembly.

I followed Robert Bruckner's method (below) from a previos thread in this
news group. The chart displays fine in the designer preview, but appears as
an 'X' image when deployed to the report server.

I'm pretty sure I've copied the .dlls to the right spot and added the
references correctly. I am able to display simple text from my assembly into
a text box when deployed to the server ... but not an image.

Has anyone been able to display a Dundas chart via a custom assembly? Are
there specific Code Access Security Settings for the Dundas .dll that must be
set in the Rept Svcs config file?

Thanks,
Bill

-----------------------------
From Robert Bruckner:

Please try this:
* Add an image to your report
* Set the image type to Database
* Set the image mimetype to e.g. image/png
* For the image value use an expression like
=MyCustomAssembly.GenerateChart()

Note: your custom assembly call has to return the image as byte[].
Here is a code snippet which should convert the Dundas chart output into a
byte array:

public static byte[] GenerateChart()
{
// chart rendering code
...

// save chart image to byte[]
System.IO.MemoryStream renderedImage = new MemoryStream();
dundasChart.ImageType = ChartImageType.Png;
dundasChart.Save(renderedImage);
renderedImage.Position = 0;
return renderedImage.ToArray();
}
Robert Bruckner [MSFT]
1/26/2005 7:41:35 PM
There can be several issues here. The first thing I would check is that your
custom assembly works correctly in the "stand-alone preview" of report
designer:
* Load the report project in report designer.
* Hit F5 (to startup the stand-alone preview and run the report)

If the report does not work there, then missing security permission asserts
in rsPreviewPolicy.config as well as in rsSrvPolicy.config cause the issue.
If you are using the Dundas chart library your custom assembly will need to
have Fulltrust permissions and assert these security permissions before
invoking any Dundas API methods and properties.

The static function call in the custom assembly would need to look like this
when asserting the permissions through attributes (C#):

[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
public static byte[] GenerateChart()
{
// chart rendering code
// ...

}

In addition you need to add the FullTrust permissions in the config files.
Make sure to have them in the correct location inside the config files -
position matters!

<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="MyNewCodeGroup"
Description="A special code group for my custom
assembly.">
<IMembershipCondition
class="UrlMembershipCondition"
version="1.0.0.0"
Url="C:\MyCustomAssembly.dll"/>
</CodeGroup>

See also:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/dngrfCodeAccessSecurityInSQLServer2000ReportingServices.asp


HTH,
Robert

--
This posting is provided "AS IS" with no warranties, and confers no rights.



[quoted text, click to view]

billd
1/27/2005 8:33:02 AM
Thanks Robert. I got it working ... sort of.

I added the codegroup below to the rssrvpolicy.config file. (I got the blob
for the control via secutil -hex -s DundasWebGauge.dll)

<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="DundasGauge_Strong_Name"
Description="This code group grants Dundas gauge assembly. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="00240000048000009400000006020000002400005253413100040000010001007900AC08414E1C4AF3910919D020AD041966F2F8DF512B15187D2E7CEC6FB25FF8CBD08B10E1BF7A602AD4B7D8B597F64160A06924BD445CEDD06FA9D866C9D5F78DEE2E15351035D01869E8F67CE717AD291A3125192EA97E2619330831E5851B5487243A8ED9F8798B3021758A8EA0CCB37E84B4E9E33D3E417C5521500DD3"/>
</CodeGroup>

After putting this entry in and setting the security asserts, the dudas
image appears. However, it seems pretty quirky. After I re-deploy the report
or re-copy the custom assmbly to the rept. svcs. bin directory, I need to
close the Report Manager and re-open it and then hit refresh a few times
before the image finally appears.

- Bill

[quoted text, click to view]
billd
1/29/2005 10:57:02 AM
Robert,

I just need to add a reference to my custom assembly?

Is there no need to add a "fulltrust" entry for the Dundas .dll in the
report services configuration file? (I am using the Gauge library)

Thx,
Bill



[quoted text, click to view]
Robert Bruckner [MSFT]
1/29/2005 1:50:02 PM
If you are working based on RS 2000, the policy files contain already a
Fulltrust entry for the Dundas chart control. If the Dundas Gauge library
has the same public key blob, then it will also get Fulltrust privileges. If
the library uses a different public key blob, you need to explicitly add
Fulltrust permissions to the configuration files.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]

billd
1/29/2005 2:41:02 PM
Thanks. This is a tricky process. I was able to get a gauge to appear in a
deployed report on one development computer, but not on any others. They all
work fine in preview mode. The config files are identical on all machines.

Odds are that it is a securty problem. But are there logs (or any other
indicatior) that will give me information of what is going wrong beyond just
seeing the broken image icon?

Regards,
Bill


[quoted text, click to view]
Robert Bruckner [MSFT]
1/29/2005 6:34:27 PM
Just to confirm - with "preview mode" you mean the stand-alone preview (F5),
right? If it does not work in the stand-alone preview than you could use
these steps to track down security exceptions:
http://msdn.microsoft.com/library/en-us/RSPROG/htm/rsp_prog_rdl_8wyq.asp

What are the differences between the machine that works and the others that
don't? Same OS? Same IIS? Same network/firewall configuration? Do any of the
machines have computer names that contain characters like "_"? On the
machines where the reports won't work, do trivial reports work correctly
that contain just an image?

You may want to try the following on one of the machines where it does not
work:
* run iisreset and then navigate to http://localhost/reports
* launch Visual Studio .NET 2003 and open your custom assembly project
* set breakpoints inside your custom assembly code
* attach the VS debugger to aspnet_wp.exe (IIS5) or w3wp.exe (IIS6)
make sure to check the option that the debugger is invoked when a CLR
exception is thrown
* run the report and watch for SecurityExceptions; also look into the VS
output window

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]
AddThis Social Bookmark Button