MySql.Data in GAC, still SecurityException - c#

I have a problem with MySql.Data in a partial trusted environment.
I've added MySql.Data to the GAC (by installing it with the MSI from the mysql.com site). As you can see here:
>gacutil /l | grep -i mysql
MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d,
processorArchitecture=MSIL
MySql.Data.CF, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c4
4d, processorArchitecture=MSIL
MySql.Data.Entity, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc889
69c44d, processorArchitecture=MSIL
MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d,
processorArchitecture=MSIL
>
I've add the following to my web.config:
<configuration>
<system.web>
<trust level="Vevida"/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</assemblies>
</compilation>
</system.web>
</configuration>
But I still get the following exception:
Exception Details: System.Security.SecurityException: Request for the permission of type 'MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' failed.
It is thrown when I try to open a connection.
I'm not sure what I can check more.
According to the MySql documentation, I need at least the following permissions:
System.Net.SocketPermission, System.Security.Permissions.ReflectionPermission, System.Net.DnsPermission, and System.Security.Permissions.SecurityPermission
In my trust level I these:
<IPermission
class="SocketPermission"
version="1"
Unrestricted="true">
</IPermission>
<IPermission
class="ReflectionPermission"
version="1"
Flags="RestrictedMemberAccess"/>
<IPermission
class="DnsPermission"
version="1"
Unrestricted="true"/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution,ControlPrincipal,ControlThread,SerializationFormatter"/>
As far as I can see in the documentation, this is enough. Also tried to set the SecurityPermission and ReflectionPermission to unrestricted, this didn't help.
Do you have any ideas?

MySqlClientPermission has to be added to the medium trust config as SecurityClass and IPermission. My web_mediumtrust.config addition is:
<SecurityClass Name="MySqlClientPermission"
Description="MySql.Data.MySqlClient.MySqlClientPermission,
MySql.Data, Version=6.5.4.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d"
/>
<IPermission class="MySqlClientPermission" version="1">
<add connectionString="Server=;Database=;User=;Password=;Port=;Pooling=;"
restrictions=""
KeyRestrictionBehavior="PreventUsage" />
</IPermission>
As also posted on http://www.saotn.org/mysql-connector-net-6-5-partial-trust/

Every time your code opens a MySqlConnection, the MySql client makes a demand for MySqlClientPermission on the connection string. Your application must have this permission, regardless of whether the MySql client assemblies are in the GAC or not.
The permissions listed at http://englishebook.info/1/software-to-download/656-running-connectornet-65-inside-medium-trust-level (the ones that you've mentioned in your question) are the ones need by the MySql client assemblies, not the ones needed by your ASP.NET application. To allow your application to use MySql, you will need to grant it MySqlClientPermission.

Related

Could not load file or assembly 'Oracle.ManagedDataAccess'

we are developing a windows service which connect to oracle database. We use
Oracle ManagedDataAccess from Nuget package.
When running the windows service we are receving below error. Tried to get details from stackoverflows and nothing is able to resolve the problem.
Our config file is as below
Could not load file or assembly 'Oracle.ManagedDataAccess,
Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342'
or one of its dependencies
Config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="eClaimsService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</sectionGroup>
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<system.web>
<httpRuntime executionTimeout="3600" requestValidationMode="2.0" maxRequestLength="10240"/>
<sessionState mode="InProc" timeout="60"/>
<pages validateRequest="false" />
</system.web>
</configuration>
In my case just go to Visual Studio 20xx Developer Command Prompt and open as Administrator.
Then run the command
C:\Windows\System32>gacutil /u Oracle.ManagedDataAccess
And you are able to uninstall the data successfully.
Now I am able to access application without any error.
I got this error when my App.Config contained an old version of the DLL, I just removed this entry from the App.Config and it worked

Visual Studio Page Inspector Assembly not found

I have a ASP MVC Project which I didn't make but I need to upload it on a IIS server. This works but when I upload it and visit the website I get this error:
Could not load file or assembly 'Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Everything works locally but not on the server. Things I tried already:
Repairing .NET Framework
Trying to remove 2 lines from .NET Framework webconfig (Located in: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config) file but can't because file is in use. Can't stop process because of Access Denied error
I found that removing these 2 lines might be a solution but I can't remove them:
<remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Is there something I am missing? Any help is much appreciated! Thx
Try adding just this line to your site web.config. The config files are inherited from the .NET base up to you site and then folders in your site. So Your site will override the .NET framework config.
<remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
EDIT
The line should go here...
<configuration>
<system.web>
<compilation>
<assemblies>
<remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
</system.web>
</configuration>
It should be noted that all that junk in the assembly attribute more than likely needs to be identical to the one that adds it in the .NET framework config.

