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.

Update Razor compiler to use global:: more liberally

See original GitHub issue

Issue: In a Razor Component any variables named “Microsoft” reproduce the error (variable type on the error message changes accordingly):

Error CS1061 ‘string’ does not contain a definition for ‘AspNetCore’ and no accessible extension method ‘AspNetCore’ accepting a first argument of type ‘string’ could be found (are you missing a using directive or an assembly reference?)

Question: Is this an issue or by design?

Project details and files: This is a Razor Class Library project.

.csproj

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
    <LangVersion>8</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.1" />
  </ItemGroup>

</Project>

LoginFormUserComponent.razor

@using SBL.Models.User.Login.OpenId

<div class="login">
    <div class="page-title">
        Login
    </div>

    <p>
        To login you must use one of the available Social Login options below:
    </p>

    <div class="social-login__container">
        <SocialButtonLoginComponent Provider="@Facebook" Image="/images/social/brands/facebook_37x37.png" />
        <SocialButtonLoginComponent Provider="@Google" Image="/images/social/brands/google_37x37.png" />
        @*<SocialButtonLoginComponent Provider="@Microsoft" Image="/images/social/brands/microsoft_37x37.png" />*@
        <SocialButtonLoginComponent Provider="@Twitter" Image="/images/social/brands/twitter_37x37.png" />
    </div>
</div>

@code {
    [Parameter]
    public ProviderOpenIdModel? Facebook { get; set; } = null;

    [Parameter]
    public ProviderOpenIdModel? Google { get; set; } = null;

    //[Parameter]
    //public ProviderOpenIdModel? Microsoft { get; set; } = null; // ERROR

    [Parameter]
    public ProviderOpenIdModel? Twitter { get; set; } = null;

    public string Microsoft { get; set; } // ERROR
}

Comments: I started getting this random error and found out that apparently I cannot write “Microsoft” as a variable name in a Razor component.

I was unable to find the search keywords for anything similar to this.

I initially thought that there was a reference issue on my project when I realized the commented parameter was the issue. I then tried using a native variable type to see if the issue persisted - and it did.

It’s not really an issue I need fixing per say - just wondering why this happens.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Eiloncommented, Mar 30, 2021

I saw something similar to this where I had a Razor component with the same name as the namespace.

E.g.:

MyTestComponent.csproj

  • MyTestComponent.razor. Full type name = MyTestComponent.MyTestComponent
  • AnotherComponent.razor. In here try to use <MyTestComponent ... /> and you get C# compiler errors because the generated code is ambiguous between the namespace MyTestComponent and the type MyTestComponent.

The workaround was easy, once I figured it out (thanks to @captainsafia): rename the component or the namespace so they aren’t the same.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I set a global variable in Razor Pages of ASP.NET ...
I just made a function in razor page to do that. However, I think use the function to check if the browser is...
Read more >
Razor: Compiler no longer produces a Views assembly
The Razor compiler no longer produces a separate Views.dll file that contains the CSHTML views defined in an application. Version introduced.
Read more >
The Trouble with TypeScript
So I sat down and started using generics to assign multiple values and creating wrappers to project types for return values. Someone how...
Read more >
Postel's Law - The Robustness Principle
Postel's Law, also known as the robustness principle, states: Be conservative in what you do, be liberal in what you accept from others....
Read more >
Upgrading Optimizely CMS 11 to 12 and Commerce 13 to 14
Background. There are many great resources for learning how to build a new solution using CMS 12 and Commerce 14.
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