I am using the Windows.Devices.Bluetooth library in a WPF application using the .net 5.0 framework.
I have referenced the windows api by installing the CSWinRT nuget and using the target framework moniker in my csproj file like this:
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
This is instead of adding references to windows.winmd and windowsruntime.dll as you had to do pre-.net5. I am able to use the windows library with no problem, but I am also using a class library made from a different project using .net 4.7.2 which also references/uses the Windows.Devices.Bluetooth library and thats when im getting this error:
Severity Code Description Project File Line Suppression State
Error CS0012 The type 'BluetoothLEDevice' is defined in an assembly
that is not referenced. You must add a reference to assembly 'Windows,
Version=255.255.255.255, Culture=neutral, PublicKeyToken=null,
ContentType=WindowsRuntime'. 128 Active
So i can access the library directly but not through the dll. Maybe its a problem that the dll uses a different framework?
Does anyone know how to solve this?
The solution to this was to upgrade the class library project .net 5 so that both projects are using the same framework.
Related
I have converted .NET Framework 3.5 TestAPP to .NET 6 TestAPP and worked well.
i have an Automation project(C++ project) which was using .NET Framework 3.5 TestAPP.dll to run the tests, but right now i have replaced the .NET Framework 3.5
.dll with .NET 6 TestAPP i.e. TestAPP.dll
when i ran the exe in command line , i have got an error as
"Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)"
Please let me know if anything needs to be corrected.
Resolved the error by changing the C++/CLI properties from visual studio project properties , which was referring to .NET framework earlier and i have changed the property as .NET core runtime(clr:netcore) and it is internally handled all GAC changes and worked well.
Hope it might help someone .
When upgrading an app to a later .NET version, edit your csproj file and make sure there is no <RuntimeFrameworkVersion> node in there that someone may have inserted manually.
This will not be updated automatically when switching .NET versions
The running project returned this error. When I changed it to the way in the image, the error was solved.
Project>Properties
In my case the error was due to worng Default Project in Package Manager Console, if you are running EF migrations or something that is in a project that need to get info from the API make sure you are targetting the right project, also try clean + build first.
I just start to write a new application with Net Core 2.0 and I have this structure:
ConsoleApp
Library
the ConsoleApp import the Library reference that is a dll, and Library import HtmlAgilityPack 1.8.0 that's the last version available.
When I run the ConsoleApp, I get this error:
Unhandled exception of type 'System.IO.FileNotFoundException' in Library.dll
Could not load file or assembly 'HtmlAgilityPack, Version=1.8.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a'. The specified file could not be found.
The file is available, as you can see in the image:
Seems that I was able to fix the "bug". To summarize, I have two applications, the first one is a .NET Core Console Application, and the second one is a .NET Core Library. So I've removed the second assembly (.NET Core Library), and I've created the same project as .NET Standard Library.
I got the same problem: when I run the Console Application, the compiler shows the error message:
Unhandled exception of type 'System.IO.FileNotFoundException' in Library.dll Could not load file or assembly 'HtmlAgilityPack, Version=1.8.0.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a'. The specified file could not be found.
So I've tried to install the HtmlAgilityPack also on the Console Application, and, like dark magic, this worked perfectly.
So I guess that I should add the dependency used on the Library imported also to the Console Application, because .NET Core must be sure that all the dependencies of the imported Library are compatible with .NET Core.
IMHO, this should be specified by Microsoft, and again, this problem should be handled by Visual Studio itself. Why do I need to add the dependencies twice?
Of course, I'm not going to accept my own answer; I prefer to wait for someone who explains this situation.
I want to create a library for ASP.NET Core in VS17 that uses System.Data.SqlClient for accesing database. I picked .NET Core Library Class.
The problem is that I'm getting errors like :
CS0012 The type 'Object' is defined in an assembly that is not >referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, >Culture=neutral, PublicKeyToken=b77a5c561934e089'.
On stackoverflow I found a thread with advice to add NuGet package : Microsoft.NETCore.Portable.Compatibility, but then it just throws following exception :
FileNotFoundException: Could not load file or assembly 'System.Data, >Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I tried getting other library types like .NET Standard or .NET Framework, but I am also getting errors e.g. some types from standard System.Data.SqlClient are unavailable.
Is there a way to create a library for ASP.NET Core that uses SqlClient for accesing database then?
I had a similar problem of your.
Try simply run dotnet restore myProjectName on package manager console or on command prompt.
In this way the packages and SDK's on your project are download and reference problems will go away.
This could be a simple No if it's not possible, so first I'll ask outright, Is it possible to use Microsoft.AspNet.SignalR.Client with dnxcore50 right now?
If it should be possible, details of the error I'm hitting are below, this a vNext Console Application:
After adding a dependency on Microsoft.AspNet.SignalR.Client version 2.2.0 the code compiles correctly for dnx451, however for dnxcore50, I am getting an error that I can't seem to figure out:
var hubConnection = new HubConnection("http://localhost");
IHubProxy hubProxy = hubConnection.CreateHubProxy("MyHubName");
Visual Studio underlines the CreateHubProxy() method with the error:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
Obviously as I want to use dnxcore50 I can't just add a reference to mscorlib. I'm trying to figure out if there's something under System that I should referencing here or if this package is just not compatible.
I've found out that at the moment, there's no (reasonably simple) way to get this running on dnxcore50.
I asked Scott Hanselman on Twitter too and he confirmed that you can't right now.
With this I will continue to use the vNext Console Application project so that when the SignalR Client Libraries offer support it should be the case of a config change and package update to run this on both Linux and Mac using .NET Core
I downloaded recent sources of Castle.ActiveRecord from github. I succesfully compiled it against vs2010 (targetting .Net 4.0)
I added reference to Castle.Core, Castle.ActiveRecord.dll assembly and using Castle.ActiveRecord; to my simple project (Console app, .Net 4.0)
And i got the following compile error
"The type or namespace name 'ActiveRecord' does not exist in the namespace 'Castle' (are you missing an assembly reference?)"
But this namespace exists in this assembly (I checked via object browser)
What is the problem?
Castle.Core and Castle.ActiveRecord both have a dependency on System.Web. System.Web does not exist in the .NET Client Profile (either 3.5 or 4). Look further down in your compile errors/warnings and you'll see:
The referenced assembly "Castle.Core"
could not be resolved because it has a
dependency on "System.Web,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which
is not in the currently targeted framework
".NETFramework,Version=v4.0,Profile=Client".
Please remove references to assemblies
not in the targeted framework or
consider retargeting your project.
Go to Project Properties... Application... Target framework... and switch it to ".NET Framework 4" and you should be good.