Thursday, July 5, 2012

Request for the permission of type "System.DirectoryServices failed"


I created a ssrs report with custom dll execution. The custom dll would retrieve the active directory groups of the report user. Code of custom dll function was:

// Get groups of user with specific prefix and extract the store information
public static List GetStoresSecurity(string groupprefix, string userName)
{
List result = new List();
// establish domain context
PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);
// find your user
UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, userName);
// if found - grab its groups
if (user != null)
{
PrincipalSearchResult groups = user.GetAuthorizationGroups();
// iterate over all groups
foreach (Principal p in groups)
{
// make sure to add only group principals
if (p is GroupPrincipal)
{
if (p.Name.StartsWith(groupprefix))
{
result.Add(p.Name.Replace(groupprefix, ""));
}
}
}
}
return result;
}

When I deployed the report I added to rssrvpolicy.config the following permission assign (ReportFunctions.dll contains my function):

<CodeGroup>

class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Report Functions"
Description="This code group grants full permissions to directory functions ">
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSRS10_50.R2\Reporting Services\ReportServer\bin\ReportFunctions.dll"
/>
</CodeGroup>

When I tried to execute the report I got the error: Request for the permission of type "System.DirectoryServices failed". This was a permission error and the way I found to overpass it was to give full trust to .net assemblies. The way to do this was to edit again rssrvpolicy.config and make the following change:

<CodeGroup>

class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Report_Expressions_Default_Permissions"
Description="This code group grants default permissions for code in report expressions and Code element. ">
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100512C8E872E28569E733BCB123794DAB55111A0570B3B3D4DE3794153DEA5EFB7C3FEA9F2D8236CFF320C4FD0EAD5F677880BF6C181F296C751C5F6E65B04D3834C02F792FEE0FE452915D44AFE74A0C27E0D8E4B8D04EC52A8E281E01FF47E7D694E6C7275A09AFCBFD8CC82705A06B20FD6EF61EBBA6873E29C8C0F2CAEDDA2"
/>
</CodeGroup>

Tuesday, May 29, 2012

Remotely Working and Debugging SharePoint 2010 Solutions

How to remotely debug a custom webpart on sharepoint 2010? The task is not easy but if its absolutely necessary for your project then you should follow the steps analyzed in this article. If the solution provided for remote debugging is too hard then you can always install visual studio on the same machine as sharepoint, to avoid all the trouble...

Friday, May 25, 2012

Timeout expired on Dynamics CRM 4.0

Today I got a timeout expired error when calling a query to dynamic crm (from web service). I saw the query from trace and I when I executed it from sql server it elapsed 31 seconds. The problem was that the default timeout of sql queries in Microsoft Dynamics CRM 4.0 is 30 seconds.
This timeout can be overriden from registry by adding a DWORD value with the timeout time in seconds to the following registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\OLEDBTimeout]

Good reference of timeout specifications can be found here

Tuesday, May 22, 2012

Pass multivalue parameter to drillthrough report


Recently I had a request to create a drillthrough report for an aging report (actually 5 reports). I had 2 choices. One to create 5 reports or two to make one with multivalue parameters (each one of the parent reports must pass different values witch were static). Of course I decided to follow the second option. In order to do that I created the desired parameter in the parent report and I set it as multivalue and as internal.



Next I set the available values, and I set the same values and as defaults




Finally on the textbox witch I wanted to trigger the drillthrough action I inserted the parameter (OrderStatus is a multivalue parameter of the drillthrough report)




The text exression of the parent parameter was



Running Unit Tests From Network Drive

I used visual studio 2010 to create some unit tests for a custom application and I got the following error message "Error loading U:\Visual Studio 2010\Projects\LoyaltyViewer\LoyaltyViewerTest\bin\Debug\LoyaltyViewerTest.dll: Could not load file or assembly 'file:///U:\Visual Studio 2010\Projects\LoyaltyViewer\LoyaltyViewerTest\bin\Debug\LoyaltyViewerTest.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)". I googled the problem and what I found what the problem was. It appeared that visual studio could not load the assembly from a remote drive. To fix the problem, I followed the instructions from this post. The workaround is to create set COMPLUS_LoadFromRemoteSources=1.


Open a command prompt and type "setx COMPLUS_LoadFromRemoteSources 1"

or

Create an environment variable named COMPLUS_LoadFromRemoteSources
Set the value to 1