CRM 2015 OnLine - Request for the permission SecurityPermission failed - dynamics-crm-online

I'm trying to generate a PDF in memory to send it to a WS. This PDF should be created in memory (Stream) and in the Microsoft CRM "cloud" in a plugin code.
Is this possible?
In the plugin (already coded and deployed) I have this lines, the 3th fails
PdfDocument pdf = new PdfDocument();
PdfPage pdfPage = pdf.AddPage();
XGraphics graphics = XGraphics.FromPdfPage(pdfPage); //<-- ERROR
is this line of code trying to access a resource in the cloud that is not permitted/available?
this is the error:
Unexpected exception from plug-in (Execute): Plugins8.Plugin: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
any ideas?

I assume you are using PDFsharp and you have its libraries merged into your plugin assembly using ILMerge.
If so, the SecurityException can be caused by PDFsharp using GDI+. In partial trusted app domains drawing graphics with GDI+ is not allowed. You can however compile PDFsharp for WPF. Try compiling PDFsharp with directives WPF plus (maybe) SILVERLIGHT.

Related

HTTP Error 500.0 - Internal Server Error, AspNetInitializationExceptionModule VS 2015

After running some NuGet Updates my project will not run locally throwing "HTTP Error 500.0 - Internal Server Error" and referencing Handler "AspNetInitializationExceptionModule"
I'm using VS 2015, .NET Framework 4.6.1, Any CPU, IISExpress.
The refered link suggests I look into the IIS Logs which are full of data but there seems to be no information for these eyes.
I Understand that 500.0 is the server shouting that something generic went wrong but frankly I don't know what to try next.
Any thoughts?
Frustrated in New Hampshire.
More info
adding a vanilla favicon.ico still resulted in 500.0 but now just at the root.
HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
(XHR): GET - http://localhost:3029/
Drilling into Eventviewer/Custom Views/Summary page events I found an ASP.NET 4.0.30319.0 Warning.
At the bottom of the warning detail it says
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) Could not load file or assembly 'Microsoft.AI.Agent.Intercept' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
http://localhost:3029/
So my Nuget Update incorrectly updated Microsoft Application Insights.
Uninstalled it and now I'm back to earning a living.
It seems that when IIS knows it has an exception it should tell the browser.
Pat NH USA

Intermittent "Could not load type 'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter'" Error

I am working on a project that includes an ASP.NET WebAPI component.
Intermittently, I get the following error:
Could not load type
'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from
assembly 'System.Net.Http.Formatting, Version=5.2.3.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
with the source error pointing to my GlobalConfiguration.Configure() call:
Line 35: {
Line 36: AreaRegistration.RegisterAllAreas();
Line 37: GlobalConfiguration.Configure(WebApiConfig.Register); //<-- error here
Line 38: FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
Line 39: RouteConfig.RegisterRoutes(RouteTable.Routes);
In my register, I am doing the following to return JSON by default:
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes
.FirstOrDefault(t => t.MediaType == "application/xml");
if (appXmlType != null)
{
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
(not sure of the source, but found somewhere on this site as a way to return JSON by default, unless the caller asks for something else)
I'd like to continue to return JSON as the default content type going forward.
The project includes two other (non WebAPI) websites (that are MVC5), which hit the WebAPI site.
Here's the interesting thing:
This DOES NOT happen when the application is deployed (to Azure)
This only happens occasionally
Typically, I run one of the MVC5 sites in the debugger and see this issue
If I navigate directly to the WebAPI site after the above, I'll get the "Yellow Screen of Death" with the error as per above
Sometimes, even after a cold reboot, this error will NOT appear, other times it will
What I currently do to work around the problem:
If I run the WebAPI site in the debugger, if the error is present, it will fixed itself
After running in the debugger (per above), I can relaunch an MVC5 site in the debugger and the issue goes away
Just to repeat, this DOES NOT happen ever when the application is deployed to Azure.
I have multiple developers working on this project, and we all run into the same error at some stage.
I am referencing the following Nuget packages:
Microsoft.AspNet.WebApi (version 5.2.3)
Microsoft.AspNet.WebApi.Client (version 5.2.3)
Microsoft.AspNet.WebApi.Core (version 5.2.3)
Microsoft.AspNet.WebApi.Owin (version 5.2.2)
Microsoft.AspNet.WebApi.WebHost (version 5.2.3)
If I look inside the *.csproj file, I have a reference to the following:
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
I've checked the bin folder of the website, and all the assemblies inside it have the correct version as per the above list (including System.Net.Http.Formatting.dll).
Also note that, during debugging and development, each of the three websites are run under Local IIS (constraints of external resources force us to do this), so I have:
http://localhost/site1
http://localhost/site2
http://localhost/api
It's becoming cumbersome to get into a debugging session, to get this error, to then stop debugging, launch the API site under the debugger, and to then switch back to what I was doing at the start.
Not sure where else to go to track down what is happening here. Any ideas?
Update - 26 July 2016
Still have this happening. Since posting the question, have updated the WebAPI to run in its own Application Pool, but that doesn't seem to have made a difference.
Uninstalled Web API 2 NuGet package
Installed Web API 2 NuGet package again.
I think you are going about it wrong. Try setting JSON as your default media formatter like this:
// first clear all formatters
config.Formatters.Clear();
// Since JSON is the first added,
// it will be the "default" if no Accept header present
config.Formatters.Add(new JsonMediaTypeFormatter());
// You can choose not to add these back if you never want to use them,
// up to you.
config.Formatters.Add(new XmlMediaTypeFormatter());
config.Formatters.Add(new FormUrlEncodedMediaTypeFormatter());
I had added what was possibly an incorrect version of System.Net.Http.Formatting to my Global Assembly Cache (GAC) and started getting
Could not load type
'System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter' from assembly
'System.Net.Http.Formatting
errors in my Webservice. After removing this System.Net.Http.Formatting dll from GAC my webservice started working again.
when you build looks for any warning that talks about conflict. Double-clicking on the warnings injects the compatible versions in the section of web.config. This obviously can be done manually also.

Error in using RoleEnvironment to get Configuration

my web app is using MVC3 with razor
If I am trying to read anything from ServiceConfig using RoleEnvironment.GetConfigurationSettingValue("senderName")
I am getting error related to Microsoft.IdentityModel
Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.Serialization.SerializationException: Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SerializationException: Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4727747
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
System.AppDomain.get_Id() +0
<CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +185
<CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) +328
<CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +102
[ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.
]
.
It's true that I am making use of Windows identity foundation for Azure acs authentication .But everything worked fine when I deployed to azure.But if I make use of RoleEnvironment to read any settings from my ServiceConfig files (for ex :RoleEnvironment.GetConfigurationSettingValue("Smtpserver")) .Its failing on azure .
But everything workes fine on my local azure appfabric .If I am removing this line of code ,then all workes fine .RoleEnvironment.GetConfigurationSettingValue("Smtpserver"))
I am using two webroles in my cloud app.
Please help me identify the cause of error
How did you installed the WIF on the Azure?
The most reliable way is to have the WIF runtime installed via a startup task. You check out this question here. And I think this one is exact duplicate.

