I am trying to compile my project with mono on linux. My cmd looks something like...
gmcs Pages/UserProfile.cs Properties/AssemblyInfo.cs queues.cs watch_editor.cs Class1.cs -define:USE_SQLITE -r:System -r:System.Collections -r:System.Collections.Generic -r:System.Collections.ObjectModel -r:System.Collections.Specialized -r:System.Configuration
but much long. and i get the output
error CS0006: cannot find metadata file `System.Collections'
error CS0006: cannot find metadata file `System.Collections.Generic'
error CS0006: cannot find metadata file `System.Collections.ObjectModel'
...
How do i solve this?
I also tried it the other way around (below) and had the same error msg with .dll at the end of them
gmcs -define:USE_SQLITE -r:System.dll -r:System.Collections.dll -r:System.Web.UI.WebControls CommentCenter.cs cookies.cs db.cs Default.aspx.cs
You are confusing assemblies and namespaces. An assembly, such as System.dll, is a binary library file that can contain types in multiple namespaces. A namespace can be split across multiple assemblies, and the assembly name doesn't have to match the namespaces in any way.
-r is for referencing assemblies. You do not need to reference namespaces.
Given that most of the classes in those namespaces are in mscorlib (which is referenced by default) or System.dll, you probably just want
gmcs Pages/UserProfile.cs Properties/AssemblyInfo.cs queues.cs watch_editor.cs Class1.cs -define:USE_SQLITE -r:System
I strongly suggest you use an IDE such as MonoDevelop. You can view the compiler commands it generates, if you're interested.
Related
Im using .NET Framework 4.8 and Im using the ClosedXML Library,but my programm is an class Library type of programm so that the dll of the programm will land in an different folder where all other additional dll like the closedXML dll are not allowed to be there in that folder. So if i want to execute the dll I get error message that the Assembly references not are found, which is logic because in the other folder all the dll like closedXML are not in the folder and cant be referenced.
So what I tried to do is to embedded the Interop Type set to true.
But when I set it to true I get these two Error Messages:
Error CS1747 Interoptypes cannot be embedded from assembly "DocumentFormat.OpenXml, Version=2.19.0.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17" because the System.Runtime.InteropServices.GuidAttribute attribute is missing.
and
Error CS1759 Cannot embed interoptypes from assembly "DocumentFormat.OpenXml, Version=2.19.0.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17" because either the System.Runtime.InteropServices.ImportedFromTypeLibAttribute attribute or the System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute attribute is missing.
what I tried to fix this problem was at first rebuild entire solution and install the dll new.
And I tried to add this Code to the assemblyinfor.cs file:
[assembly: System.Runtime.InteropServices.Guid("2e197457-53cd-4261-81b6-07c65281b2a3")]
[assembly: PrimaryInteropAssembly(1, 0)]
but I get the Error message still, all the dll are on the newest version.
Someone an Idea how to set the Interop Type to true without getting this Error message?
I have to extend an in-house build system to compile C# files targeting .Net Core 3.
As of now, the system is capable of processing source sets, references, and lib directories,
where it generates the following command:
"C:\Program Files\dotnet\dotnet.exe" exec "C:/Program Files/dotnet/sdk/3.1.300/Roslyn/bincore/csc.dll" -nologo -target:library "-lib:C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.1.4" -r:netstandard.dll C:/Users/kirsch/Documents/Repositories/ComplexProject/lib/csharp/native/VeryComplexLogic.cs -out:C:/Users/kirsch/Documents/Repositories/ComplexProject/default/ComplexProject.net.626a237a/ComplexProject.net.dll
Sadly, this fails with the following error:
error CS0518: Predefined type 'System.Object' is not defined or imported
I tried to search for a solution. The proposed solutions either suggested something, that was not related (like deleting some generated directory), or suggested to add references. Pursuing the latter, I added the following references:
netstandard.dll
mscorlib.dll
System.dll
System.Core.dll
Referencing these did, however, not solve the problem.
To conclude my question:
Which reference am I missing?
If it's not a reference, what else am I missing then?
You need System.Runtime.dll.
Please note that just providing
/lib:"C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.1.4"
is not enough. This is only a directory where the referenced assemblies will be searched for. But you still need to provide each particular referenced assembly by the /reference (or /r) option:
/reference:mscorlib.dll /reference:netstandard.dll /reference:System.Collections.dll /reference:System.Console.dll
... etc
MSBuild or dotnet.exe do this for you.
I had a problem running my C# application throwing the following error when trying to use a certain reference as follows:
Could not load file or assembly 'My3rdPartyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)"
Then I followed this answer for signing the assembly in question.
I can confirm via Visual Studio and Sn as well that my DLL is now definitely signed and has a strong name.
However I am seeing 2 things:
On my signed version of the application I still get the same error as above as if the assembly does not have a strong name.
On my unsigned version which was working fine until now with the unsigned DLL, it now throws the same error with the signed version of the DLL.
I am out of clue on what could be the reason.
Thx for the help.
It turns out that I was able to solve it. I was updating the third-party library (the assembly that I want to sign) so that it can work well with my .exe BUT it gets replaced by an unsigned version that came from the NuGet package.
You'll have to update the .dll in the following location:
I will have instruction for an example package named WPFCustomMessageBox.dll. Follow the ff. steps to update the package and have it reflect on the debug folder:
Open cmd in the path provided above.
Type the ff. You should organize the path in your system as your folder structure and where your files are located may not be the same as mine:
a. This one gets the necessary files from the .dll
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\Ildasm.exe" /all /out=WPFCustomMessageBox.il WPFCustomMessageBox.dll
b. I'm not sure what this one does but it preps the file for the next command.
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Ilasm.exe" "WPFCustomMessageBox.il" /dll /resource="WPFCustomMessageBox.res" /key="publickey.snk"
c. This one creates the signed .dll
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\sn.exe" -R "WPFCustomMessageBox.dll" "pair.pfx"
Type the password for your .pfx file and it should make the signed .dll.
I've tested this method with the aid from Adding a Strong Name to a Third-Party Assembly. The next time you compile, the former unsigned .dll that gets compiled/copied over to the Debug folder should be signed. Hope this helps :)
I'm trying to create a single-file executable. The code is .Net-based and also relies on some additional libraries including SQLite.
When I compile the source code, all of the relevant files go into the Release directory, although the SQLite DLL (sqlite3.dll) goes into a sub-directory (x86). I think this happens because I'm using SQLite-raw and that "spits out" both x86 and x64 copies of the DLL.
My initial command line to try is:
ILMerge /out:GEDtoRH.all.exe GEDtoRH.exe *.dll /target:exe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2" /wildcards /log
This produces the following output that worries me:
AssemblyResolver: Assembly 'System.Runtime.WindowsRuntime' is referencing assembly 'System.Runtime'.
...
AssemblyResolver: Did not find assembly in framework directory.
AssemblyResolver: Unable to resolve reference. (It still might be found, e.g., in the GAC.)
AssemblyResolver: Assembly 'System.Runtime.WindowsRuntime' is referencing assembly 'System.Threading.Tasks'.
...
AssemblyResolver: Did not find assembly in framework directory.
AssemblyResolver: Unable to resolve reference. (It still might be found, e.g., in the GAC.)
AssemblyResolver: Assembly 'System.Runtime.WindowsRuntime' is referencing assembly 'System.IO'.
...
AssemblyResolver: Did not find assembly in framework directory.
AssemblyResolver: Unable to resolve reference. (It still might be found, e.g., in the GAC.)
Location for referenced module 'sqlite3' is ''
Should I be concerned about the unresolved references? The reason I ask is because the finished executable doesn't work. It breaks with a null reference exception (Object reference not set to an instance of an object) on this line:
file = await StorageFile.GetFileFromPathAsync(filename);
The un-merged version of the executable works fine :( It isn't "filename" that is broken as I've tried adding some extra tests and it is fine.
Try as I might to add the sqlite3.dll to the list of things to ingest, if I try, ILMerge just complains with a "Could not load assembly" error.
As SQLite is not a .NET library it doesn't contain any IL to be merged
Using the code in this link I am attempting to compile a generated .cs file at runtime. The file (call it Gen.cs) has been generated by CodeDOM and subclasses another file (call it Base.cs). I get the following error message from the runtime compilation:
The type or namespace name `Base' could not be found. Are you missing a using directive or an assembly reference?
I know that this error means it can't find Base.cs when it's compiling. I'm new to both C# and compiling C# files dynamically, so this is a bit hard to pick apart. Neither Base nor Gen use namespaces, and both .cs files are in the same directory. Is there anything I'm missing? Why can't Gen.cs see Base.cs?
EDIT - This may or may not be relevant, but here's the result of a manual compilation via gmcs (I'm on MacOS)
mtrc$ gmcs -lib:Base.cs Gen.cs
Gen.cs(13,27): error CS0246: The type or namespace name
`Base' could not be found. Are you missing a using
directive or an assembly reference?
Typically a compiler will only compile source files that it's been told to compile in a single pass. ie: specify all .cs names on the command line, or specify to compile all .cs files in a given folder.
In this case:
string []arrCode = { code, "base.cs" };
CompilerResults results =
compiler.CompileAssemblyFromSource(compilerparams, arrCode);
Alternative syntax:
CompilerResults results =
compiler.CompileAssemblyFromSource(compilerparams, code, "base.cs");