The best debugging tool for debugging custom assemblies, no surprise, is Visual Studio. There are two debugging options:
Debugging with a single instance of Visual Studio ( DebugLocal method) requires several setup steps:
Running the GetLibraryInfo() example that was developed earlier in the chapter did not create any issues when you ran it in preview mode (Report Preview tab). This is because preview mode does not enforce security permissions. Let's try to run GetLibraryInfo() in DebugLocal mode. Visual Studio breaks on the GetExecutingAssembly() call and shows an exception: System.Security.SecurityException was unhandled by user code Message="Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." So, what happened with your code and why didn't it work? First, you have to check if the configuration was properly set. Reading of the configuration file was discussed earlier, but GetLibraryInfo() does not really read a configuration file. All it does is call the GetExecutingAssembly() function. public static string GetLibraryInfo() { return Assembly.GetExecutingAssembly().GetName().ToString() + ( (mPeriod != -1) ? " Initialized with value=" + mPeriod.ToString() : " Not initialized " ); } The clue here is the fact that the assembly is trying to retrieve information about itself. So, it must mean that you need some kind of permission to that assembly file. Earlier in this chapter, you learned that the GetExecutingAssembly() requires the PathDiscovery permission. To configure Report Designer for debugging of this library, copy the library to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\ or, better yet, set an output path for the library in Visual Studio. In Solution Explorer, right-click the library project, select Properties, click the Build tab, and enter C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\ for the Output Path, as shown in Figure 23.8. Figure 23.8. Library Properties interface.The benefit of setting an output path is that Visual Studio realizes that it was using this library (through Report Designer) and, thus, is able to replace it. If Visual Studio compiles the library to an alternative location and a developer is trying to copy to the C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\ directory, afterward he might not be able to do that. This is because Visual Studio will be "holding" this library during and after debugging. Visual Studio will require restart so it can release the "hold" and so the library can be replaced . The next step is to create a <PermissionSet> with PathDiscovery permission in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\RSPreviewPolicy.config : <PermissionSet class="NamedPermissionSet" version="1" Name=" GetLibraryInfoPermissions " Description="A custom permission set to grant read access to a configuration file."> <IPermission class="FileIOPermission" version="1" PathDiscovery ="C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies" /> <IPermission class="SecurityPermission" version="1" Flags="Execution, Assertion" /> </PermissionSet> And in the same file, add the following: [View full width]
to this location: ... ADD HERE (before the second CodeGroup above the PolicyLevel) </CodeGroup> </CodeGroup> </PolicyLevel> The final step is to Assert the permission in the code, as follows : [View full width]
|