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:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Because you have a nested namespace, i.e.
Comlink.CefSharp.*
andCefSharp.*
. Then your window is inComlink.*
so everything inside that namespace that refers to simplyCefSharp
would resolve toComlink.Cefsharp
rather thanCefSharp
, 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.
@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