C# + UWP + Console Application + MSVS2017 = not (always) working - c#

My internet searches have led me to downloading the project templates for UWP Console applications in C#, which work perfectly in VS2019, but unfortunately our build machine uses VS2017 and I am forced to "downgrade" (i.e. setup the project again) for that version.
The application is not extremely complicated. It connects to a BLE device, registers to a specific characteristic, prints the received data and also sends it through TCP/IP to a server for visualization. All in all less than 700 lines of code. For the usage of Bluetooth and TCP/IP I have found a couple of checkboxes in the manifest, which I enabled.
Compiling in VS2017 seemed like a roll of the dice, but I think I have found the pattern now. Release mode (whether it is for x86 or x64) will never work. It gives me 168 errors of which over 100 are "Loading assembly "XXX.dll" failed. System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.". 100 different XXX.dlls, always related to System.Private.CoreLib.
In debug mode, it is a different story. The first attempt fails, with only one XXX.dll (System.Runtime.dll, and still related to System.Private.CoreLib), but when I do a 'Clean Solution' and compile again, compiling and linking succeeds. Do I clean and compile again, the error pops up again. Clean and compile again? -> Error gone. It seems to ping-pong ad infinitum between success and failure.
Any other relevant information may be that the minimum and target Windows versions are 2004 (10.0, build 19041).
I am afraid the situation I am in is very specific and therefore I can't find a solution, but maybe someone here is able to help.

Thanks to Roy Li for pointing out that the project templates have a minimum version of VS 2017. I upgraded it and now everything compiles.

Related

Problems trying to use Monodevelop on Manjaro

