本文整理汇总了C#中IAssemblyLoadContext.LoadStream方法的典型用法代码示例。如果您正苦于以下问题:C# IAssemblyLoadContext.LoadStream方法的具体用法?C# IAssemblyLoadContext.LoadStream怎么用?C# IAssemblyLoadContext.LoadStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAssemblyLoadContext
的用法示例。
在下文中一共展示了IAssemblyLoadContext.LoadStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAssembly
/// <summary>
/// Loads the assembly containing precompiled views.
/// </summary>
/// <param name="loadContext">The <see cref="IAssemblyLoadContext"/>.</param>
/// <returns>The <see cref="Assembly"/> containing precompiled views.</returns>
public virtual Assembly LoadAssembly(IAssemblyLoadContext loadContext)
{
var viewCollectionAssembly = GetType().GetTypeInfo().Assembly;
using (var assemblyStream = viewCollectionAssembly.GetManifestResourceStream(AssemblyResourceName))
{
if (assemblyStream == null)
{
var message = Resources.FormatRazorFileInfoCollection_ResourceCouldNotBeFound(AssemblyResourceName,
GetType().FullName);
throw new InvalidOperationException(message);
}
Stream symbolsStream = null;
if (!string.IsNullOrEmpty(SymbolsResourceName))
{
symbolsStream = viewCollectionAssembly.GetManifestResourceStream(SymbolsResourceName);
}
using (symbolsStream)
{
return loadContext.LoadStream(assemblyStream, symbolsStream);
}
}
}
示例2: GetAssemblyFromCompilation
public static CompilationResult GetAssemblyFromCompilation(
IAssemblyLoadContext loader,
Compilation compilation)
{
EmitResult result;
using (var ms = new MemoryStream())
{
using (var pdb = new MemoryStream())
{
if (PlatformHelper.IsMono)
{
result = compilation.Emit(ms, pdbStream: null);
}
else
{
result = compilation.Emit(ms, pdbStream: pdb);
}
if (!result.Success)
{
var formatter = new DiagnosticFormatter();
var errorMessages = result.Diagnostics
.Where(IsError)
.Select(d => formatter.Format(d));
return CompilationResult.FromErrorMessages(errorMessages);
}
ms.Seek(0, SeekOrigin.Begin);
Assembly assembly;
if (PlatformHelper.IsMono)
{
assembly = loader.LoadStream(ms, assemblySymbols: null);
}
else
{
pdb.Seek(0, SeekOrigin.Begin);
assembly = loader.LoadStream(ms, pdb);
}
return CompilationResult.FromAssembly(assembly);
}
}
}
示例3: Load
public Assembly Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
{
if (_response.Diagnostics.HasErrors())
{
throw new DesignTimeCompilationException(_response.Diagnostics);
}
if (_response.AssemblyPath != null)
{
return loadContext.LoadFile(_response.AssemblyPath);
}
if (_response.PdbBytes == null)
{
return loadContext.LoadStream(new MemoryStream(_response.AssemblyBytes), assemblySymbols: null);
}
return loadContext.LoadStream(new MemoryStream(_response.AssemblyBytes),
new MemoryStream(_response.PdbBytes));
}
示例4: Load
public Assembly Load(IAssemblyLoadContext loadContext)
{
if (!_context.Success)
{
throw new FSharpCompilationException(_context.Diagnostics);
}
using (var assembly = new MemoryStream(_context.Assembly))
{
if (FSharpCompiler.SupportsPdbGeneration && _context.Pdb != null)
{
using (var pdb = new MemoryStream(_context.Pdb))
{
return loadContext.LoadStream(assembly, pdb);
}
}
else
{
Logger.TraceWarning("PDB generation is not supported on this platform");
return loadContext.LoadStream(assembly, null);
}
}
}
示例5: Load
public Assembly Load(IAssemblyLoadContext loadContext)
{
using (var pdbStream = new MemoryStream())
using (var assemblyStream = new MemoryStream())
{
IList<ResourceDescription> resources = CompilationContext.Resources;
Logger.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name);
var sw = Stopwatch.StartNew();
EmitResult emitResult = null;
if (_supportsPdbGeneration.Value)
{
emitResult = CompilationContext.Compilation.Emit(assemblyStream, pdbStream: pdbStream, manifestResources: resources);
}
else
{
Logger.TraceWarning("PDB generation is not supported on this platform");
emitResult = CompilationContext.Compilation.Emit(assemblyStream, manifestResources: resources);
}
sw.Stop();
Logger.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds);
var diagnostics = CompilationContext.Diagnostics.Concat(
emitResult.Diagnostics);
var afterCompileContext = new AfterCompileContext(CompilationContext, diagnostics)
{
AssemblyStream = assemblyStream,
SymbolStream = pdbStream
};
foreach (var m in CompilationContext.Modules)
{
m.AfterCompile(afterCompileContext);
}
if (!emitResult.Success ||
afterCompileContext.Diagnostics.Any(RoslynDiagnosticUtilities.IsError))
{
throw new RoslynCompilationException(afterCompileContext.Diagnostics);
}
Assembly assembly = null;
// If this is null it'll fail anyways, just don't blow up with
// a null reference
if (afterCompileContext.AssemblyStream != null)
{
afterCompileContext.AssemblyStream.Position = 0;
}
if (afterCompileContext.SymbolStream == null ||
afterCompileContext.SymbolStream.Length == 0)
{
assembly = loadContext.LoadStream(afterCompileContext.AssemblyStream, assemblySymbols: null);
}
else
{
afterCompileContext.SymbolStream.Position = 0;
assembly = loadContext.LoadStream(afterCompileContext.AssemblyStream, afterCompileContext.SymbolStream);
}
return assembly;
}
}
示例6: Load
public Assembly Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
{
using (var pdbStream = new MemoryStream())
using (var assemblyStream = new MemoryStream())
{
var afterCompileContext = new AfterCompileContext
{
ProjectContext = CompilationContext.ProjectContext,
Compilation = CompilationContext.Compilation,
AssemblyStream = assemblyStream,
SymbolStream = pdbStream
};
EmitResult emitResult = null;
// If assembly is not a satelite assembly or if assembly culture is neutral, then do not generate a resources assembly.
if (!string.Equals(Path.GetExtension(assemblyName.Name), ".resources") || ResourcesHelper.IsResourceNeutralCulture(assemblyName))
{
var resourcesForCulture = ResourcesForCulture.GetResourcesForCulture(assemblyName.CultureName ?? string.Empty, CompilationContext.Resources);
if (resourcesForCulture == null)
{
// No resources is fine for a main assembly
resourcesForCulture = Enumerable.Empty<ResourceDescriptor>();
}
var resources = resourcesForCulture
.Select(res => new ResourceDescription(res.Name, res.StreamFactory, isPublic: true));
Logger.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name);
var sw = Stopwatch.StartNew();
bool emitPdb;
var emitOptions = GetEmitOptions(out emitPdb);
emitResult = CompilationContext.Compilation.Emit(assemblyStream,
pdbStream: emitPdb ? pdbStream : null,
manifestResources: resources,
options: emitOptions);
sw.Stop();
Logger.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds);
foreach (var m in CompilationContext.Modules)
{
m.AfterCompile(afterCompileContext);
}
}
else
{
var resourcesForCulture = ResourcesForCulture.GetResourcesForCulture(assemblyName.CultureName ?? string.Empty, CompilationContext.Resources);
if (resourcesForCulture == null)
{
return null;
}
afterCompileContext.SymbolStream = null;
emitResult = EmitResourceAssembly(assemblyName, resourcesForCulture, afterCompileContext.Compilation.Options, afterCompileContext.AssemblyStream);
}
afterCompileContext.Diagnostics = CompilationContext.Diagnostics.Concat(emitResult.Diagnostics).ToList();
if (!emitResult.Success || afterCompileContext.Diagnostics.Any(RoslynDiagnosticUtilities.IsError))
{
throw new RoslynCompilationException(afterCompileContext.Diagnostics, CompilationContext.ProjectContext.TargetFramework);
}
Assembly assembly = null;
// If this is null it'll fail anyways, just don't blow up with
// a null reference
if (afterCompileContext.AssemblyStream != null)
{
afterCompileContext.AssemblyStream.Position = 0;
}
if (afterCompileContext.SymbolStream == null ||
afterCompileContext.SymbolStream.Length == 0)
{
assembly = loadContext.LoadStream(afterCompileContext.AssemblyStream, assemblySymbols: null);
}
else
{
afterCompileContext.SymbolStream.Position = 0;
assembly = loadContext.LoadStream(afterCompileContext.AssemblyStream, afterCompileContext.SymbolStream);
}
return assembly;
}
}
示例7: Load
public Assembly Load(IAssemblyLoadContext loadContext)
{
if(_response.Errors.Any())
{
throw new CompilationException(_response.Errors);
}
if (_response.AssemblyPath != null)
{
return loadContext.LoadFile(_response.AssemblyPath);
}
if (_response.PdbBytes == null)
{
return loadContext.LoadStream(new MemoryStream(_response.AssemblyBytes), assemblySymbols: null);
}
return loadContext.LoadStream(new MemoryStream(_response.AssemblyBytes),
new MemoryStream(_response.PdbBytes));
}
示例8: Load
public Assembly Load(IAssemblyLoadContext loadContext)
{
using (var pdbStream = new MemoryStream())
using (var assemblyStream = new MemoryStream())
{
IList<ResourceDescription> resources = CompilationContext.Resources;
Trace.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name);
var sw = Stopwatch.StartNew();
EmitResult emitResult = null;
if (_supportsPdbGeneration.Value)
{
emitResult = CompilationContext.Compilation.Emit(assemblyStream, pdbStream: pdbStream, manifestResources: resources);
}
else
{
Trace.TraceWarning("PDB generation is not supported on this platform");
emitResult = CompilationContext.Compilation.Emit(assemblyStream, manifestResources: resources);
}
sw.Stop();
Trace.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds);
var diagnostics = CompilationContext.Diagnostics.Concat(
emitResult.Diagnostics);
if (!emitResult.Success ||
diagnostics.Any(RoslynDiagnosticUtilities.IsError))
{
throw new RoslynCompilationException(diagnostics);
}
Assembly assembly = null;
// Rewind the stream
assemblyStream.Seek(0, SeekOrigin.Begin);
pdbStream.Seek(0, SeekOrigin.Begin);
if (pdbStream.Length == 0)
{
assembly = loadContext.LoadStream(assemblyStream, assemblySymbols: null);
}
else
{
assembly = loadContext.LoadStream(assemblyStream, pdbStream);
}
return assembly;
}
}