{"id":1026,"date":"2010-08-04T17:10:23","date_gmt":"2010-08-04T15:10:23","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/index.php\/cas-net-4-0-repostviewer"},"modified":"2010-08-04T17:10:23","modified_gmt":"2010-08-04T15:10:23","slug":"cas-net-4-0-and-rdlc-reportviewer","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/cas-net-4-0-and-rdlc-reportviewer","title":{"rendered":"CAS .NET 4.0 and RDLC ReportViewer"},"content":{"rendered":"<p>In .NET 4.0 Code Access Security (<strong>CAS<\/strong>) has been deprecated.<\/p>\n<p>Well I never liked CAS very much, so it&#8217;s definitely a good thing!<br \/>\nUnfortunately because of that some things are done differently now (in .NET 4.0).<\/p>\n<p>Especially when you use <strong>RDLC ReportViewer <\/strong> control.<\/p>\n<p>If you need to use your assembly in ReportViewer (like for example <a href=\"\/barcode\">Barcode.dll barcode component<\/a>) you need to follow this steps:<\/p>\n<p><strong>1.<\/strong><\/p>\n<p>First make sure that your assembly (Barcode.dll) is registered in GAC (Barcode.dll installer does that).<br \/>\nYou can use:<br \/>\n<code>gacutil -l Barcode <\/code><br \/>\nto check, and<br \/>\n<code>gacutil -i Barcode.dll <\/code><br \/>\nto register.<\/p>\n<p>As Code Access Security was deprecated you have to options:<\/p>\n<p><strong>2a.<\/strong><\/p>\n<p>You can add NetFx40_LegacySecurityPolicy entry in your App.config file:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;\n&lt;configuration&gt;\n &lt;runtime&gt;\n   &lt;!-- enables legacy CAS policy for this process --&gt;\n   &lt;netFx40_LegacySecurityPolicy enabled=&quot;true&quot; \/&gt;\n &lt;\/runtime&gt;\n&lt;\/configuration&gt;\n<\/pre>\n<p>and use this code (it is used in samples in Form1_Load method):<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C#\n\nthis.ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(\n  Assembly.GetExecutingAssembly().Evidence);\nthis.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain(\n  &quot;Barcode, Version=2.0.0.20, Culture=neutral, PublicKeyToken=6dc438ab78a525b3&quot;);\nthis.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain(\n  &quot;System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;);\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET\n\nMe.ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain( _\n  Assembly.GetExecutingAssembly().Evidence)\nMe.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain( _\n  &quot;Barcode, Version=2.0.0.20, Culture=neutral, PublicKeyToken=6dc438ab78a525b3&quot;)\nMe.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain( _\n  &quot;System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;)\n<\/pre>\n<p>or the second approach which is <strong>easier<\/strong>:<\/p>\n<p><strong>2b.<\/strong><\/p>\n<p>Use the following code in Form1_Load method:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C#\n\nPermissionSet permissions = new PermissionSet(\n  PermissionState.Unrestricted);\nthis.ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(\n  permissions);\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET\n\nDim permissions As New PermissionSet( _\n  PermissionState.Unrestricted)\nMe.ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain( _\n  permissions)\n<\/pre>\n<p>You can find samples how to use Barcode.dll with RDLC in C#, VB.NET in Windows Forms and ASP.NET in the <a href=\"\/barcode\">Barcode.dll download package<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In .NET 4.0 Code Access Security (CAS) has been deprecated. Well I never liked CAS very much, so it&#8217;s definitely a good thing! Unfortunately because of that some things are done differently now (in .NET 4.0). Especially when you use RDLC ReportViewer control. If you need to use your assembly in ReportViewer (like for example [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1026","post","type-post","status-publish","format-standard","hentry","category-mail-dll"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1026"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=1026"}],"version-history":[{"count":0,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1026\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}