This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Repository navigation
Fix assembly conflict issue #208
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9be29fe
Fix assembly conflict.
Shwetap05 89b6afa
changes
Shwetap05 421771e
More changes
Shwetap05 00d77e9
More changes
Shwetap05 1de674c
remove file
Shwetap05 c53082e
Added mapping for ushort type
Shwetap05 c3ccf02
merge
Shwetap05 86f0216
Fix review comments
Shwetap05 e36e77b
Fixed compiler directives
Shwetap05 26dbfaf
Added comments for assembly loader
Shwetap05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/AssemblyLoader/AppDomainCreator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.AssemblyLoader | ||
| { | ||
|
|
||
| #if NETFRAMEWORK | ||
| /// <summary> | ||
| /// Creates a separate app domain. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type for which instance needs to be created in new app domain.</typeparam> | ||
| internal sealed class AppDomainCreator<T> : MarshalByRefObject, IDisposable | ||
| { | ||
| /// <summary> | ||
| /// Initializes new instance of <see cref="AppDomainCreator{T}"/>. | ||
| /// </summary> | ||
| public AppDomainCreator() | ||
| { | ||
| var setupInformation = AppDomain.CurrentDomain.SetupInformation; | ||
|
|
||
| // Specify that the new domain should make a copy to the shadow directory, preventing | ||
| // the locking of the assemblies. | ||
| setupInformation.ShadowCopyFiles = "true"; | ||
|
|
||
| // The privateBinPath is a ; separated list of paths located in the base path of the | ||
| // application where the CLR will attempt to locate assemblies during the load process. | ||
| // Here we add the location where we will copy dlls. | ||
| setupInformation.PrivateBinPath += ";DefaultGenerationBin"; | ||
|
|
||
| // Setup the domain. | ||
| Domain = AppDomain.CreateDomain( | ||
| "AppDomain" + Guid.NewGuid(), | ||
| AppDomain.CurrentDomain.Evidence, | ||
| setupInformation ); | ||
|
|
||
| var type = typeof( T ); | ||
|
|
||
| Object = (T) Domain.CreateInstanceAndUnwrap( type.Assembly.FullName, type.FullName ); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the <see cref="AppDomain"/>. | ||
| /// </summary> | ||
| public AppDomain Domain { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the instance of the object created in the new app domain. | ||
| /// </summary> | ||
| public T Object { get; } | ||
|
|
||
| /// <summary> | ||
| /// Unloads the app domain. | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| if ( Domain != null ) | ||
| { | ||
| AppDomain.Unload( Domain ); | ||
| Domain = null; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
| } |
60 changes: 60 additions & 0 deletions
60
...rosoft.OpenApi.CSharpAnnotations.DocumentGeneration/AssemblyLoader/AssemblyLoadUtility.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
|
|
||
| namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.AssemblyLoader | ||
| { | ||
| /// <summary> | ||
| /// Contains reusable methods for loading assembly. | ||
| /// </summary> | ||
| internal static class AssemblyLoadUtility | ||
| { | ||
| /// <summary> | ||
| /// Try load the assembly by using provided assembly by name and version if provided. | ||
| /// </summary> | ||
| /// <param name="assemblyPaths">The assembly paths.</param> | ||
| /// <param name="assemblyName">The assembly name to load.It's not assembly full name.</param> | ||
| /// <param name="assemblyVersion">The assembly version to load.</param> | ||
| /// <returns>The assembly if able to load, otherwise null.</returns> | ||
| internal static Assembly TryLoadByNameOrVersion( | ||
| IList<string> assemblyPaths, | ||
| string assemblyName, | ||
| string assemblyVersion = null) | ||
| { | ||
| var assemblyPath = assemblyPaths.FirstOrDefault(path => path.EndsWith(assemblyName + ".dll")); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(assemblyPath)) | ||
| { | ||
| if(!string.IsNullOrWhiteSpace(assemblyVersion)) | ||
| { | ||
| try | ||
| { | ||
| var info = FileVersionInfo.GetVersionInfo(assemblyPath); | ||
| if (info.FileVersion.StartsWith(assemblyVersion)) | ||
| { | ||
| return Assembly.LoadFrom(assemblyPath); | ||
| } | ||
| } | ||
| catch (Exception) | ||
| { | ||
| // Do nothing. | ||
| } | ||
| } | ||
| else | ||
| { | ||
| return Assembly.LoadFrom(assemblyPath); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EndsWith? wouldn't we want an exact match? #WontFix
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the assemblyName passed in is not necessarily the full assemblyName. Could you update the param description so that this info is reflected. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b/c we are checking against assembly path, so path would be like //test/test.dll and we watch to match test.dll with the path, so ends with.
In reply to: 282706378 [](ancestors = 282706378)