We have an app which is .netcore 3.1 - a console app.
This uses a 3rd party library from Microsoft which internally creates a dispatcher.
Under an output type of net472 this works, howwever with an output type of netcore31 the following error occurs:
System.TypeLoadException: 'Could not load type 'System.Windows.Threading.Dispatcher' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.'
For information:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
Does anybody know if there is a way to make this work without having to change to the .net framework which causes a host of other issues mainly related to receiving serialized messages from other apps which have a serialization scheme originating in .net core 3.1.
I had been receiving the same error message, but for my .net core 5.0 testing project. After attempting several other suggestions I ran across this post and used the commented answers to "add true" as well as adding net5.0-windows.
This may not completely map to your use case as you are using a library that should be able to create your dispatcher, but for my dispatcher error this worked.
Related
I've now updated to Visual Studio 16.8, and with that, my existing (large) solution fails to build any WPF projects. Error messages such as the following everywhere:
10>C:\...\src\UserInterface\DataWriterMonitor\App.xaml.cs(5,25,5,28): error CS1558: "App" hat keine passende statische Main-Methode.
10>C:\...\UserInterface\DataWriterMonitor\App.xaml.cs(9,4,9,23): error CS0103: Der Name "InitializeComponent" ist im aktuellen Kontext nicht vorhanden.
Obviously, it's failing to pre-process the xaml files. When I change the csproj header of the offending project from <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> I get:
10>C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(240,9): error MC1000: Unbekannter Buildfehler, "Could not find assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly."
This even happens if I remove all direct references from the project.
Different other approaches (including setting the sdk to 4.8 in global.json) generated different error messages, but didn't work either.
How can I make that the build does not use the 5.0 SDK? I need it installed for other projects, but here I just want my solution to build as before with .NET Framework 4.8.
Note: I've tried the sample .NET 4.8 WPF app. This one builds, but it uses the old project file format. If I change it to the new format, I get similar problems. After some fiddling, that now works, possibly because this otherwise empty project has no references at all.
I apparently did too many things at once. Using a global.json with
{
"sdk": {
"version": "3.1.101"
}
}
and no other changes (especially no change to <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">) fixed the build.
I removed <usewpf>true</usewpf> from my projects
Last week I upgraded my .NET Core Web API from 2.2 to 3.0.
I had a lot of issues with packages and still struggling.
Case 1: What I have right now is that all of my tests are failing:
unit tests, integrations tests, etc.
I'm using:
Nunit (3.12.0)
NUnit3TestAdapter (3.15.1)
Moq 4.13.0
Microsoft.NET.Test.sdk (16.2.0)
Microsoft.AspNetCore.Mvc.Testing
When I start debugging my tests I get the following error message:
System.IO.FileNotFoundException HResult=0x80070002
Message=Could not load file or assembly 'Microsoft.IntelliTrace.Core, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Source=System.Private.CoreLib.
The error occurred in the RuntimeAssembly file (part of system.private.corelib), method InternalLoadAssemblyName.
When I continue I get this:
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'
Case 2: When I'm not debugging my tests but just run my application en startup swagger, I can use every call but my output window is filled with thousands of Exceptions like thrown:
'System.InvalidCastException' in Swashbuckle.AspNetCore.SwaggerGen.dll
This happens when the Linq class Where.SpeedOpt.cs is used and the List.cs class of generic, also in System.Private.CoreLib.
Are case 1 and case 2 related to each other?
Anyone have a workaround or solution?
Case 1 also fixed:
When using .Net Core 3.0 and automapper
you should add automapper with additional parameter
services.AddAutoMapper(typeof(Startup));
In .Net core 2.2 i just had
services.AddAutoMapper();
He fails on this during unit and integrationtesting
not on normal startup
Case 2 (swagger error) is solved.
Seems there was a bug in the swagger 5.0.0 packages
That bug is solved in the 5.0.0-rc4 version
Case 1 is still open.
I tried to reproduce with different coding and see what the results are.
When i instantiate a new httpclient, there is no error.
Nevertheless, i can not call my api because it's secured and i get the "unathorized" error (normal behaviour)
When i instantiate a new httpclient with my webapplicationfactory, there is the error.
Is there something that is not initialized from startup when i run my tests
instead of running the core api thru normal startup and calling swagger?
Maybe a problem in startup that is only an issue in unit and integrationtests?
Regards
GSharp
Using .Net Core Signal R, Azure SignalR. Code used to work. Stopped working.
Fails at await MyHubConnection.StartAsync();
Throws exception System.TypeLoadException: 'Method 'GetStreamItemType' in type 'ConnectionState' from assembly 'Microsoft.AspNetCore.SignalR.Client.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'
Microsoft.AspNetCore.SignalR.Client v 1.1.0
Microsoft.Azure.SignalR 1.0.7
How to to fix this?
Thanks!
Adam Leffert
www.leffert.com
In case anyone else runs into this problem, I'm posting the answer here.
I was able to work around this problem by updating all SignalR and related NUGet packages to their version 3.x pre-release versions.
I recently migrated a .net core 2.2.x app to framework 3.1. I experienced the same issue. the problem is version mismatch between Microsoft.AspNetCore.SignalR and Microsoft.AspNetCore.SignalR.Client.
To work properly the server must have SignalR 1.1.0
https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR/1.1.0
In terms of the client, it must be the most recent one, even when the previous one still works:
https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client/3.1.1
Other combinations of the client and server don't work or they have some unexpected behaviors.
Solution for NET 5 console app is just to use the meta-reference for ASP.NET 5.
Open your project and add this meta-reference (don't forget to remove old ASP.NET refs):
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
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.
We have a custom JSON WCF binding that we use in our .net SDK (to support JSON similar to the WebHttpBinding). Our SDK is a PCL supporting .net 4.5, Win8, IOS, Android profile - It works in our Windows Desktop application, and Android without any problem. We are just diving into MonoTouch, and have been tracing down why our custom WCF bindings were not working correctly. We were able to identify that in our WCF class that implements the System.ServiceModel.Description.IOperationBehavior interface, MonoTouch fails when trying to handle System.ServiceModel.Dispatcher.ClientOperation.
The exact error is mono "Could not load the signature of (our custom type) Failed for unknown reasons."
When I configure the .csproj Linker Options to "Link SDK assemblies only" and attempt to compile, I get the error:
Xamarin.iOS 8.6.1 Business Edition using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk
MTOUCHTASK: error MT2002: Failed to resolve "System.ServiceModel.Dispatcher.ClientOperation" reference from "System.ServiceModel.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Task "MTouchTask" execution --
Looking for any kind of work around, as we need the client operation to configure the "Formatter" property when passed in via the ApplyClientBehavior method.
Any assistance would be greatly appreciated.
I submitted this problem to Xamarin, and they confirmed that my report is a bug in Mono 3.1 - they have resolved it in Mono 4.0 but that is not out yet at the time of this writing. Hope this helps someone else out who might spend hours trying to resolve it.
Issue was the PCL library ClientOperation wouldn't work, but under the MonoTouch assmebly it was fine. Xamarin opened a private bug, so I don't have a reference number.