Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace AssemblyName.GetAssemblyName() and Assembly.Load(string) #268

Merged
merged 3 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net45'">
<DefineConstants>$(DefineConstants);DOTNET45;FEATURE_ISUPPORTINITIALIZE;FEATURE_REMOTING;FEATURE_SECURITY_PERMISSIONS;FEATURE_SYSTEM_WEB;FEATURE_SYSTEM_CONFIGURATION;FEATURE_WINFORMS;FEATURE_SERIALIZATION;FEATURE_URIMEMBERS;FEATURE_GETCALLINGASSEMBLY;FEATURE_APPDOMAIN;FEATURE_CODEDOM</DefineConstants>
<DefineConstants>$(DefineConstants);DOTNET45;FEATURE_PERFCOUNTERS;FEATURE_GAC;FEATURE_ISUPPORTINITIALIZE;FEATURE_REMOTING;FEATURE_SECURITY_PERMISSIONS;FEATURE_SYSTEM_WEB;FEATURE_SYSTEM_CONFIGURATION;FEATURE_WINFORMS;FEATURE_SERIALIZATION;FEATURE_URIMEMBERS;FEATURE_GETCALLINGASSEMBLY;FEATURE_APPDOMAIN;FEATURE_CODEDOM;FEATURE_ASSEMBLIES</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netstandard1.5'">
<PropertyGroup Condition="'$(TargetFramework)'=='netstandard1.6'">
<DefineConstants>$(DefineConstants);FEATURE_NETCORE_REFLECTION_API</DefineConstants>
</PropertyGroup>

Expand Down
21 changes: 9 additions & 12 deletions src/Castle.Windsor/Castle.Windsor-VS2017.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net45;netstandard1.6</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\common.props"></Import>
Expand All @@ -19,26 +19,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.0.0" />
<Compile Include="..\..\buildscripts\CommonAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net45'">
<Reference Include="System.Configuration" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\buildscripts\CommonAssemblyInfo.cs" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net45'">
<DefineConstants>$(DefineConstants);FEATURE_PERFCOUNTERS;FEATURE_GAC</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.5'">

<ItemGroup Condition="'$(TargetFramework)'=='netstandard1.6'">
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="1.1.2" />
</ItemGroup>
</Project>
24 changes: 17 additions & 7 deletions src/Castle.Windsor/Core/Internal/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ namespace Castle.Core.Internal
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
#if !(SILVERLIGHT)
using System.Collections.Concurrent;
#if !FEATURE_ASSEMBLIES
using System.Runtime.Loader;
#endif

public static class ReflectionUtil
Expand Down Expand Up @@ -78,11 +79,9 @@ public static Assembly GetAssemblyNamed(string assemblyName)
try
{
Assembly assembly;
#if FEATURE_ASSEMBLIES
if (IsAssemblyFile(assemblyName))
{
#if (SILVERLIGHT)
assembly = Assembly.Load(Path.GetFileNameWithoutExtension(assemblyName));
#else
if (Path.GetDirectoryName(assemblyName) == AppContext.BaseDirectory)
{
assembly = Assembly.Load(Path.GetFileNameWithoutExtension(assemblyName));
Expand All @@ -91,12 +90,21 @@ public static Assembly GetAssemblyNamed(string assemblyName)
{
assembly = Assembly.LoadFile(assemblyName);
}
#endif
}
else
{
assembly = Assembly.Load(assemblyName);
}
#else
if (IsAssemblyFile(assemblyName))
{
assembly = Assembly.Load(AssemblyLoadContext.GetAssemblyName(assemblyName));
}
else
{
assembly = Assembly.Load(new AssemblyName(assemblyName));
}
#endif
return assembly;
}
catch (FileNotFoundException)
Expand Down Expand Up @@ -281,10 +289,10 @@ private static void EnsureIsAssignable<TBase>(Type subtypeofTBase)
throw new InvalidCastException(message);
}

#if !SILVERLIGHT
private static AssemblyName GetAssemblyName(string filePath)
{
AssemblyName assemblyName;
#if FEATURE_ASSEMBLIES
try
{
assemblyName = AssemblyName.GetAssemblyName(filePath);
Expand All @@ -293,9 +301,11 @@ private static AssemblyName GetAssemblyName(string filePath)
{
assemblyName = new AssemblyName { CodeBase = filePath };
}
#else
assemblyName = AssemblyLoadContext.GetAssemblyName(filePath);
#endif
return assemblyName;
}
#endif

private static TBase Instantiate<TBase>(Type subtypeofTBase, object[] ctorArgs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace Castle.MicroKernel.Lifestyle.Scoped
/// cref="LifestyleType.Scoped" /> .
/// </summary>
/// <remarks>
/// The scope is passed on to child threads, including ThreadPool threads. The capability is limited to single <see
/// cref="AppDomain" /> and should be used cautiously as call to <see cref="Dispose" /> may occur while the child thread is still executing, what in turn may lead to subtle threading bugs.
/// The scope is passed on to child threads, including ThreadPool threads. The capability is limited to single
/// AppDomain and should be used cautiously as call to <see cref="Dispose" /> may occur while the child thread is still executing, what in turn may lead to subtle threading bugs.
/// </remarks>
public class CallContextLifetimeScope : ILifetimeScope
{
Expand Down