我一直在尝试编写一个简单的基于命令行的应用程序(使用Visual 2015和Windows 10中的C#和.NET ),以便在Microsoft的通用示例之后启动Wi直接广告,但手动添加对必要的*.dll和*.winmd程序集的引用,而不是创建UniversalWindowsPlatform项目。(System.Runtime.WindowsRuntime来自Refference程序集,Windows来自Windows \10\Union Metadata\Windows.winmd)
以下是有关守则:
public void StartAdvertisement(WiFiDirectAdvertisementListenStateDiscoverability discoverability,
bool listenToConnections)
{
if (mPublisher == null)
mPublisher = new WiFiDirectAdvertisementPublisher();
if (listenToConnections)
{
mListener = new WiFiDirectConnectionListener();
mListener.ConnectionRequested += OnConnectionRequested;
}
mPublisher.StatusChanged += OnStatusChanged;
mPublisher.Advertisement.IsAutonomousGroupOwnerEnabled = true;
mPublisher.Advertisement.ListenStateDiscoverability = discoverability;
mPublisher.Start();
}
async void OnConnectionRequested(WiFiDirectConnectionListener sender,
WiFiDirectConnectionRequestedEventArgs connectionEventArgs)
{
// Connection code
}广告商启动OK (可以从其他设备中找到,并创建必要的网络接口),但是当其他设备试图连接时,OnConnectionRequested方法不会被调用。我已经看到,对于使用Wi直接,一个通用的Windows应用程序必须添加到它的清单接近能力,但对于一个通用的应用程序,没有清单。
仅通过引用必要的程序集,我可以使用来自非通用WiFi应用程序的Windows 10 Windows吗?
发布于 2015-09-11 13:50:12
因此,我最终可以使用非通用WinRT应用程序的Wi(包括Wi直接API,即使没有声明接近能力使用的清单),但在Windows 10中比8或8.1要复杂一些。
编辑项目的*.csproj以在组中添加以下行后.
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>您将在参考管理器中看到一个名为Windows的新部分,其中包含winmd库。它们都不会有用,您可能只需要在两个库中添加浏览:
C:\Program Files (x86)\Windows Kits\10\Union Metadata\Windows.winmd
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll有了这两种引用,您就可以避免类似于
‘XXXX类型是在未引用的程序集中定义的’
或
名称空间XXXX是在两个不同的程序集中定义的。
但我们还没完呢!特别是在Wi直接中,一旦广告商尝试连接广告和其他计算机,如果您有WiFiDirectConnectionListener实例,应该调用以下方法
async void OnConnectionRequested(WiFiDirectConnectionListener sender, WiFiDirectConnectionRequestedEventArgs connectionEventArgs)但是你却得到了一个System.BadImageFormatException。这是因为System.Runtime.WindowsRuntime.dll的实际版本与清单中声明的版本有所不同,因此无法加载。
在Visual中打开属性工具,选择System.Runtime.WindowsRuntime引用并更改以下属性:将Local和特定版本复制为true。
现在该起作用了!
https://stackoverflow.com/questions/32439651
复制相似问题