I can't get monodevelop to work on Manjaro. I tried all the different options to install in AUR (monodevelop-beta, monodevelop-bin, monodevelop-git, monodevelop-nuget3, monodevelop-stable) and most of them failed to build.
The only one that didn't fail was monodevlop-bin, but I couldn't get it to build my program. At first I got this error:
The imported project "/usr/lib/mono/msbuild/15.0/bin/Roslyn/Microsoft.CSharp.Core.targets" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. (MSB4019)
There was no folder "Roslyn" in the specified location. I made a folder with that name and copied the file Microsoft.CSharp.targets from msbuild/15.0/bin/ in the "Roslyn" folder (renamed the copy to Microsoft.CSharp.Core.targets).
It probably wasn't a good idea, but I tried it, just in case.
That did seemed to work, but then I got another error:
Parameter "AssemblyFiles" has invalid value "/usr/lib/mono/4.7-api/mscordlib.dll".
Could not load file or assebly 'System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or' or one of its dependencies. (MSB3248)
doctorzeus commented on 2019-12-14 14:34
Since the issues with compatibility with the latest version of mono and msbuild as well as
there no longer being a "stable" build mode on the github project I am disowning this project.
Sadly I stopped using this IDE in favor of VSCode a while ago and also no longer have the time to maintain it with the large number of incompatibilities with the various dependencies.
Hopefully someone with more time will take over..
This is from the original maintainter/builder (at the time of writing) in the comments of the AUR page. After him, it seems that another person tried to continue maintaining it, but he still failed:
coder2000 commented on 2020-03-31 18:51
The build process is currently broken and the documentation is incomplete.
So, for now, you can't use monodevelop on Arch based systems (at least from AUR). You will have to use alternative IDEs, like JetBrains Rider, or text editors (with proper extensions), like VSCode or Atom.
Also, from personal experience, I would advice against using Arch based distributions for programming, because of problems like that. Use Ubuntu or something Ubuntu based for easiest experience with programming tools (I use Linux Mint for programming and I haven't had any major problems).

Zune Lcd API Source On My PC

I'm trying to get the source of this project to build and run on my computer (64-bit, Visual Studio 2010 Ultimate (though I believe my copy of VS is 32-bit, and the Zune software is, of course, 64-bit)). The solution comes with several projects, but I'm only concerned with ZuneLcdApi and ZuneLcdApiDebug. If I try running the debug program, I get XamlParseException. I Didn't even want to bother with that, so I started my own project in the solution. All my program does is ZuneLcdApi.Launch(), but it doesn't work. I get "Could not load file or assembly 'X, Version=4.8.0.0, Culture=neutral, PublicKeyToken=(some characters)' or one of its dependencies. The system cannot find the file specified." where x is one of the ZuneLcdApi dependencies (UIX, ZuneDbApi, or ZuneShell).
Anyone have any ideas? The project is sort of old so I don't know if I'll be able to reach out to the developer. I'll try, but in the meantime, I'd really like to know how to start using this API, because it's really incredible.
-edit-
I tried a different computer, and now the debug wpf application works fine. But still, my own windows form c# application gives me "Could not load file or assembly 'UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217' or one of its dependencies. An attempt was made to load a program with an incorrect format." How come it can't be found in my project but it can be found in the debug program? They both get copied to the exact same directory!
Figured it out. It was x86 instead of any cpu. I had to go into build>configuration manager to switch the project over. Once I did that, it was smooth sailing.

Windows Service: The module was expected to contain an assembly manifest

I've got a C# program that was built as a Windows service. I tested this last week and it worked fine, but today I'm getting an error.
When I try to install using installutil.exe, I get the error:
Could not load file or assembly [file name] or one of its dependencies. The module was expected to contain an assembly manifest.
Rebuilding the project had no effect. I also noticed in task manager that the service is still listed and running. On the chance that might be interfering with the installation, I tried uninstalling via installutil, but got the same error message back again.
I've seen many other questions related to this error, but most of them have either no answer, or a very specific answer related to their unique situation. Has anybody had this happen, and how did you fix it? Any ideas are appreciated.
Update:
I successfully uninstalled the service using the "sc delete" command via command prompt, but I'm still getting the same error from installutil on trying to reinstall.
Update 2:
Just for the sake of trying something, I deleted the bin folder from the project, reopened the solution, and did a clean and build. It still won't install, but now I've got a different message:
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
Question:
What would cause there to be a mismatch in runtimes? As far as I know, I've only used .NET Framework 4.5 and haven't deviated. Is there a value I should be looking at / changing to fix that?
Update 3:
Here's what I've tried so far:
One answer suggested the version of installutil being used matters. I'd been running v2.0.50727, but there's also a v4.0.30319 I hadn't thought to try. Running this resulted in:
An attempt was made to load a program with an incorrect format...
I'd be willing to work on that error instead, if it would solve the problem. However, I'm compelled to think that's not the problem since I'd been successfully running v2.0.etc just before the first error popped up.
Inside App.config, there's a line "supported Runtime version=v4.0". I switched this to 4.5, but it had no effect good or bad.
I tried switching the target framework (under project properties) down to 4.0, but this cause an error with:
Some NuGet packages were installed using a target framework different from the current target framework, etc...
This was referring to the EntityFramework, and I'd rather not start messing with NuGet again unless it's the only way (last time it was a nightmare).
I tried installing the service on the target server (the machine it will eventually be deployed to) and got the same error. This leads me to think it's a problem with the project / solution and not the pc.
Looks like a assembly loading problem. Use the Fuslogvw.exe utility. Start it from the Visual Studio Command Prompt. Click the Settings button and click the "Log binding failures to disk" radio button. Switch back to VS and start the program and wait for the exception to occur. Back to Fuslogvw, click the Refresh button and double-click the added entry. It will show you the file it found.
One another possibility is to trying to load a .NET 4 assembly with an EXE that asked for CLR version 2. That requires an app.exe.config file that forces CLR 4 to be used.

MySql.Data reference in my own .dll only functions on development computer, not on end user's computers

I have a question as a novice programmer regarding a MySql.data reference I added from the MySql connector net, to my code. The program that I compile would be made into a .dll that runs from within another application. The application is a stock trading program, and my code is a strategy that makes evaluations of price data and executes buy and sell orders, etc.
Just when I thought my strategy was fully developed I've run into a new snag I'd love to have someone's help with in solving.
I'm asking stackoverflow because the support forum mods of the trading application removed this question from their forums, probably because it was outsie their supportable boundaries.
I've been adding extra .NET references to my strategy, like windows forms and system.management, etc so that it would be able to check the computer's hard drive 'serial number' to make sure that the strategy is licensed on that computer. Everything has been working ok so far, and I was able to get the strategy to run on other computers by exporting it as a .dll
The latest and final addition I made was to add a reference to MySql.Data.MySqlClient (which is a .dll that had to be downloaded and installed separately and isn't part of .NET) so that it could check the computer's hardware ID against an online database to see if it's on the whitelist. I got that working perfectly on the development computer, and as soon as I tried to get it running on my other computer, this error message came up in the output window:
NT Error on calling 'OnStartUp' method for strategy 'MyStrategy/7f5e28c481644cb5a7754d0b7a0be47f': Could not load file or assembly 'MySql.Data, Version=6.1.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
I don't fully know what is happening, but it seems that in the past all external .dll from microsoft .NET that I referenced in my code were carried over and functioned perfectly on other computers, and while my code runs with the MySql.Data reference, once any MySql commands are run the program terminates and says that error message about a missing file. (But if I comment out those lines of code it runs fine, just without the licensing checks I need to have)
One last thing I can mention for more information, as I'm new to this area of development and don't know if it matters, is that I installed the most recent MySQL connection net to the laptop which is a later version than the 6.1.6.0 that I have on the development computer.
The strategy runs exactly as intended on the computer it was developed on though.
My main question has two parts to it then:
1) Is there a way to embed or merge the MySql.Data .dll so that it can be a part of my .dll?
2) Will every end user of this software need to have MySql connection net installed on their computer, and the exact same version as whatever it was developed in (noob question)
Any answers, guesses and speculation are welcomed and appreciated.
Just check if your programs output directory contains the MySql.Data dll file.
If not Try to copy the MySql.Data dll file to the output directory of your program.
it should solve your problem.
The problem happens because may be you are referencing the MySql.Data dll from any other directory rather then copying it to the local project directory. or may be it is not copying into your projects output directory.
So when you run the program to another machine it is unable to find the MySql.Data dll file in specified directory and says
MyStrategy/7f5e28c481644cb5a7754d0b7a0be47f': Could not load file or
assembly 'MySql.Data, Version=6.1.6.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The
system cannot find the file specified