Razor intellisense does not work in vs2013

The Razor intellisense stopped working in one MVC 4 project, and one project only on my pc. I use Visual Studio 2013 Professional. I know this is an issue that has happened to a lot of people before me. I've tried many possible solutions, but the one that works for me has not been there yet...
A list of what I tried so far:
Delete the temporary .suo file
In tools->options check Auto list members
Remove the project from the solution and add it back
Create a new Visual Studio MVC project and copy the web.config file
Delete old Visual Studio 2010 settings in AppData/Roaming/Windows/Visual Studio
Change MVC version in web.config file in Views folder
Clean the solution, exit VS, reopen it and rebuild entire solution
Unload and reload the project within the solution
and probably I tried more which I can't remember right now. Does anyone have another solution/tip to solve this?
Suggested answers for this post which didn't work either:
Repair Visual Studio and reinstall ASP .NET MVC
I've faced same kind of problem with different causes and solved as follow:
web.config in all views folders: I got a correct version of web.config creating a new Area in my project and using it in other view folders
Feature … cannot be used because it is not part of the ISO-2 C# language specification generally these kind of errors does not block compilation, but could be very annoying. To solve this error I've added this segment in web.config (or in app.config if your project is not a web project)
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<!-- ASP.NET 4.0 Assemblies -->
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
local assemblies: sometimes, when I've used external assemblies (for helpers e.g.) I've had to check for Copy Local = true in Project references.
In all cases It could be needed to close/reopen VS to get the modification applied.
hope it helps

why I got this in my web.config

I got these dlls in gac then why I got them in web.config as well,
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=removedForPrivacyMyself"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=removedForPrivacyMyself"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=removedForPrivacyMyself"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=removedForPrivacyMyself"/>
</assemblies>
</compilation>
My application seem to work fine when i remove this section
These are just stored in the config file by default. It also means that you do not need to provide a
using System.Web.Extensions;
etc. in every source file.
During compilation, the compiler will use the <assemblies> section to figure out which assemblies to add into the compilation process. If you do put usings everywhere then indeed this section adds nothing.
Your web application project properly using those assemblies in the reference definition.
You can remove them, but remember if you going to use one of those assemblies your web application won't work.
Usually the visual studio add them automatically your web.config

LINQ not in namespace

I have a web project in visual studio 2012 that I am working with over an ftp connection. I am getting the error that the Linq does not exist in the namespace System.Data and Linq does not exist in the namespace System. Visual studio displays an error and will not give code suggestions, however, the code runs fine on the IIS server.
My web.config contents are below.
I have read over the many questions and articles on this problem and was still unable to find a working solution.
<system.web>
<compilation debug="true" strict="false" explicit="true" urlLinePragmas="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Services.Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Services.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Data.Linq"/>
<add namespace="System.Linq"/>
<add namespace="System.Xml.Linq"/>
</namespaces>
</pages>
Try to manually add the reference to System.Data.Linq in your project.This should hopefully resolve your problem.
Project -> References -> Add reference -> System.Data.Linq
This comes a little late, but in the interest of "giving back"..... When I had this issue (VS 2010 running website through IIS), I had to change the target framework to something else, save the changes, and then change it back to v 4.0 (the original my project was built with). (Right-click Project -> property pages -> Build -> "Target Framework"). That cleared up the issue. Not sure how or why. =)
In Visual Studio, check that the project is targetted to a version of the .NET framework that includes Linq. Right click on the project, then look for the Target Framework option. If this is set to v2, everything else that VS tells you will be based on v2 - the available assemblies, the versions of the base class library assemblies, etc.
This happens to me when I upgrade from VisualStudio 2013 to 2015.
I encounter to these errors while the Project build doesnot comes to the end and stops after some warnings. I resolve these warnings, and when I solve the last warning:
Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0, . . .
the error:
the Linq does not exist in the namespace System
get solved.

Categories