Switching to a new framework can be fun at times.
This time I had a little problem with the Reportviewer.
Report execution in the current AppDomain requires Code Access Security policy which is off by default in .NET 4.0 and later. Enable lagacy CAS policy or execute the report in the sandbox AppDomain.
I like the and later part.
Here is the printscreen, just in case you don’t believe me.
Solving this took some time. Finding out that they changed this is easy. Finding out how to solve it is a little less documented.
In the end I found that it is this line that caused the problem.
_PreviewForm.Viewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("rbarcode20, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
Well to be honest it had a green squigle underneath it to say that AddTrustedCodeModuleInCurrentAppDomain was deprecated and that I had to use AddFullTrustModuleInSandboxAppDomain all the time. But I thought it was just trying to annoy me.
So I changed it to this.
Dim asm = Assembly.Load("rbarcode20, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
Dim asm_name = asm.GetName()
_PreviewForm.Viewer.LocalReport.AddFullTrustModuleInSandboxAppDomain(New System.Security.Policy.StrongName(New StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken), asm_name.Name, asm_name.Version))
which was based on this.
I find it weird that you have to give it a StrongName while the assembly is not Strongly named. For version 5 I would like an extra overload for AddFullTrustModuleInSandboxAppDomain that takes a string (TIA)