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.

System.UriFormatException: Invalid URI: The hostname could not be parsed. #479

See original GitHub issue

Describe the bug Facing this exception while testing with dotnet test on ubuntu-latest on Azure DevOps: I still have no idea of the value that DefaultAssemblyDirectoryFormatter is passing to Uri from the Assembly, no idea which Assembly in this the loop.

The assembly directory depends on what framework you’re using, among other things, like whether you bundled the entrypoint project into a single DLL solution or not. This isn’t exactly a RazorLight question, though.

The project is not bundle into a single DLL. This is happening during test on ubuntu. I’m trying to debug to see what Assembly is causing the error, but anyway simply passing Assembly.Location over to UriBuilder is known to cause problems. Don’t we need a check?

To Reproduce Steps to reproduce the behavior: Just run tests on a setup with Embedded Resource Project.

Expected behavior Probably expect that you might get an assembly with no valid location, as according to https://github.com/dotnet/corert/issues/5467, the location may or may not exist, or could even be null.

Information (please complete the following information):

  • OS: ubuntu-lastest (from azure devops)
  • Platform: .NET 6.0
  • RazorLight version: stable 2.0.0
  • Are you using the OFFICIAL RazorLight package? Official
  • Visual Studio version [ e.g Visual Studio Community 17.8.5 ] Azure Devops, .NET 6.0 sdk / MSTEST

Additional context It is a good practice to discuss before simply closing an issue. Thanks for understanding.

https://github.com/toddams/RazorLight/blob/aceda132f1b97a49663906a22b8c280a57b078da/src/RazorLight/Compilation/DefaultAssemblyDirectoryFormatter.cs#L10-L11

System.UriFormatException: Invalid URI: The hostname could not be parsed.
  Stack Trace:
      at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at System.UriBuilder..ctor(String uri)
   at RazorLight.Compilation.DefaultAssemblyDirectoryFormatter.GetAssemblyDirectory(Assembly assembly)
   at RazorLight.Compilation.DefaultMetadataReferenceManager.<Resolve>b__12_2(Assembly p)
   at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(Assembly assembly, DependencyContext dependencyContext)
   at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(Assembly assembly)
   at RazorLight.Compilation.RoslynCompilationService.EnsureOptions()
   at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions()
   at RazorLight.Compilation.RoslynCompilationService.CreateSyntaxTree(SourceText sourceText)
   at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
   at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
   at RazorLight.Compilation.RazorTemplateCompiler.CompileAndEmitAsync(RazorLightProjectItem projectItem)
   at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
   at RazorLight.EngineHandler.CompileTemplateAsync(String key)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20

github_iconTop GitHub Comments

1reaction
jzabroskicommented, May 10, 2022

@SerhiyBalan Can I get detailed info on your Linux environment, e.g., which linux distro and version and libc and glibc? Maybe best to open a new ticket. This is great - I should be able to figure out a better approach.

1reaction
SerhiyBalancommented, May 6, 2022

So far, the only solution I’ve found is to roll back to version 2.0.0-rc.3. It works well on Linux.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid URI: The hostname could not be parsed
I am trying to Construct a URI. But I am unable to handle bad URIs. Is there any way we can handle bad...
Read more >
Invalid URI: The hostname could not be parsed · Issue ...
Same issue here. Getting an error during rendering a view (that doesn't use URI just string and one property named Url). ... at...
Read more >
Invalid URI The hostname could not be parsed
What this error means and how to fix these errors. A family of Microsoft on-premises document management and storage systems.
Read more >
Invalid URI: The hostname could not be parsed - CAREWare
To resolve the "Invalid URI: The hostname could not be parsed" you can change the server hostname used in the client tier server...
Read more >
Invalid URL: The hostname could not be parsed
This error indicates that the URL for either the Source or Destination in your pro​ject is not valid. This usually occurs when you...
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