How to embed or-tools in a C# application? - c#

I'm trying to follow the instructions at https://developers.google.com/optimization/introduction/installing.html#windows_binary so that I can use or-tools inside my C# application.
I'm stuck on the make all step. I am in the Developer Command Prompt, but this command says:
'make' is not recognized as an internal or external command,
operable program or batch file.
I tried downloading GNU make, but that fails also. make install says "no target", and a bare make says:
process_begin: CreateProcess(NULL, cl /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo /O2 -DNDEBUG -DUSE_CBC -DUSE_CLP /D__WIN32__ /Iinclude\src\windows /DGFLAGS_DLL_DECL= /DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /Iinclude /Iexamples -DUSE_GLOP -DUSE_BOP -c examples\cpp\costas_array.cc /Foobjs\costas_array.obj, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [objs\\costas_array.obj] Error 2
I also tried copying the DLLs from the bin folder directly into my project. I was able to compile against them by doing this, but when I tried to run it I got an error:
System.BadImageFormatException: 'Could not load file or assembly 'Google.OrTools, Version=5.1.6235.37215, Culture=neutral, PublicKeyToken=7a052e3db761d3be' or one of its dependencies. An attempt was made to load a program with an incorrect format.'
What am I missing?

Regarding the System.BadImageFormatException:
The OrTools binary format is provided in a 64bit dll.
Make sure, that your project is set to 64bit:
In Visual Studio you can check it out by right clicking on the Project --> Properties --> Build, Platform Target: This should be set to x64.

In case you have the same issue with web application, just enable 64 bits on IIS Express using Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64-bit version on IIS Express for web sites and projects

I was having this issue when using OR-Tools in a Web Application (it worked fine in a console application). I was getting:
System.BadImageFormatException HResult=0x8007000B Message=Could not load file or assembly 'Google.OrTools' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Using x64 didn't help, and Octopus was not building the project correctly either. The solution that worked for me was specifying which ASPNETCOMPILER to use (x64) in the project's .csproj :
<Project .... >
<PropertyGroup>
<AspNetToolPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>
</PropertyGroup>

Related

Cannot archive release version of my IOS Xamarin project

I'm currently trying to archive a release version of my IOS xamarin project so I can upload it to the app store connect for submission. The project builds fine in debug and now runs in release after setting 'GenerateSerializationAssembly' to 'Off' but when I go to archive the project I get error below:
2>SGEN : error : Could not load file or assembly 'mscorlib, Version=2.0.5.9, Cultureneutral, PublicKeyToken-7cecs5d7bea7798e’ or one of its dependencies. Strong name validation failed. (Exception from HRESULT: #xB013141A)
In my case, I had the same issue with Visual Studio 2019 and I already had signed the assembly.
I fixed it by this way: Right click on the project which causes the issue -> "Properties" -> "Build" -> Change the value of the "Platform target" field.
I had to change it from Any CPU to x86 but I guess that in function of the project and the library which is failing, you should change its value to x64.

CS1705 error while adding a C++ project to solution

Hi and thanks in advance.
I'm using TFS build 2013 (team services, not on premise) to build my solution. After creating a new C++ project in the solution I'm unable to build successfully.
The error I'm getting on the build machine is:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): An error has occurred during compilation. error CS1705: Assembly 'Microsoft.Build.Utilities.Core,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' uses 'Microsoft.Build.Framework,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher
version than referenced assembly 'Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): The "SetEnvironmentVariable" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name
of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask
interface. 3.) The task is correctly declared with <UsingTask> in the project file, or
in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin\amd64" directory.
I've red about error CS1705 on the internet but I still don't understand why I get this error - the project is an empty project which has no references what so ever and no other project reference it either.
I'm targeting .NET framework 4.6.1 on all my C# projects and in my build definition I'm adding these msbuild arguments: /tv:14.0 /p:VisualStudioVersion=14.0 hence it uses the 2015's version of the c# compiler.
The target platform for this C++ project is VS 2015 (v140) as follows:
C++ project configuration
Needless to say that when I'm removing this project from the list of project to build (configuration manager) - the solution builds successfully.
Any help/clue would be greatly appreciated!
The problem was something other than what I thought it was. Seems it's got something to do with CodeAnalysis and some environment variable related to it.
In my build definition I'm disabling CodeAnalysis and even inside the C++ project properties It's explicitly disabled. After I commented out some attributes on the "SetCABuildNativeEnvironmentVariables" target inside this file on the build machine:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets"
The problem disappered.
This is a nasty workaround however since I'm not fully aware of what's really happening.
Thanks a lot anyways!
Seems there are something still point to "Microsoft.Build.Framework, Version=12.0.0.0"
The /tv:14.0 command argument doesn't work as expected. See:
BuildActivity ignores ToolsVersion
As a workaround, you need to customize the build process template:
Open the template in Visual Studio and find the Run MSBuild for
Project MSBuild activity.
Set ToolVersion to "14.0".
Set ToolPath to target to MSBuild14 (by default: "C:\Program Files
(x86)\MSBuild\14.0\Bin").
Check in this build process template and re-queue the build.
You can also refer the answer from Marson in TFS 2013 building .NET 4.6 / C# 6.0

Can't publish ASP.NET 5 with external library reference

I have included an external reference of Moneris library eSELECTplus_dotNet_API.dll to my ASP.NET 5 RC1 project. It wrapped it alright and I can build project and run it using Kestrel. But when I publish it from VS or command line I got following error:
The package ID 'eSELECTplus_dotNet_API' contains invalid characters. Examples of valid package IDs include 'MyPackage' and 'MyPackage.Sample'.
I tried to rename library to a better name to fit nuget specs and it worked so I can publish it. But now when I run my project I got runtime error saying following:
System.IO.FileNotFoundException : Could not load file or assembly 'eSELECTplus_dotNet_API, Version=2.5.3.0, Culture=neutral, PublicKeyToken=8cb9cd598f87e276' or one of its dependencies. The system cannot find the file specified.
Please advice.

WebKit.NET with C# Project Runtime Exception

I have downloaded WebKit.NET 0.5-bin-cairo to work with an existing C# Project. I've included WebKitBrowser.dll and WebKit.Interop.dll as a reference to the module that requires it, as well as playing them directly in the debug/bin folder as directly by this tutorial.
I do not get any errors until I run the project and get an exception on this line in InitializeComponent() of the designer class.
this.webKitBrowser1 = new WebKit.WebKitBrowser();
The exception:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in WebKitBrowser.dll
Additional information: Failed to initialize activation context
I am building all the modules as 86x debug and my computer is 64 bit.
Any suggestions are appreciated as I've been playing around with this for multiple days.
I had encountered same issue. Three things were missing in my scenario.
manifest files: must be placed as all dlls are dynamically linked
VC++ must be installed on machine: In my case I used vc++2005 redistributable sp1.
Not only dlls/pdb/manifest you need to copy all the folders to root directory of executable
There is no correct packaging available yet for all files/folders of webkit.NET
And obviously project architecture should be x86 for all projects referencing webkit dlls
Have you tried:
WebKit.Net and OpenWebKitSharp Error: Failed to initialize activation context ? Namely to copy all the files from Core(not just the dlls) into your project /bin/release/ or /bin/debug/ folder?
quoted from the tutorial you followed:
Before we can run the application, WebKit.dll and it's dependencies must be present in the output directory. In Windows Explorer (or otherwise), copy all of the files from the WebKit .NET 'bin' directory to your project's output directory. For example, here is the listing of my output directory after copying:
D:\webkitdotnet\WebKitTest\WebKitTest\bin\Debug>ls
CFLite.dll icudt40.dll
JavaScriptCore.dll icuin40.dll
JavaScriptCore.resources icuuc40.dll
SQLite3.dll libcurl.dll
WebKit.Interop.dll libcurl.dll.manifest
WebKit.dll libeay32.dll
WebKit.resources libeay32.dll.manifest
WebKitBrowser.dll libpng13.dll
WebKitBrowser.dll.manifest libxml2.dll
WebKitBrowser.pdb libxslt.dll
WebKitTest.exe pthreadVC2.dll
WebKitTest.pdb ssleay32.dll
WebKitTest.vshost.exe ssleay32.dll.manifest
WebKitTest.vshost.exe.manifest zlib1.dll
curl.exe.manifest
You mentioned you only copied WebKitBrowser.dll and WebKit.Interop.dll over

How to get IKVM to build in Visual Studio 2008?

I've downloaded the IKVM sources (http://www.ikvm.net/) from http://sourceforge.net/cvs/?group_id=69637
Now I'm trying to get it to build in Visual Studio 2008 and am stuck. Does anyone know of documentation of how to build the thing, or could even give me pointers?
I've tried opening the ikvm8.sln, which opens all the projects, but trying to build the solution leads to a bunch of "type or namespace could not be found" errors.
As you can probably guess I'm no Visual Studio expert, but rather am used to working with Java in Eclipse.
So again, I'm looking for either: step-by-step instructions or a link to documentation on how to build IKVM in Visual Studio.
Let me know if you need any more info. Thanks for any help!
Edit: I've also tried a manual "MsBuild.exe IKVM8.sln", but also get a bunch of:
JniInterface.cs(30,12): error CS0234: The type or namespace name 'Internal' does not exist in the namespace 'IKVM' (a
re you missing an assembly reference?)
JniInterface.cs(175,38): error CS0246: The type or namespace name 'ClassLoaderWrapper' could not be found (are you mi
ssing a using directive or an assembly reference?)
JniInterface.cs(175,13): error CS0246: The type or namespace name 'ClassLoaderWrapper' could not be found (are you mi
ssing a using directive or an assembly reference?)
Edit #2: I noticed a "ikvm.build" file so I downloaded and ran nant on the folder, which got me a step further. A few things start to build successfully, unfortunately I now get the following error:
ikvm-native-win32:
[mkdir] Creating directory 'C:\Documents and Settings\...\My Documents\ikvm\ikvm\native\Release'.
[cl] Compiling 2 files to 'C:\Documents and Settings\...\My Documents\ikvm\ikvm\native\Release'.
BUILD FAILED
C:\Documents and Settings\...\My Documents\ikvm\ikvm\native\native.build(17,10):
'cl' failed to start.
The system cannot find the file specified
Total time: 0.2 seconds.
Edit #3: OK solved that by putting cl.exe in the path, still getting other errors though. Note this is all for building it on the console e.g. with Nant. Is there no way to get it to build in Visual Studio? That would be sad...
Edit #4: Next step was installing GNU classpath 0.95, and now it looks like I need a specific OpenJDK installation... Linux AMD64?!
[exec] javac: file not found: ..\..\openjdk6-b12\control\build\linux-amd64\gensrc\com\sun\accessibility\internal\resources\accessibility.java
[exec] Usage: javac <options> <source files>
[exec] use -help for a list of possible options
Edit #5: Got an answer from the author. See below or at http://weblog.ikvm.net/CommentView.aspx?guid=7e91b51d-6f84-4485-b61f-ea9e068a5fcf Let's see if it works...
Edit #6 As I feared, next problem: "cannot open windows.h", see separate question here.
Final Edit: Found Solution! After getting the Platform SDK folders in the Lib and Path environment variables, the solution I described below worked for me.
I don't know that this would do it for you but can you try building from the command line?
msbuild ________
I think that's how I built the application due to the same issues.
OK just got the following reply from the author: http://weblog.ikvm.net/CommentView.aspx?guid=7e91b51d-6f84-4485-b61f-ea9e068a5fcf
If you want to build from cvs, you're on your own. However, you can more easily build from source if you use an official release.
If you download ikvm-0.36.0.11.zip, classpath-0.95-stripped.zip and openjdk-b13-stripped.zip from SourceForge (the last two are under the ikvm 0.36.0.5 release) you have all the sources that are needed.
Now you'll have to open a Visual Studio 2008 Command Prompt (i.e. one that has cl.exe and peverify in the path).
Then in the ikvm root directory, do a "nant clean" followed by "nant". That should build the whole project. After you done that, you should be able to build in Visual Studio (debug target only), but you may need to repair the assembly references in the projects (unless you have ikvm installed in c:\ikvm).
Regards,
Jeroen
Edit: After making sure the Platform SDK folders were in the Path and Lib environment variables, this worked for me. Thanks, Jeroen!
This is how I built IKVM 8.1.5717.0 from source. Visual Studio is not required.
Create a folder:
c:\ikvm\
Add the above folder to PATH (e.g. set PATH=%PATH%;c:\ikvm and leave command prompt open for later).
Download:
ikvmsrc-8.1.5717.0.zip (http://www.frijters.net/ikvmsrc-8.1.5717.0.zip)
Unzip and place "ikvm-8.1.5717.0" folder in c:\ikvm\
Download:
openjdk-8u45-b14-stripped.zip (http://www.frijters.net/openjdk-8u45-b14-stripped.zip)
Unzip and place "openjdk-8u45-b14" folder in c:\ikvm\
Download:
Java 8 SDK (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
Install and make sure location is added to path
Download:
NAnt 0.92 (https://sourceforge.net/projects/nant/files/nant/0.92/nant-0.92-bin.zip/download)
Unzip and place "nant-0.92" folder in c:\ikvm\
ICSharpCode.SharpZipLib.dll (http://www.icsharpcode.net/opensource/sharpziplib/Download.aspx)
Place "ICSharpCode.SharpZipLib.dll" in C:\ikvm\ikvm-8.1.5717.0\bin\
Open the following file in a text editor and change the version number:
C:\ikvm\ikvm-8.1.5717.0\CommonAssemblyInfo.cs.in
Using command prompt from earlier, cd to:
C:\ikvm\ikvm-8.1.5717.0\ikvm\
Run:
..\nant-0.92\bin\NAnt.exe
If successful all the binaries will be in:
C:\ikvm\ikvm-8.1.5717.0\bin

Categories