Skip to content

Commit

Permalink
Renames the generated assemblies to Insight.Database.DynamicAssembly …
Browse files Browse the repository at this point in the history
…to avoid conflicts with debug loading of assemblies
  • Loading branch information
jonwagner committed May 16, 2017
1 parent 7737e8f commit d0eafbd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
7 changes: 2 additions & 5 deletions Insight.Database/CodeGenerator/InterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ static InterfaceGenerator()
{
// make a new assembly for the generated types
AssemblyName an = Assembly.GetExecutingAssembly().GetName();

// TODO remove debugger condition for v6
if (StaticFieldStorage.DebuggerIsAttached()) // Make the dynamic assembly have a unique name. Fixes debugger issue #224.
an.Name = an.Name + ".DynamicAssembly";
an.Name += ".DynamicAssembly";

AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);

Expand Down Expand Up @@ -156,7 +153,7 @@ private static Func<Func<IDbConnection>, object> CreateImplementorOf(Type type,
#endif
{
var template = "{0} is inaccessible to Insight.Database. Make sure that the interface is public, or add " +
"[assembly:InternalsVisibleTo(\"Insight.Database\")] and [assembly:InternalsVisibleTo(\"Insight.Database.DynamicAssembly\")] " +
"[assembly:InternalsVisibleTo(\"Insight.Database.DynamicAssembly\")] " +
"to your assembly (System.Runtime.CompilerServices). If the interface is nested, then it must be public to the world, " +
"or public to the assembly while using the InternalsVisibleTo attribute.";
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, template, type.FullName));
Expand Down
23 changes: 1 addition & 22 deletions Insight.Database/CodeGenerator/StaticFieldStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class StaticFieldStorage
/// </summary>
private static ModuleBuilder _dynamicModule;

/// <summary>
/// Temporary variable to cache whether a debugger is attached. Remove in v6.
/// </summary>
private static bool? _isDebuggerAttached;

/// <summary>
/// The cache of the static fields.
/// </summary>
Expand All @@ -41,10 +36,7 @@ static StaticFieldStorage()
{
// create a shared assembly for all of the static fields to live in
AssemblyName an = Assembly.GetExecutingAssembly().GetName();

// TODO remove debugger condition for v6
if (DebuggerIsAttached()) // Make the dynamic assembly have a unique name. Fixes debugger issue #224.
an.Name = an.Name + ".DynamicAssembly";
an.Name += ".DynamicAssembly";

AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
_dynamicModule = ab.DefineDynamicModule(an.Name);
Expand All @@ -71,19 +63,6 @@ public static void EmitLoad(ILGenerator il, object value, ModuleBuilder moduleBu
il.Emit(OpCodes.Ldsfld, field);
}

/// <summary>
/// Indicates if the debugger is attached. Only evaluated once so that the answer is stable
/// Temporary method, remove in v6
/// </summary>
/// <returns>True if there is a debugger attached.</returns>
internal static bool DebuggerIsAttached()
{
if (!_isDebuggerAttached.HasValue)
_isDebuggerAttached = Debugger.IsAttached;

return _isDebuggerAttached.Value;
}

/// <summary>
/// Creates a static field that contains the given value.
/// </summary>
Expand Down
6 changes: 1 addition & 5 deletions Insight.Tests/InterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
using Insight.Database.Reliable;

// since the interface and types are private, we have to let insight have access to them
[assembly: InternalsVisibleTo("Insight.Database")]

// TODO: uncomment this InternalsVisibleTo in v6:
// To _debug_ some unit test you will need to enable this[assembly: InternalsVisibleTo("Insight.Database.DynamicAssembly")]
// it should remain commented out in v5 to ensure we preserve Insight's ability to access non-public strcutures
[assembly: InternalsVisibleTo("Insight.Database.DynamicAssembly")]

namespace Insight.Tests
{
Expand Down

0 comments on commit d0eafbd

Please sign in to comment.