question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference to Win32.Registry for 2.0?

See original GitHub issue

Hi,

upgrading to AspNetCore 2.0 - i tried using the current alpha3 which works fine on windows. (using the following code to initialize because no prerelease was made for RazorLight.Mvc):

private static void AddRazorLightSelf(this IServiceCollection services, string root)
		{
			if (services == null)
				throw new ArgumentNullException(nameof(services));

			if (string.IsNullOrEmpty(root))
				throw new ArgumentNullException(nameof(root));

			if (root.StartsWith(value: "/"))
			{
				root = root.Substring(1);
			}
			else if (root.StartsWith(value: "~/"))
			{
				root = root.Substring(startIndex: 2);
			}

			// resolve complete root path 
			var serviceProvider = services.BuildServiceProvider();
			var env = serviceProvider.GetService<IHostingEnvironment>();
			var absoluteRootPath = System.IO.Path.Combine(env.ContentRootPath, root);

			// register options
			services.AddSingleton<RazorLightOptions>();

			// register razor-light project
			services.AddSingleton<RazorLightProject, RazorLightProject>(p => new FileSystemRazorProject(absoluteRootPath));

			// register razorsourcegenerator
			services.AddSingleton<RazorSourceGenerator, RazorSourceGenerator>();

			// register metadatareferencemanager
			services.AddSingleton<IMetadataReferenceManager, DefaultMetadataReferenceManager>();

			// register compiler
			services.AddSingleton<RoslynCompilationService>();

			// register templatefactory
			services.AddSingleton<ITemplateFactoryProvider, TemplateFactoryProvider>();

			// register cachingprovider
			services.AddSingleton<ICachingProvider, DefaultCachingProvider>();

			// register engine
			services.AddSingleton<IRazorLightEngine, RazorLightEngine>(p =>
			{
				var engine = new RazorLightEngine(
					p.GetRequiredService<RazorLightOptions>(),
					p.GetRequiredService<ITemplateFactoryProvider>(),
					p.GetRequiredService<ICachingProvider>());

				return engine;
			});
		}

Unfortunately - using RazorLight on Linux with this approach - fires an InvalidOperationException for not being able to find assembly “Microsoft.Win32.Registry”, see the following stacktrace:

System.AggregateException: One or more errors occurred. (Cannot find compilation                                                                                                                                                              library location for package 'Microsoft.Win32.Registry') ---> System.InvalidOpe                                                                                                                                                             rationException: Cannot find compilation library location for package 'Microsoft                                                                                                                                                             .Win32.Registry'
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePa                                                                                                                                                             ths(ICompilationAssemblyResolver resolver, List`1 assemblies)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvide                                                                                                                                                             r.PopulateFeature(IEnumerable`1 parts, MetadataReferenceFeature feature)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateF                                                                                                                                                             eature[TFeature](TFeature feature)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.GetCo                                                                                                                                                             mpilationReferences()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boole                                                                                                                                                             an& initialized, Object& syncLock, Func`1 valueFactory)
   at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.Execu                                                                                                                                                             teCore(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDo                                                                                                                                                             cument document)
   at RazorLight.RazorSourceGenerator.<GenerateCodeAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.RazorSourceGenerator.<GenerateCodeAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.TemplateFactoryProvider.<CreateFactoryAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.RazorLightEngine.<CompileRenderAsync>d__9.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotifica                                                                                                                                                             tion)
   at FluiTec.AppFx.Mail.MailKitTemplatingMailService.<>c__DisplayClass4_0`1.<Se                                                                                                                                                             ndEmailAsync>b__0()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C                                                                                                                                                             ontextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at FluiTech.CallRouting.AspCoreHost.Controllers.HomeController.<Error>d__6.Mo                                                                                                                                                             veNext()
---> (Inner Exception #0) System.InvalidOperationException: Cannot find compilat                                                                                                                                                             ion library location for package 'Microsoft.Win32.Registry'
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePa                                                                                                                                                             ths(ICompilationAssemblyResolver resolver, List`1 assemblies)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvide                                                                                                                                                             r.PopulateFeature(IEnumerable`1 parts, MetadataReferenceFeature feature)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateF                                                                                                                                                             eature[TFeature](TFeature feature)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.GetCo                                                                                                                                                             mpilationReferences()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boole                                                                                                                                                             an& initialized, Object& syncLock, Func`1 valueFactory)
   at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.Execu                                                                                                                                                             teCore(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDo                                                                                                                                                             cument document)
   at RazorLight.RazorSourceGenerator.<GenerateCodeAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.RazorSourceGenerator.<GenerateCodeAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.TemplateFactoryProvider.<CreateFactoryAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.RazorLightEngine.<CompileTemplateAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot                                                                                                                                                             ification(Task task)
   at RazorLight.RazorLightEngine.<CompileRenderAsync>d__9.MoveNext()<---

Is there anything i can do to avoid this error?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
IInvocationcommented, Mar 26, 2018

@benbuckland I’m sorry - in case u hit the exactly same error - u’re still using PreCompilation, that RazorLight currently doesnt support. You’ll probably have to dig into deactivating that… The settings in the csproj im normally using are: <PreserveCompilationContext>true</PreserveCompilationContext> <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>

You can also try to add the following: <ItemGroup> <MvcRazorFilesToCompile Include="**\*.cshtml" Exclude="MailViews\**\*.cshtml" /> </ItemGroup>

1reaction
benbucklandcommented, Mar 26, 2018

Thanks for coming back to me @IInvocation the following did the trick for me!<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Registry Class (Microsoft.Win32)
This class provides the set of standard root keys found in the registry on machines running Windows. The registry is a storage facility...
Read more >
class Win32::Registry - Documentation for Ruby 2.0.0
win32 /registry is registry accessor library for Win32 platform. It uses dl/import to call Win32 Registry APIs. example¶ ↑. Win32::Registry::HKEY_CURRENT_USER.
Read more >
Does the Registry class in the Microsoft.Win32. ...
I have a .NET Standard 2.0 library with a dependency on the Microsoft.Win32.Registry package. Here's a simple class:
Read more >
Using Microsoft.Win32.Registry on a .NET Standard ...
Win32.Registry and then referencing that Library NuGet package in the applications that want to use it and the dotnet sdk with nuget will ......
Read more >
Microsoft.Win32.Registry 5.0.0
Provides support for accessing and modifying the Windows Registry. Commonly Used Types: Microsoft.Win32.RegistryKey. Microsoft.Win32.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found