Assembly references won't resolve properly on our build server

We code in C# using VS2008 SP1. We have a server that runs Team System Server 2008 which we use for source control, tasks etc. The server is also our build machine for Team Build. This has been working just fine for a long time. Untill now. We get these error messages when trying to build one of our projects that has a reference to one external assembly (this happens both via Team Build, and when logging on physically and doing a regular build via Visual Studio):
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets
: warning MSB3246: Resolved file has a
bad image, no metadata, or is
otherwise inaccessible. Could not load
file or assembly 'C:\Program
Files\Syncfusion\Essential
Studio\7.1.0.21\Assemblies\3.5\Syncfusion.XlsIO.Base.dll'
or one of its dependencies. The module
was expected to contain an assembly
manifest.
C:\Program
Files\MSBuild\Microsoft\VisualStudio\v9.0\ReportingServices\Microsoft.ReportingServices.targets(24,2):
error MSB4062: The
"Microsoft.Reporting.RdlCompile" task
could not be loaded from the assembly
Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a. Could
not load file or assembly
'Microsoft.ReportViewer.Common,
Version=9.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The module
was expected to contain an assembly
manifest. Confirm that the
declaration is correct, and that the
assembly and all its dependencies are
available.
The referenced component
'Syncfusion.XlsIO.Base' could not be
found.
These errors are for one project with one problematic assembly reference. When I try to build the entire solution there are of course many more errors because of this one. And there are two other projects that has the same problem with other assembly references. I have a list of the referenced assemblies that VS can't seem to resolve:
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WinForms
Syncfusion.Compression.Base
Syncfusion.Core
Syncfusion.XlsIO.Base
The Syncfusion assemblies are from a 3rd-party component package. The other two are related to the Microsoft ReportViewer component.
The references has been added via the Add Reference window, in the .NET tab, so I don't think there is anything suspicious about that. In the properties window for the assembly reference, there is no value in Culture, Description, Path, Runtime Version or Strong Name. Version says 0.0.0.0 and Resolved is False. I guess it is pretty obvious that VS cant resolve the reference. My question is why??? I've scratched my head a lot over this one. This only occurs on the server, the solution builds just fine on both my machine, and my coworkers machine. The assembly reference properties are fine on our machines.
I have tried uninstalling the 3rd-party component (on the server of course), and then reinstalling it again. Didn't help. I tried to repair the VS2008 installation. Didn't help. Tried to retrieve an earlier version from source control (that I know has buildt on the server before), and I got the same error messages. I have checked file permissions, and everything appears to be in order. I am running out of ideas...
How do I solve this?
Update 16.02.2009:
I have tried to compare ildasm output of the dll on my pc and on the server (see the comment I wrote about that), and there is one small difference in a line that to me appears to be a comment. I must admit that I don't understand why there is a difference at all, so maybe someone could explain that to me?
I also tried running a virus scan on the server. Didn't help. Tried to remove the reference and then readd it by browsing to the dll on disk. Didn't work.
Update 17.03.2009:
I've found the solution! The culprit was the TruPrevent module of Panda Antivirus. After disabling the module, everything works! =)
I discovered this with the help of fuslogvw.exe and the log it generated. Googled the result, and stumbled upon this blog entry.. Hope this can help somebody else to.
Almost certainly the problem is environmental - not source related.
Some ideas ...
(i) Try disabling your anti-virus/anti-malware tools - I've seen cases where these tools (particularly Trend Micro Antivirus, for some reason) can keep a DLL file locked after (during?) scanning, interfering with compilers.
(ii) Check your PATH environment variable. Even in these modern days, the PATH variable is used to resolve some things - if this is messed up (too long, maximum length is 2048 characters IIRC) then things can be odd.
(iii) You've checked File permissions - have you checked permissions in the registry? For example, SyncFusion installs its license key in both the User and Machine hives - if the build server can't read one or the other, could cause issues.
Good luck!
It could also be that the referenced assemblies are in the GAC on the dev machine, but not on the build machine. Get it out of the GAC, into your source repository, and reference it by path.
We've had the same problem, turns out the C drive was full (only had 28MB).
Freeing space resolved the issue, even though the build happens on D.
Do you see any differences between ildasm of this file
'C:\Program Files\Syncfusion\Essential Studio\7.1.0.21\Assemblies\3.5\Syncfusion.XlsIO.Base.dll'
on your machine versus on the server?
My suspicion is that the user that the build process is under does not have access to the folder that your 3rd party control is in. Since this functions properly on your machines, it is almost certainly user/permission specific.
Your 3rd party dll may depend on unmanaged dlls. Often it's because a specific version of the VC++ Runtime Dlls are missing.
Open the Dll with the Dependency Walker http://www.dependencywalker.com/ on your server and check for missing references.
Not sure if this'll help in your case, but I did have something similar before where a dll apparently got unregistered somehow, and running regsvr32 on the dll did the trick.

Categories

Resources