I have a problem loading an assembly (from a memory stream) that was emitted from Roslyn compilation.
While trying to load the assembly i'm getting a FileNotFound Exception RazorLight, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified
.
In the compilation ExternalReferences there is 261 items which includes C:\Users\favishg\source\repos\Empeon_Reports\Reports\bin\Debug\net461\RazorLight.dll
, so i assume that the roslyn compiler knows were to find this assembly, but it still gives this file not found exception.
More details: i'm dynamically loading a Sample.dll (late binding), this dll is using RazorLight to compile a schtml Template, in order for RazorLight to know about the Sample.dll and it's type's i needed to add MetadataReferences to the Sample.dll which worked fine, but i still got a FileNotFound Exception.
To debug it i downloaded the RazorLight source code and it seems that the exception is when trying to get assembly.GetCustomAttribute<RazorLightTemplateAttribute>()
from the Roslyn compiled assembly.
Code Report reunner (Sample.dll)
MetadataReference metadata =MetadataReference.CreateFromFile(PayrollReport);
MetadataReference metadataRazor=MetadataReference.CreateFromFile(RazorLight);
IRazorLightEngine engine;
engine = new RazorLightEngineBuilder()
.AddMetadataReferences(metadata, metadataRazor)
.UseFilesystemProject(templatePath)
.UseMemoryCachingProvider()
.Build();
PayrollSummary payrollSummary = repo.GetPayrollData();
return await engine.CompileRenderAsync("Report.cshtml", payrollSummary);
Call the sample.dll dynamically
Assembly asmPayroll = Assembly.LoadFrom(ParollReportDll);
//Get the correct type from dll..
IHardcodedReport rpt = (IHardcodedReport)Activator.CreateInstance(type);
string html = await rpt.GetReportHtmlAsync(bundle);
Aucun commentaire:
Enregistrer un commentaire