MissingMethodException: Method not found: 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(AuthenticationCallback, System.Net.Http.HttpClient)' - csproj

I have a cs project that uses the new csproj format (Project Sdk="Microsoft.NET.Sdk") and targets .NET framework 4.6.2, when referencing it from a console application that also uses the new csproj format and targets .NET framework 4.6.2, it works fine, but when referencing it from a WPF application that uses the old csproj format but also targets .NET framework 4.6.2, I get the following exception: MissingMethodException: Method not found: 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(AuthenticationCallback, System.Net.Http.HttpClient)' Any suggestion why?

Related

How to bundle windows visual studio VSIX with other built application?

I found that the windows visual studio extension is targeted to .net framework and only .net framework (which seems not clearly described in the docs?), after switching our custom mono debugger extension to .net 7.0, with framework not compatible (between vsix project's .net framework 4.8 and debugger project's .net 7.0) error when building the vsix project.
If I switch the debugger project target back to .net framework 4.8 then I can build the extension along with the debugger and create a vsix bundle them togeter successfully.
I tried the previewing visual studio extensibility tools: the out-of-process solution, but the out-of-process way seems not have access to the dte object, thus no way to send the debug adapter launch command. If I use the in-process solution, then we head back to the .net framework target :(
The mono debugger extension is a "3rd party executable file" that launched by visual studio debug adapter. If I manually paste the .net 7.0 version mono debugger to the extension install location, the extension can still work with the debugger. I manage the debugger project and the vsix project within a solution is for easier project management only, in fact they are not referenced directly in code.
I switched our mono debugger project to .net 7.0 is for trying to upgrade our toolset to the newest unified framework (every other tool in our team are upgraded to .net 7.0).
TL;DR, how can we bundle a none .net framework targeted project along with a windows visual studio extension, which is targeted to .net framework only? Or how can we integrate/bundle/add built exe,dlls into the vsix container?
There are some solutions from other stackoverflow answers such as add dlls using vsixmanifest, but it can only add dll file, and the way it handle asset file seems not quite right, it just copy the dll to vsix project folder once, meaning it won't get updated when the dll's project rebuild.
Here I managed to bundle the files in a wonky way:
I create a publish folder under vsix project folder,
then copy the published debugger project file to it, add them as existing file to vsix project, and configure them as vsix content, copy to vsix,
then add a pre-build event for the vsix project, publishing our debugger project and output to this publish folder.
With process above, I can package the published file into vsix when trigger vsix project build.
For anyone have similar issue, you can have a try.

How to access UWP devices from C# Winforms App in .Net 5

I downloaded some great code from https://learn.microsoft.com/en-us/samples/microsoft/windows-universal-samples/barcodescanner/ which accesses my barcode scanner really well . I would like to use this functionality from within a Winforms app but I can't seem to load the right library. If I just add the nuget package I get the following error:
Error NU1202 Package System.Numerics.Vectors.WindowsRuntime 4.0.1 is not compatible with net5.0-windows7.0 (.NETCoreApp,Version=v5.0).
Package System.Numerics.Vectors.WindowsRuntime 4.0.1 supports: uap10.0 (UAP,Version=v10.0)
Any thoughts/help is appreciated.

How to get WPF XAML Designer to play nicely with IValidatableObject from NET Standard 2.0 libraries?

Background:
using Visual Studio 2017 v15.4 (no ReSharper or any weird extensions)
Repro solution includes 2 projects:
WPF project: .NET 4.6.1, using NuGet PackageReference format
Class library: NET Standard 2.0
Both projects have the System.ComponentModel.Annotations NuGet package installed.
Problem
After upgrading my WPF project's NuGet format from the old packages.config to the new PackageReference, I started experiencing design-time errors:
Or sometimes the harsher flavor:
To start with, the following ViewModel code works fine:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public class MainWindowViewModel
{
public ValClass MyProp => new ValClass();
}
public class ValClass : IValidatableObject
{
//Implementation stuff
}
However, if I then define an identical class in my NET Standard project, and include that as a type in my ViewModel, it produces the error.
Comparing an F12 on the IValidatableObject of these 2 classes:
The WPF version:
#region Assembly System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\System.ComponentModel.DataAnnotations.dll
#endregion
The NET Standard 2.0 version:
#region Assembly System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// C:\Users\a0110\.nuget\packages\system.componentmodel.annotations\4.4.0\ref\netstandard2.0\System.ComponentModel.Annotations.dll
#endregion
It's clear that the same type and namespace are defined in assemblies with different names--not just assembly versions.
How can I get the XAML Designer to successfully locate whatever assembly is required to use IValidatableObject?
Things I have Tried
Installing VS v15.5 preview and targeting the WPF project to .NET 4.7 (also 15.5 preview 2 and 3, .NET 4.7.1)
Adding the old System.ComponentModel.DataAnnotations reference to the WPF project (with and without the NuGet version)
reverting back to packages.config format (this didn't actually succeed; it appears that I'm stuck with PackageReference!)
grabbing a copy of the System.ComponentModel.Annotations.dll from the project's output folder and referencing it directly (VS would not let me do this)
adding a bindingRedirect to my App.config
adding <DependsOnNETStandard>True</DependsOnNETStandard> to the .csproj
adding <DependsOnNETStandard>netstandard2.0</DependsOnNETStandard> to .csproj
adding <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime> to .csproj
adding the NETStandard.Library NuGet package to the WPF project
Update
For anyone else who is plagued by this issue, I have found a workaround:
Locate the System.ComponentModel.Annotations.dll on your hard drive that your NET Standard project uses for IValidatableObject. Copy it to a location within your project.
Uninstall the System.ComponentModel.Annotations NuGet package from your solution
Give your NET Standard project a direct reference to DLL you copied
Give your WPF project a reference to the standard assembly System.ComponentModel.DataAnnotations
Upgrade your WPF project to target .NET 4.7.1
Compile. Your WPF design-time should be free from this error.
.

Reference .NETCoreApp NuGet from NET47 WPF App

Is it possible to reference a .NETCoreApp 2.0 built NuGet package within a WPF App on Framework 4.7
I have built my own NuGet but fails to add the package:
Could not install package 'My.Common 1.0.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
The package dependencies:
Do we have to wait until NETStandard 2.0? It's fine I can cross compile using;
<TargetFrameworks>netstandard1.6;netcoreapp2.0</TargetFrameworks>
Although I'd rather target less frameworks!
No, netcoreapp is always framework that is incompatible to net. .NET Core can (and does) implement APIs that aren't available on .NET Framework.
With "current" (.NET CLI < 2.0, VS 2017 < 15.3) tooling, the highest version of .NET Standard that .NET 4.7 can use is netstandard15 (which can be used on .NET Framework 4.6.2).
Even when .NET Standard 2.0 (tooling) is released, .NET Framework projects cannot reference .NET Core libraries. Only higher .NET Standard versions.

Error installing MahApps.Metro "trying to install this package into a project that targets '.NETFramework,Version=v3.5'"

I'm trying to install MahApps.Metro http://mahapps.com/MahApps.Metro/ on my Visual Basic .NetFramework 3.5 project, but i have an error
Could not install package 'MahApps.Metro 0.10.0.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I don't understand i already huild on .NetFramework 3.5 .. how can i solve this?
It seems this library requires .NET 4+. Upgrade to a higher .NET version (4.0 or 4.5) and it should work.

Resources