Dynamics CRM 2016 Online Security/Isolation Mode - dynamics-crm

I have a simple post create plugin on the Account entity that makes a subsite in SharePoint online with the same name of the Account that has been created.
I have used the SharePointOnlineCredentials class from the Microsoft.SharePoint.Client.Runtime assembly to login to the SharePoint instance.
The plugin works on an on-premise instance as long as the plugin is set to isolation mode = none.
When I run the plugin in Sandbox isolation mode I get the error below (online version error).
I want to run this plugin on an online instance of SharePoint, but as, I believe, I cannot run online with an isolation mode = none, is there another way of running code using this SharePoint assembly on an online CRM instance?
Message: Create, Method: ExecutePluginLogic Exception:
System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.    at System.Security.CodeAccessSecurityEngine.Check(Object
demand, StackCrawlMark& stackMark, Boolean isPermSet)    at
System.Security.CodeAccessPermission.Demand()    at
System.Net.AuthenticationManager.Register(IAuthenticationModule
authenticationModule)    at
Microsoft.SharePoint.Client.SharePointOnlineAuthenticationModule.EnsureRegistered()
   at
Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String
username, SecureString password)    at
MWLSPXRMToolkitOnline.Plugins.AccountCreate.ExecutePluginLogic(IServiceProvider
serviceProvider)    at
MWLSPXRMToolkitOnline.Plugins.BasePlugin.Execute(IServiceProvider
serviceProvider)
The action that failed was: Demand The type of the
first permission that failed was:
System.Security.Permissions.SecurityPermission The Zone of the
assembly that failed was: MyComputer

Not sensibly, when running in Sandbox mode you can't include references to other assemblies. You could try using ILMerge to combine the assemblies together, but if I was you I would take a different approach, e.g. pushing work to an external web service.

