Permalink
Browse files

Added workaround for Medium Trust ReflectionTypeLoaderException probl…

…em; 0.8.4
  • Loading branch information...
1 parent 13261f2 commit 90a15a891d6c08db3a6fe26208b776e45ec12ef9 @markrendle committed Aug 4, 2011
View
@@ -19,5 +19,5 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-[assembly: AssemblyVersion("0.8.3.0")]
-[assembly: AssemblyFileVersion("0.8.3.0")]
+[assembly: AssemblyVersion("0.8.4.0")]
+[assembly: AssemblyFileVersion("0.8.4.0")]
@@ -8,28 +8,27 @@
namespace Simple.Data.Ado
{
+ using System.Security;
+
[Serializable]
public class AdoAdapterException : AdapterException
{
- private readonly string _commandText;
- private readonly IDictionary<string,object> _parameters;
-
public AdoAdapterException() : base(typeof(AdoAdapter))
{
}
public AdoAdapterException(string message, IDbCommand command) : base(message, typeof(AdoAdapter))
{
- _commandText = command.CommandText;
- _parameters = command.Parameters.Cast<IDbDataParameter>()
+ CommandText = command.CommandText;
+ Parameters = command.Parameters.Cast<IDbDataParameter>()
.ToDictionary(p => p.ParameterName, p => p.Value);
}
public AdoAdapterException(string commandText, IEnumerable<KeyValuePair<string,object>> parameters)
:base(typeof(AdoAdapter))
{
- _commandText = commandText;
- _parameters = parameters.ToDictionary();
+ CommandText = commandText;
+ Parameters = parameters.ToDictionary();
}
@@ -40,52 +39,41 @@ public AdoAdapterException(string message) : base(message, typeof(AdoAdapter))
public AdoAdapterException(string message, string commandText, IEnumerable<KeyValuePair<string,object>> parameters)
:base(message, typeof(AdoAdapter))
{
- _commandText = commandText;
- _parameters = parameters.ToDictionary();
+ CommandText = commandText;
+ Parameters = parameters.ToDictionary();
}
public AdoAdapterException(string message, Exception inner) : base(message, inner, typeof(AdoAdapter))
{
}
- public AdoAdapterException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- _commandText = info.GetString("_commandText");
- try
- {
- var array = info.GetValue("_parameters", typeof (KeyValuePair<string, object>[]));
- if (array != null)
- {
- _parameters = ((KeyValuePair<string, object>[]) array).ToDictionary();
- }
- }
- catch (SerializationException)
- {
- }
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ protected AdoAdapterException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
{
- base.GetObjectData(info, context);
- info.AddValue("_commandText", _commandText);
- if (_parameters != null)
- {
- info.AddValue("_parameters", _parameters.ToArray(), typeof(KeyValuePair<string,object>[]));
- }
- else
- {
- info.AddValue("_parameters", null);
- }
+ //CommandText = info.GetString("CommandText");
+ //try
+ //{
+ // var array = info.GetValue("Parameters", typeof(KeyValuePair<string, object>[]));
+ // if (array != null)
+ // {
+ // Parameters = ((KeyValuePair<string, object>[])array);
+ // }
+ //}
+ //catch (SerializationException)
+ //{
+ //}
}
public IDictionary<string, object> Parameters
{
- get { return _parameters; }
+ get { return Data.Contains("Parameters") ? ((KeyValuePair<string,object>[])Data["Parameters"]).ToDictionary() : null; }
+ private set { Data["Parameters"] = value.ToArray(); }
}
public string CommandText
{
- get { return _commandText; }
+ get { return Data.Contains("CommandText") ? Data["CommandText"].ToString() : null; }
+ private set { Data["CommandText"] = value; }
}
}
}
@@ -1,6 +1,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@@ -15,3 +17,6 @@
[assembly: InternalsVisibleTo("Simple.Data.TestHelper")]
[assembly: InternalsVisibleTo("Simple.Data.IntegrationTest")]
[assembly: InternalsVisibleTo("Simple.Data.Ado.Test")]
+
+[assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]
+[assembly: AllowPartiallyTrustedCallers]
@@ -3,46 +3,48 @@
namespace Simple.Data.Ado.Schema
{
+ using System.Security;
+
[Serializable]
+ [SecurityCritical]
public class AmbiguousObjectNameException : Exception
{
- private readonly string _name;
-
public AmbiguousObjectNameException()
{
}
public AmbiguousObjectNameException(string name)
{
- _name = name;
+ Name = name;
}
public AmbiguousObjectNameException(string name, string message) : base(message)
{
- _name = name;
+ Name = name;
}
public AmbiguousObjectNameException(string name, string message, Exception inner) : base(message, inner)
{
- _name = name;
+ Name = name;
}
protected AmbiguousObjectNameException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
- _name = info.GetString("_name");
}
public string Name
{
- get { return _name; }
+ get { return Data.Contains("Name") ? Data["Name"].ToString() : null; }
+ private set { Data["Name"] = value; }
}
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("_name", _name);
- }
+ //[SecurityCritical]
+ //public override void GetObjectData(SerializationInfo info, StreamingContext context)
+ //{
+ // base.GetObjectData(info, context);
+ // info.AddValue("Name", Name);
+ //}
}
}
@@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>SecurityRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Simple.Data.Ado</id>
- <version>0.8.3</version>
+ <version>0.8.4</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>ADO Adapter for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>sqlserver database data ado .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Core" version="0.8.3" />
+ <dependency id="Simple.Data.Core" version="0.8.4" />
</dependencies>
</metadata>
</package>
@@ -8,11 +8,13 @@
namespace Simple.Data.Ado
{
+ using System.Security;
+
public static class TraceHelper
{
public static void WriteTrace(this IDbCommand command)
{
- if (Trace.Listeners.Count == 0) return;
+// if (Trace.Listeners.Count == 0) return;
try
{
var str = new StringBuilder();
@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Simple.Data.Mocking</id>
- <version>0.8.3</version>
+ <version>0.8.4</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>XML-based Mocking adapter for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>database data .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Ado" version="0.8.3" />
+ <dependency id="Simple.Data.Ado" version="0.8.4" />
</dependencies>
</metadata>
</package>
@@ -1,6 +1,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@@ -11,4 +13,6 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2aa66263-94ee-46d5-bb0f-bae22bcec3e8")]
-[assembly: InternalsVisibleTo("Simple.Data.SqlCe40Test")]
+[assembly: InternalsVisibleTo("Simple.Data.SqlCe40Test")]
+[assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]
+[assembly: AllowPartiallyTrustedCallers]
@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Simple.Data.SqlCompact40</id>
- <version>0.8.3</version>
+ <version>0.8.4</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>SQL Server Compact 4.0 ADO provider for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>sqlserver compact sqlce database data ado .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Ado" version="0.8.3" />
+ <dependency id="Simple.Data.Ado" version="0.8.4" />
</dependencies>
</metadata>
</package>
@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Simple.Data.SqlServer</id>
- <version>0.8.3</version>
+ <version>0.8.4</version>
<authors>Mark Rendle</authors>
<owners>Mark Rendle</owners>
<description>SQL Server ADO provider for the Simple.Data data access library.</description>
@@ -12,7 +12,7 @@
<tags>sqlserver database data ado .net40</tags>
<language>en-us</language>
<dependencies>
- <dependency id="Simple.Data.Ado" version="0.8.3" />
+ <dependency id="Simple.Data.Ado" version="0.8.4" />
</dependencies>
</metadata>
</package>
@@ -6,42 +6,38 @@
namespace Simple.Data
{
+ using System.Security;
+
[Serializable]
public abstract class AdapterException : Exception
{
- private readonly Type _adapterType;
-
protected AdapterException(Type adapterType)
{
- _adapterType = adapterType;
+ AdapterType = adapterType;
}
protected AdapterException(string message, Type adapterType) : base(message)
{
- _adapterType = adapterType;
+ AdapterType = adapterType;
}
protected AdapterException(string message, Exception inner, Type adapterType) : base(message, inner)
{
- _adapterType = adapterType;
+ AdapterType = adapterType;
}
protected AdapterException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
- _adapterType = info.GetValue("AdapterType", typeof(Type)) as Type;
+
+
}
public Type AdapterType
{
- get { return _adapterType; }
- }
-
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- info.AddValue("AdapterType", _adapterType);
+ get { return Data.Contains("AdapterType") ? Data["AdapterType"] as Type : null; }
+ private set { Data["AdapterType"] = value; }
}
}
}
View
@@ -8,6 +8,8 @@
namespace Simple.Data
{
+ using System.Diagnostics;
+
class MefHelper : Composer
{
public override T Compose<T>()
@@ -23,11 +25,19 @@ public override T Compose<T>()
public override T Compose<T>(string contractName)
{
- using (var container = CreateContainer())
+ try
+ {
+ using (var container = CreateContainer())
+ {
+ var export = container.GetExport<T>(contractName);
+ if (export == null) throw new ArgumentException("Unrecognised file.");
+ return export.Value;
+ }
+ }
+ catch (ReflectionTypeLoadException ex)
{
- var export = container.GetExport<T>(contractName);
- if (export == null) throw new ArgumentException("Unrecognised file.");
- return export.Value;
+ Trace.WriteLine(ex.Message);
+ throw;
}
}
Oops, something went wrong.

0 comments on commit 90a15a8

Please sign in to comment.