Custom Membership - Error in Web Site Administration Tool (Type is not resolved for member'')

I had to customize the class MembershipProvider for the user validation is done by email.
But when you open the Asp.net Web Site Administration Tool, the "Security" tab the following error:
There is a problem with your selected data store. This can be caused
by an invalid server name or credentials, or by insufficient
permission. It can also be caused by the role manager feature not
being enabled. Click the button below to be redirected to a page where
you can choose a new data store.
The following message may help in diagnosing the problem: Type is not
resolved for member
'System.Data.Entity.ModelConfiguration.ModelValidationException,EntityFramework,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Because the code is great and not to pollute the topic, I put on github.
Code:
https://gist.github.com/1146084
While I am still new to MVC 3 and EF 4.1, try adding a line in your web.config for EntityFramework assembly. It seems like I had this problem as well with my setup. I can't remember the exact line, but it's something like (I will look it up when I get home):
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

What is this error in ASP.NET MVC 3 RTM Project?

I Create new Project ASP.NET MVC 3 RTM and Replace References for
using ASP.NET MVC 3 Source code
but When I run project again, get this exception:
[A]System.Web.WebPages.Razor.Configuration.HostSection
cannot be cast to
[B]System.Web.WebPages.Razor.Configuration.HostSection.
Type A originates from
'System.Web.WebPages.Razor,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' in
the context 'Default' at location
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
Type B originates from
'System.Web.WebPages.Razor,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' in the context
'Default' at location
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary
ASP.NET
Files\root\2505c7ee\369315c5\assembly\dl3\f7bae428\d03eeed8_85bbcb01\System.Web.WebPages.Razor.DLL'.
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Source Error:
Line 106: internal static RazorWebSectionGroup GetRazorSection(string virtualPath) {
Line 107: // Get the individual sections (we can only use GetSection in medium trust) and then reconstruct the section group
Line 108: return new RazorWebSectionGroup() {
Line 109: Host = (HostSection)WebConfigurationManager.GetSection(HostSection.SectionName, virtualPath),
Line 110: Pages = (RazorPagesSection)WebConfigurationManager.GetSection(RazorPagesSection.SectionName, virtualPath)
Source File:
E:\GreenTour\webpages\src\System.Web.WebPages.Razor\WebRazorHostFactory.cs
Line: 108
This error means that part of your application is being compiled using your own copy of the source code as a reference while at runtime its finding the reference assemblies in the GAC. Make sure you remove all references to the GACed version of MVC 3 assemblies. This includes a number of things in your web.config files that use this public key token: 31bf3856ad364e35.
I just came across the same problem whilst upgrading my app, the problem was in the web.config file located in the views directory, I blindly copied this over from the old app (my bad).
My solution , create a new MVC 4 app and copy the web.config from the views directory to your app thats having the problem.
Hope this helps
Although the above thread was useful. I could not get things working until I created a 'dummy' 'basic' MVC 4 application and then compared the web.configs to find any changes.
I fixed this not by removing all references to assemblies with the public key of 31bf3856ad364e35 as this covers a lot of irrelevant assemblies.
Instead it should be fixed by updating all configuration references
System.Web.Mvc to 4
System.Web.WebPages to 2
System.Web.WebPages.Razor to 2
Be sure to update all the web.configs, including the ones in View directories.

Resources