If using ILMerge to combine the assemblies together(as recommended by James Wood because when running in Sandbox mode you can't include references), use the '/copyattrs' parameter with ILMerge.
If you have installed ilMarge in the project with NuGet package:
Editing the file in solution:ILMerge.props
Change parameters:
<ILMergeAllowMultipleAssemblyLevelAttributes>true</ILMergeAllowMultipleAssemblyLevelAttributes>
<ILMergeCopyAttributes>true</ILMergeCopyAttributes>

Related

.Net Core: what is the best version to use? SDK 2.1.301 or Runtime 2.1.1

what is the best one to work in .net core? SDK 2.1.301 or Runtime 2.1.1?
I am trying to create a webapi with dotnet, I run dotnet and set http://localhost:5000/api/values/get?Id=1 and fails telling me page not found
I don't know if it is the version of dotnet I installed, I used SDK.
The URL is wrong. It should be http://localhost:5000/api/values/1. That's specified in the controller method itself with a routing attribute :
The SDK inlcudes the runtime so there's no reason to worry about order of installation.
The SDK contains the tools and libraries needed to create and build a project, like dotnet new and dotnet build. It runs on top of the runtime, it doesn't provide its own.
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
This means that the Get action will be called in response to the GET verb and the id parameter will be retrieved from the URL itself.
The runtime contains only the parts that run a program.
UPDATE
The URL just works with the default Web API template. To verify :
Create a new folder
Run dotnet new webapi to create a new Web API project
Run dotnet build to build it and then dotnet run
Paste http://localhost:5000/api/values/1 in any browser.
The response will be
value
UPDATE 2
Postman also works, once SSL certificate verification in Settings > General is disabled.
The Web API template comes with HTTPS preconfigured and works with a self-signed certificate. Calls to http://localhost:5000 will be redirected to https://localhost:5001.
In terms of the framework, there is no difference if you use SDK or runtime. The first one is designed for development, while the latter one for production environments.
Issue comes out from your project, routing for e.g., but difficult to say once you need to share more details. Mentioned framework variants are irrelevant here.

Using Umbraco membership in console application

I am creating a console application that needs to access to Umbraco members in order to do some maintenance jobs.
What I want to do is get all the users for a specific role:
Roles.GetUsersInRole("SomeRole");
I added an app.config file and referenced the assemblies I thought were required. I might be missing something, since I get the following error:
Unhandled Exception: System.TypeLoadException: Could not load type 'umbraco.providers.members.UmbracoRoleProvider' from assembly 'System.Web, Version=4.0.0.0
at System.Web.Security.Roles.Initialize()
The Umbraco APIs don't work outside of an HttpContext - it's one of the current limitations that the MVC version, v5, was meant to address (before it was officially mothballed in June 2012).
However, there is a set of web services which may do what you require - check /umbraco/webservices/api/MemberService.asmx in you installation and reference it in your console app - if you reference that, then you can work with the member store outside of a direct HttpContext.

Azure appfabric cache as provider for distributed outputcache in multiple webroles fires errors "Failed to start monitoring file changes"

Crystal clear :
Step 1
Create a webrole with a few websites with a default.aspx file and a plain regular <%# OutputCache Duration="3600" VaryByParam="*" %>, in the webconfig use the appfabric cache provider for outputcache and link to your cache subscription in azure with provided code
Use only one instance of the webrole, lauch the page, it chaches it, reload few times, it works solid
Step 2
Now increase to 2 or more instances of this WebRole
Here is my problem, reload your default.aspx page on client, now depending of the Webrole the loadbalancer will direct your request, you might get a System.Web.Caching.CacheDependency error upon the fact that the default.aspx cached in distributed cache seems to be based on a file monitoring dependancy, a hard path of the default.aspx page like "E:\sitesroot\2\". But you may have (and you do) "F:\sitesroot\2\" on the other instances of the Webrole.
So it fires an error :
System.Web.HttpException (0x80070003): Directory 'E:\sitesroot\2' does not exist. Failed to start monitoring file changes.
at System.Web.FileChangesMonitor.FindDirectoryMonitor(String dir, Boolean addIfNotFound, Boolean throwOnError)
at System.Web.FileChangesMonitor.StartMonitoringPath(String alias, FileChangeEventHandler callback, FileAttributesData& fad)
at System.Web.Caching.CacheDependency.Init(Boolean isPublic, String[] filenamesArg, String[] cachekeysArg, CacheDependency dependency, DateTime utcStart)
at System.Web.Caching.CacheDependency..ctor(Int32 dummy, String[] filenames)
at System.Web.Caching.OutputCache.HasDependencyChanged(Boolean isFragment, String depKey, String[] fileDeps, String kernelKey, String oceKey, String providerName)
at System.Web.Caching.OutputCache.Get(String key)
at System.Web.Caching.OutputCacheModule.OnEnter(Object source, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I'm struggling with this errors since one week, i don't get it, if anyone knows a way for implementing distributed outputcache over multiple instances of webroles please share your solution.
EDIT
I ended dropping completely asp.net outputcache provider for appfabric and writing a custom cache with appfabric. Works great, few line of codes and cachedependancy on azure made easy.
I ended dropping completely asp.net outputcache provider for appfabric and writing a custom cache with appfabric. Works great, few line of codes and cachedependancy on azure made easy.

Private accessor for signed assembly together with InternalsVisibleTo

I'm using Visual Studio 2010 unit testing features in a project of mine. I'm running into problems trying to create a private accessor.
MyProject:
The strong name key is password protected (.pfx file instead of .snk)
I use InternalsVisibleTo attribute to provide access to internals for MyProject.Tests
Verification of the key is skipped (on development systems) with sn -Vr ... to allow instrumentation in Release builds; for the purpose of obtaining code coverage. This is because the instrumentation part of Visual Studio does not support password protected keys.
MyProject.Tests:
Signed with the same key as MyProject, to allow use of InternalsVisibleTo
I'm trying to generate a private accessor in this project to test some private methods.
When trying to compile the test project with the newly added private accessor, I'm getting the following error message:
Error occurred during processing of assembly 'MyProject.dll': Unable
to obtain public key for StrongNameKeyPair.
I've browsed the internet regarding the error message, but the only solution I could find was to disable signing on the test project. Doing so would mean that I am no longer able to use InternalsVisibleTo. It might work if I rewrite all my existing unit tests for internal members to use shadowed types as well, but obviously I don't want to do so.
Are there any better options?
In case it matters: the strong name key is password protected because the source control system is fairly public, but I wanted to prevent access from anybody outside the development team.

MS Dynamics CRM 4 - The current configuration system does not support user-scoped settings

I have register my plugin to MSCRM 4.0. When I revise or close quote, error will appear. See it below
Log from event viewer
The description for Event ID 18176 from source MSCRMWebService cannot
be found. Either the component that raises this event is not installed
on your local computer or the installation is corrupted. You can
install or repair the component on the local computer.
If the event originated on another computer, the display information
had to be saved with the event.
The following information was included with the event:
3fcb582d-1ab7-dd11-9382-001cc4e015ee
f21001ba-1ee5-e011-8cb3-02bfac1e2a4b quoteclose 50 Create
AAA.Microsoft.CRM.Plugin.CloseddateToQuote, CloseddateToQuote,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=0b2965a625ff0115
AAA.Microsoft.CRM.Plugin.CloseddateToQuote Unhandled Exception:
System.Configuration.ConfigurationErrorsException: The current
configuration system does not support user-scoped settings. at
System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext
context, SettingsPropertyCollection properties) at
System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider
provider) at
System.Configuration.SettingsBase.GetPropertyValueByName(String
propertyName) at System.Configuration.SettingsBase.get_Item(String
propertyName) at
System.Configuration.ApplicationSettingsBase.GetPropertyValue(String
propertyName) at
System.Configuration.ApplicationSettingsBase.get_Item(String
propertyName) at
CloseddateToQuote.Properties.Settings.get_CloseddateToQuote_CrmSdk_CrmService()
at
AAA.Microsoft.CRM.Plugin.CloseddateToQuote.Execute(IPluginExecutionContext
context) at
Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext
context)
Have anyone know the root cause? and How to simulate this error ?
How to solve it?
Thanks,
It looks like your plugin uses the Settings file, which to my knowledge isn't supported in plugins. If you need to pass configuration to your plugin, you can do so using the unsecure/secure parameters in your plugin constructor.
You can then register configuration text (such as XML) in the PluginRegistrationTool. In your plugin constructor, parse the unsecured/secure parameters and save them to local backing fields for use in your Execute method.

Resources