When I try to add an OpenAPI service reference (from a valid .json file) to my .Net Standard 2.0 class library, Visual Studio 2019 throws the following error message at me (message box): "Project needs to be restored before the service reference can be added". What does that mean? What is the problem?
I had the same problem. Then I tried it with a .Net Core Library instead and it worked without a hitch. I think .Net Standard is the wrong library type.
Related
There's a great article here that describes how to use native C++ libraries in Xamarin/C#, and I would assume that this would extend to MAUI: https://learn.microsoft.com/en-us/xamarin/cross-platform/cpp/
I followed these instructions, and put together an end-to-end demo solution of it here: https://github.com/whodges/bindingsample. This does require that you link Visual Studio to a MacBook to build the full solution.
That example essentially uses the default MAUI template, and modifies it slightly so that the actual 'click counter' value is set and retrieved from a native library on a per-platform basis. For Windows, that's a C++ DLL (works great). For Android, that's a .so library (works great). And for iOS, that's a static .a library, and here's where I'm running into trouble: when I try to launch this app using the iOS Simulator, it fails with a clang++ error, and something along the lines of "Could not extract the native library 'libCounteriOS.a' from .../obj/Debug/net6.0-ios/iossimulator-x64/linker-cache/libCounteriOS.a'. Please ensure the native library was properly embedded in the managed assembly (if the assembly was built using a binding project, the native library must be included in the project, and its Build Action must be 'ObjcBindingNativeLibrary')".
I created a C# .NET iOS Binding Library project (Counter.iOS in my example), and this is supposed to bundle libCounteriOS.a, which is generated when CounteriOS (a C++ project) is compiled. First, when Counter.iOS is built using Visual Studio on Windows, it fails to generate the Counter.resources folder in its 'bin' folder, along with the subsequent 'manifest' file. When I use Visual Studio for Mac, these files do get generated. So, I stuck with Visual Studio for Mac to build the iOS.Counter project (everything else is built with Visual Studio on Windows).
Regardless, I still get the "could not extract the native library" error I described. I've tried setting the library file's Build Action in Counter.iOS to ObjcBindingNativeLibrary, but that just results in an unhelpful "Build failed - see build log for details" error in Visual Studio for Mac, and I cannot find said log file for the life of me. On top of that, it's not an Objective C library anyway - it's a C++ one - so I'm not sure if this step is actually appropriate. Does it have to be Objective C? The Xamarin article suggests otherwise, and the native reference option 'Is C++' is there as well. I've also tried setting libCounteriOS.a's Build Action to 'BundleResource' - no luck with that either. I've tried it with .NET 7.0 as well - also no luck there.
I'm really at a loss. Is this even possible? It doesn't seem to work and I've been poking at it for weeks on it. That Xamarin article seems to suggest it should be possible. Any help would be greatly appreciated.
I was super excited to see that the latest previews of .NET Core 3.1 and Visual Studio 2019 add support for managed C++/CLI projects, as such a project is the only think keeping a particular project on .NET Framework.
So, I installed Visual Studio Preview 16.4.0 Preview 4, along with the "C++/CLI support for v142..." options, and as expected I see the new C++ CLR templates and have .NET Core 3.1 preview 2 installed
I created a new project using the "CLR Class Library (.NET Core)" template, copied the files an old managed C++/CLI project, tweaked a little, and the assembly built - great!
However, when I try to use the assembly in a .NET Core 3.1, I get this fatal exception:
Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'MyAssembly, Version=2019.0.1.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
File name: 'MyAssembly, Version=2019.0.1.0, Culture=neutral, PublicKeyToken=null'
at TestApp.Program.Main(String[] args)
Both the managed assembly and test app target X64. Any ideas what could be the problem?
Someone from Microsoft provided the solution over on the Github repo.
When the managed C++/CLI project is built, a file ijwhost.dll is placed in the output folder alongside the assembly - this file needs to be deployed with the app that uses the assembly.
After putting ijwhost.dll in the same folder as the app, it worked as expected.
As an aside, the old C++/CLI project that I built against .NET Core 3.1 preview is actually quite complex - I'm very pleasantly surprised that it basically "just worked"!
Hopefully a better error message will be used in future!
I am using .net 5.0 as the CLI runtime. I finally found that the problem I have is missing native dependency DLLs.
For native applications, there will be an error prompt telling you which DLL is missing. While in .net core C++/CLI, they only give you a BadImageFormatException.
My solution is, create a pure native console project, paste the code that will cause BadImageFormatException, run it and see which DLL is missing then add it back to C++/CLI project file list.
I just found some unexpected dependencies.
In my case c# Net 5.0 app loads managed C++ dll, which is wrapping around unmanaged C++ dll.I get this error every time i try to run on on machine with no Visual Studio installed. I debugged it with ProcessMonitor and figure out that it can't found VCRUNTIME140D.dll. Found these dlls in my dev PC, copied them (both 32 and 64 bit versions) from my dev machine to customer's one to corresponded folders, and it made the trick. Hope will help somebody. Cheers.
I am trying to develop a native (CPP) IIS 7.5 module that will handle a specific type of request using visual studio 2010 and I am having a heck of a time. The library builds correctly however it appears IIS is never calling RegisterModule.
Things I have verified:
The module is listed in globalModules and modules.
The library looks all good from dependency walker and has no missing dependencies.
Built the library as a Win32 release DLL.
Verified the definition file is correct.
I build the IIS7NativeModule provided by Microsoft and it also gets the same errors.
The error generated by IIS is as follows:
HTTP Error 500.21 - Internal Server Error
Handler "URLModule" has a bad module "IIS7NativeModule" in its module list
My end goal is to provide a URL such as "/track?code=testing123" and respond either with an error message or redirect the user to a specific URL based on the GET code.
Any thoughts / advice, etc?
Thanks!
Nate
I have Created a C++/CLI Console Application and I am using C Static Library(Multi-threaded (/MT)) In it.
Its Compiling fine but, when I try to launch it is showing Message Box
Saying
Unable to start ....\ManagedSample.exe
THis application has failed to start because the application configuration is incorrect. Review the manifets file for possible error.
I have Set clr option.
Typically this happens when no or the wrong C++ runtime library is installed.
Download and install the correct VC++ redist.
Eg. if you built your application with VS2010 SP1 use this package.
I am creating an application that consumes a web-service in Delphi-2005 .NET.
How I am doing it is adding a web-reference to the project and then supplying the url to the wsdl. This seems to work fine in that a pas file is generated and added to the project but as soon as I compile the project I get and access violation in the Ide in dcc90il.dll
Anyone know how to solve this?
I suspect a fundamental .net interop, IDE, or RTL bug in Delphi2005.net. Can you download the trial version of Delphi2007.net and try it there?
I have been unable to get this to work or even determine why it is failing. I ended up generating code from the wsdl using wsdl.exe from MS and then compiled the source to an assembly using csc.exe.
The assembly works fine but Delphi generates obscure errors if an error is returned from the server.
imo Delphi sucks.