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.

namespace collision in clr-namespace

See original GitHub issue
  • .NET Core Version: 7.0-rc1
  • Windows version: 11
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Don’t know, not tested

Problem description: MainWindow.xaml(28, 27): [CS0234] The type or namespace name 'Wpf' does not exist in the namespace 'Comlink.CefSharp' (are you missing an assembly reference?)

This is the error I get, the error itself is “correct”. that namespace does not contain Wpf. However, .NET shouldn’t even be looking in that namespace in the first place, since I have defined an assembly in my xaml file.

to give some more details: /src/View/MainWindow.xaml

<Window 
    x:Class="Comlink.Example.View.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
    mc:Ignorable="d"
    Title="Comlink examples" 
    Height="450" 
    Width="800"
>
    <cefSharp:ChromiumWebBrowser x:Name="CefSharpBrowser" Address="https://google.com" />
</Window>

/src/View/MainWindow.xaml

using System.Windows;
using Comlink.Core;
using Comlink.CefSharp;

namespace Comlink.Example.View
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Initialize()
        {
            Kaas kaas = new Kaas();
            Proxy<Kaas> proxied = Core.Comlink.Proxy(kaas);
            
            CefSharpBrowser.Expose(kaas);
            dynamic remote2 = Core.Comlink.Wrap<ClientSchema>(CefSharpBrowser.ToEndpoint());
            remote2.SomeMethod("a string value");
        }
    }

    public class Kaas
    {

    }

    public class ClientSchema
    {

    }
}

csproj file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net7.0-windows</TargetFramework>
    <PublishReadyToRun>true</PublishReadyToRun>
    <UseWPF>true</UseWPF>
    <NoWarn>$(NoWarn);1591</NoWarn>
    <StartupObject>Comlink.Example.View.App</StartupObject>
    <Nullable>enable</Nullable>

    <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
    <SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
    <Platforms>x64</Platforms>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="CefSharp.Wpf.NETCore" Version="106.0.260" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Comlink.Core\Comlink.Core.csproj" />
    <ProjectReference Include="..\Comlink.CefSharp\Comlink.CefSharp.csproj" />
  </ItemGroup>

  <ItemGroup>
    <ApplicationDefinition Include="src\View\App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <XamlRuntime>Wpf</XamlRuntime>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
  </ItemGroup>

  <ItemGroup>
    <Page Update="src\View\MainWindow.xaml">
      <Generator>MSBuild:Compile</Generator>
      <XamlRuntime>Wpf</XamlRuntime>
      <SubType>Designer</SubType>
    </Page>
  </ItemGroup>

</Project>

It seems to me that the generated g code in the obj folder is what is causing the naming collision between my referenced project and the package. I don’t really understand why though because I did add the assembly attribute in the xaml file.

If you want to take a deeper look at the source files of this project you can find it in https://github.com/chris-kruining/comlink-sharp/tree/main/Comlink.Example

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
miloushcommented, Oct 7, 2022

Because you have a nested namespace, i.e. Comlink.CefSharp.* and CefSharp.*. Then your window is in Comlink.* so everything inside that namespace that refers to simply CefSharp would resolve to Comlink.Cefsharp rather than CefSharp, that is not really a WPF issue and you are unnecessarily making things difficult for yourself.

Related but not very useful to your case is #7125. More interestingly #4014 would probably help you, this is perhaps duplicate of it.

1reaction
chris-kruiningcommented, Oct 18, 2022

@miloush I have not confirmed this, but if my memory serves me right. The generated code from Xamarin also prefixes everything with global::. maybe it is worth to communicate with that team to discover possible pitfalls for XAML

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is this namespace collision due to a bug in the XAML ...
1 Answer 1 · You are correct about the nature of the namespace collision, that it's assuming Common refers to the one that...
Read more >
XAML Namespaces and Namespace Mapping - WPF .NET ...
WPF defines a CLR attribute that is consumed by XAML processors in order to map multiple CLR namespaces to a single XAML namespace....
Read more >
The name -- doesnot exist in namespace "clr-namespace:.."
NET namespaces with XAML namespaces. Yes, they are mapped together, but it should be specified in your XAML top element's namespace ...
Read more >
The name xxx does not exist in the namespace "clr- ...
I just started a simple MVVM dummy project. When trying to setup the namespace for the view and viewmodels in the XAML editor,...
Read more >
Mapping CLR Namespaces to XML for XAML - Mad Props!
Core framework assembly (whose CLR namespace is simply “Comicster”) contains the collection classes such as Title, Issue, Character and Creator.
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