I have a Net 4.6.2 console app which uses a Net Standard 2.0 library I've written. One of the methods in the library returns a tuple:
public (ScanStatEntry scanEntry, DateTime nextScan) Run()
{
The routine is called from within the console app as follows:
(ScanStatEntry scanEntry, DateTime nextScan) = _scanner.Run();
This all worked fine for quite some time...until suddenly I started getting the following exception when the console app ran:
System.MissingMethodException: Method not found:
'System.ValueTuple`2<Olbert.CommunityScanner.Data.Entities.ScanStatEntry,System.DateTime>
Olbert.CommunityScanner.Scanner.Run()'. at
Olbert.CommunityScanner.ScannerService.RunAndWait() at
Olbert.CommunityScanner.ScannerService.Start() in
C:\Programming\CommunityScanner\CommunityScannerTopShelf\ScannerService.cs:line
70 at
Olbert.CommunityScanner.Program.<>c.b__0_2(ScannerService tc) in
C:\Programming\CommunityScanner\CommunityScannerTopShelf\Program.cs:line
20 at
Topshelf.ServiceConfiguratorExtensions.<>c__DisplayClass2_0`1.<WhenStarted>b__0(T
service, HostControl control) at
Topshelf.Builders.DelegateServiceBuilder`1.DelegateServiceHandle.Start(HostControl
hostControl) at Topshelf.Hosts.ConsoleRunHost.Run()
I don't know what I did to cause this problem to appear. Also, everything compiles fine, with no errors; it just crashes as soon as execution tries to enter the method within which the _scanner.Run() call is located (e.g., the containing class' constructor executes just fine).
In researching this, I realized that I had never installed the System.ValueTuple NuGet package for the console app...which I thought was a requirement when using tuples in Net 4.6.2, although, if so, I don't know why the app used to run fine.
So I tried adding the package. No joy; same compile okay but crash on execution claiming the method can't be found.
Calling another method in that same Net Standard 2.0 library works fine. It's just the method that returns a tuple that causes the problem. I could work around this by returning an object rather than a tuple, but I'm curious as to what's causing the problem, and why it appeared after everything was working fine for so long.
Several more hours researching this problem online led me into discussions about problems associated with automatic binding redirects. Apparently, those can arise when you are mixing net standard and net traditional assemblies, which themselves depend upon other assemblies that may depend on different versions of other assemblies.
In my net traditional console app automatic redirect was set in the csproj file (old style format, first PropertyGroup):
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B64EE74D-F171-4438-8E7A-ACAE7B40C6C8}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Olbert.CommunityScanner</RootNamespace>
<AssemblyName>CommunityScannerTopShelf</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Setting AutoGeneratedBindingRedirects to false solved the problem of the application crashing, and let me step into the Net Standard class library method that was returning a tuple.
I know it's a late answer, but if someone still have this problem and come by this thread, we solved it by adding multiple framework targets to the csproj file of the .net-standard project.
That way the compiler compiles a version for each framework and links the correct one.
<PropertyGroup>
<TargetFrameworks>net472;net5.0;netstandard2.0</TargetFrameworks>
</PropertyGroup>
PS: note that it's TargetFrameworkS, plural.
Related
I have working native bindings library targeting old xamarin.mac (xamarin.full net framework 4.8) built with mono.
It is binding ScritptingBridge.framework, not a static library. It is builds and works as expected.
Note: full project for experiments may be found here: https://github.com/snechaev/net6nativeBindingsError
Now I'm trying to migrate to newest net6-macos. To do so I do the following
converted main app project to the sdk style and target net6-macos. If I will temporary remove native bindings dependencies, this will build fine.
converted native bindings project to the sdk style and perform the following fixes suggested by the comiler errors
changed version to avoid wildcards
replaced [assembly: LinkerSafe] with AssemblyMetadata("IsTrimmable", "True")]
added explicit NativeReferecnce to the framework I'm trying to bind.
Final csproj content for native bindings project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6-macos</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>NativeBindingsLib</RootNamespace>
<AssemblyName>NativeBindingsLib</AssemblyName>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<IsBindingProject>true</IsBindingProject>
<NoBindingEmbedding>true</NoBindingEmbedding>
</PropertyGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
<ObjcBindingCoreSource Include="StructsAndEnums.cs" />
<NativeReference Include="/System/Library/Frameworks/ScriptingBridge.framework" Kind="Framework" />
</ItemGroup>
</Project>
When I trying to build the only bindings library with dotnet build it builds without errors.
But when I try to build the application project (app.csproj in the sample repository), which is referencing (via the the ProjectReference) the binding library, I got the following errors:
ILLINK: Error MM0140: File '/Users/user/work/MonoBindingTest/net6/app/obj/Debug/net6.0-macos/osx-x64/linker-cache/NativeBindingsLib.resources/ScriptingBridge.framework/ScriptingBridge' is not a valid framework. (MM0140) (app)
ILLINK: Error MM2342: The linker step 'Extract Binding Libraries' failed during processing: File '/Users/user/work/MonoBindingTest/net6/app/obj/Debug/net6.0-macos/osx-x64/linker-cache/NativeBindingsLib.resources/ScriptingBridge.framework/ScriptingBridge' is not a valid framework. (MM2342) (app)
I double checked the framework path and it is ok. I also tried to add ScriptingBridge.framework into the XCode project and verified that the path is the same.
I also will be happy to get any samples of working net6-macos targeted native bindings projects for frameworks (not a static libraries) for further experiments on my own.
Full project mey be found here (both mono-targeted and net6-targeted): https://github.com/snechaev/net6nativeBindingsError
Finally, I posted the issue in the xamarin repo on github https://github.com/xamarin/xamarin-macios/issues/15485.
And ducting the discussion and experiments we concluded the following:
MM0140 is because the ScriptingBridge is the system framework and this is the special case.
you should not use NativeReference for the system frameworks as it will try to copy the framework into your bundle and this is not what you want for the system framework
initially I was missleaded by the following error
MSBuild : error MM7068: Can't create a binding resource package unless there are native references in the binding project.
so I decided to add NativeReference pointing ScriptingBridge.
So, the final solution is that the "at least one NativeReference" compiler check is excessive and it will be removed it net7 (https://github.com/xamarin/xamarin-macios/issues/15489).
The temporary workaround for net6 is to add the fake NativeReference to the empty static library to make compiler happy.
<NativeReference Include="/Users/sergey/work/MonoBindingTest/net6/test.dylib" Kind="Static"/>
I believe that it is possible to specify NativeReference to point to the source code (C++) instead of binary file and provide an additional command to build such a C++ code into the binary during the build process of native bindings library.
Additional note: the MM0140 error was called MT0140 in the previous versions of xamarin. So, this note may help other to find this post.
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.
I'm trying to publish a WPF app with Target Framework net5.0-windows using ClickOnce (Built in VS2019), which has a Project Reference to another .NET5 Class Library.
But I always run into the following exception:
Publish has encountered an error.
Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.
The diagnostic log shows me the exact exception:
System.AggregateException: One or more errors occurred. ---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.
--- End of inner exception stack trace ---
---> (Inner Exception #0) Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. <---
Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.
The issue can be easily reproduced:
Create new Solution with a WPF project (.NET5)
Create new Class Library (.NET5) in this solution
Reference the ClassLibrary from the WPF App
Try to publish the WPF App with ClickOnce (right-click the WPF App project -> Publish -> ClickOnce, ...)
Here's a Demo project, which I've created followed the steps above:
PublishDemo.Core (Class library)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
PublishDemo.Wpf (WPF App)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PublishDemo.Core\PublishDemo.Core.csproj" />
</ItemGroup>
</Project>
The Build output displays the following error:
Metadata file 'C:\work\source\unmanaged\PublishDemo\PublishDemo\PublishDemo.Core\bin\Release\net5.0-windows\PublishDemo.Core.dll' could not be found
When using the Release-build configuration it tries to referece to the path \bin\Release\net5.0-windows which I think does not make any sense because the Class library targets the framework type net5.0. Also after checking the folders the Class library indeed puts the built files into a folder called net5.0.
Problem is I don't know where I can change that or if there is a workaround for that issue.
I have already updated to the newest VisualStudio version (16.9.0), since I thought maybe it's because ClickOnce way newly implemented in Vs, but this did not solve the issue.
Publishing to a Folder works. Azure I don't have, so I cannot try that.
Can anybody help me with this issue?
Also if you need more information, I'm happy to provide it.
I have found this reported issue and the error looks like yours:
https://developercommunity.visualstudio.com/t/clickonce-publish-for-net-core-31-and-net-50-may-f/1275937
Copied with little changes from the thread above:
It seems the publish command seeks the files in the same target runtime as the published project, even though it could be different (and builds succesfully outside the publish command).
The issue occurs even when the app targets net5.0-windows and the class library is net5.0.
The workaround is to select a specific Target Runtime (i.e. win-x64) on the Configuration page of the Publish Wizard instead of using the default Portable.
I have project created with an blazorhosted template.
Yesterday for some reason Client side had problem with compiling due to like 500 characters error message
I clicked on it twice, and it opened iirc something like mono runtime config file in C:\ProgramFiles\dotnet\...\0.7 folder with weird lines like {blazor smth} and I removed something and unfortunely saved that and went sleep...
I also remember that that 500 characters long error mentioned Linker
Now after starting my app it just shows "Loading..." page and error on web browser console
WASM: The assembly mscorlib.dll was not found or could not be loaded.
blazor.webassembly.js:1:32055 WASM: It should have been installed in
the
`/mnt/jenkins/workspace/test-mono-mainline-wasm/label/ubuntu-1804-amd64/sdks/out/wasm-runtime-release/lib/mono/4.5/mscorlib.dll'
directory. blazor.webassembly.js:1:32055 Error: Failed to start
platform. Reason: [object XMLHttpRequest]
I totally understand that it may be hard to debug it, but maybe somebody has an idea? or how can I reinstall or repair Blazor / Mono?
I just downloaded and installed .NET Core 3.0 (previously had 2.x)
But still the above mentioned error occurs.
If you want use Blazor with .NET Core 3.0 (at least Preview 2) then you essentially use Razor Components + Blazor. It require for you use version of Blazor only from dev feed and not from official Nuget which will work just on .NET Core 2.1 (not on 2.2).
In order to use Blazor with .NET Core 3.0 you should add following changes to your project
Add RestoreAdditionalProjectSources property
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>7.3</LangVersion>
<RestoreAdditionalProjectSources>
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
</RestoreAdditionalProjectSources>
</PropertyGroup>
Change Blazor references to
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="0.8.0-preview-19075-0444" />
<PackageReference Include="Microsoft.AspNetCore.Components.Browser" Version="3.0.0-preview-19075-0444" />
<PackageReference Include="Microsoft.AspNetCore.Components.Build" Version="3.0.0-preview-19075-0444" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.8.0-preview-19075-0444" PrivateAssets="all" />
</ItemGroup>
For me that happened when i edited index.html with some changes (page title and footer) it started with this strange error. Not sure maybe had an error in html... Well, reverted index.html back to when it was working, the error was gone.
I have a problem with resolving dependency to Enyim.Caching.dll while using Couchbase client. I have downloaded the dlls via NuGet and referenced them in the project. The solution compiles fine with the downloaded assembly Enyim.Caching, Version=2.12.0.0, Culture=neutral, PublicKeyToken=05e9c6b5a9ec94c2. But in the runtime Couchbase throws an exception because it is looking for Enyim.Caching, Version=2.12.0.0, Culture=neutral, PublicKeyToken=cec98615db04012e.
I can't undestand why it requires another dll of the same version, but with another PublicKey.
I also tried the solution described in Cant get the couchbase .net memcache client to run, complains it's strong name validation failed to remove strongname requirements via using ns.exe. But it didn't workout.
Can anoyone help me?
In the end I managed to solve this problem using description in the file Readme.mdown of couchbase-net-client project. They say that there are 2 ways to solve the problem: either remove the strong name checking via sn.exe or via removing assembly signing at all.
I have chosen the second way, since I don't that need assembly signing. I rebuilt the source from the scratch, removed every entry NuGet has created for me and manually added references to all assemblies. And it worked like a charm :)
you can delete node with "public_key.snk" in file "build/CommonProperties.targets"
<!-- delay sign the assembly if the PrivateKeyPath property is not specified -->
<!--<PropertyGroup Condition=" '$(PrivateKeyPath)' == '' And '$(PrivateKeyName)' == ''">
<AssemblyOriginatorKeyFile>..\public_key.snk</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>
</PropertyGroup> -->