I want to create a DLL in C# that I will later import in a Blender Python Export script.
Never created a DLL before.
I created a simple project (Class Library .NET standard). I only need the basic types, and a 3dVector class that allows me to do basic operations with Vectors (+,-, dot and cross).
I tried to use System.Windows.Media.Media3D (to be able to use Vector3d), imported PresentationCore.dll, but then everytime I was using Vector3d I got:
Error CS0012 The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
If I add mscorlib.dll then I get further errors.
Is there an easy way to setup a project in C# to create a dll and have a basic vector3d class?
Thanks!
I created a simple project (Class Library .NET standard).
.NET Standard is for portable libraries. This means you won't be able to use any native Windows functionality such as graphics in a .NET Standard class library.
If you look on apisof.net, you can see that the type System.Windows.Media.Media3D.Vector3D is only supported on .NET Framework, not on .NET Standard.
So, to make this work you need to create a Class Library targeting .NET Framework instead of .NET Standard.
Related
Is there any way to convert a JSON object into a Custom object without using serialization in .NET core 1.0 . As I'm using .net framework 4.5 built dll and the models which are defined in it are with [Serialize] attribute over it. So when i try to convert the JSON string into object, I'm facing the below error:
Could not load file or assembly 'System.Runtime.Serialization,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The system cannot find the file specified.
The dll internally is referring to the Serialization class in it.
Code snippet which I'm using to convert to object
public void ConvertToObject(string jsonString)
{
return JsonConvert.DeserializeObject<CustomObject>(json);
//This line throws error
}
I believe that the problem is only because of the [Serialize] attribute, but we do not have the control to modify the provided dll. And also we just need to stick with NET Core 1.0. I have tried it in Core 2.0 and its working.
There is a mess with loading referenced dll in .Net Core projects (not sure if it's fixed in Core 2.0). Try adding reference to the System.Runtime.Serialization dll for the most top project you are running. E.g. you have the following structure:
(a) Web application (ASP.Net Core) ==> (b) .Net Core DLL ==> (c) .Net 4.5 dll
Where (c) is dll with Serialize attribute
Add reference to System.Runtime.Serialization for (a)
Note: adding that reference for (b) might also help, but if you have deeper solution structure and have other projects that reference to (b), it may break again, so top project is your choice
I am attempting to use the System.Numerics.BigInteger struct from within a Xamarin.Android project, but the System.Numerics namespace is not accessible, despite having installed the latest version of the Nuget package that claims to contain BigInteger:
Update: If I create a .NET Standard 1.6 class library, I can reference BigInteger from within it. I find it hard to understand why BigInteger is not accessible from with the Android project, which also references .NET Standard 1.6. I can also reference the class library from the Xamarin.Android project and build the solution, but if the Android project tries to access any method in the class library that returns a BigInteger, the compile complains:
The type 'BigInteger' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Numerics, Version=2.0.5.0 ... '.
Any suggestions please?
I have recently made the decision to try and re-standardise my older style PCL's from the (apparently archaic) old approach of portable-net451+win81+wpa81 to now netstandard1.x. I took this decision as Xamarin Forms on my Mac was no longer recognising one of my libraries as a NuGet package.
Anyway, having started this conversion I have entered a world of unknown pain in the sense that it isn't a very automatic process. I'm now at the stage where I think I've converted my PCL's to net standard libraries but now I'm trying to reference these standards within a 'normal' windows console app I get odd errors.
Primarily my errors are thus:
Error CS0012: The type System.Linq.IQueryable 1<TItem> is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Linq.Expressions, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (CS0012)
Error CS0012: The type System.Collections.IEnumerable is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (CS0012) (Redbridge.Console)
Now given that my project is referencing one of my net standard libraries and this error originates from me using a class that requires packages System.Linq.Queryable and System.Linq to be added specifically to my net standard library I can't help but wonder how I'm meant to make this work in my console app library. I note that the versions are .20 rather than the standard .0 so what do I do to make this work?
I've tried the obvious (referencing the above packages in my console app as suggested by the compiler) but to no effect. Does anyone have any advice? Do I need to add a project.json file for example to my console app so that I can indicate that .NET standard should be used or something?
I've read quite a bit on the .NET standard and like most find it confusing as to what I'm expected to do.
This is probably a dumb question but I can't for the life of me figure it out. I'm trying to use the a Tesseract C# wrapper (https://github.com/charlesw/tesseract) and I've got it all working except for one error that reads
Error 11 The type 'System.Drawing.Bitmap' is defined in an assembly
that is not referenced. You must add a reference to assembly
'System.Drawing, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'.
My first thought was "oh, let me just add an assembly reference to System.Drawing". Except there isn't one. When I right click References in the Solution Explorer -> Add Reference -> Assemblies -> Framework there is no System.Drawing. I did find System.Drawing.dll under COM, but it won't let me add it, saying
The ActiveX type Library [path] was exported from a .NET assembly and cannot be added as a reference. Add a reference to the .NET assembly instead.
Typing "using System.Drawing" at the top of my program does not cause an error, but it also does not solve the problem.
Any help is appreciated.
Edit: Am I in the right place?
You won't go far with this project, there's this dependency for System.Drawing and the whole project doesn't seem like it's targeted towards Xamarin.
As written here Xamarin Tesseract OCR binding for Android there are bindings for Xamarin.iOS, and the person is asking for bindings for Xamarin.Android. There's indeed a version of tesseract for Android here https://github.com/rmtheis/tess-two and apparently the response is to create a binding to this Java Android version.
Both projects, the binding for Xamarin.iOS as well as Xamarin.Android are bindings to platform specific bindings who both wrap the native C++ library. Probably the best solution would be to completely bypass the Java and Objective-C wrapper by create a specific P/Invoke wrapper for C#using SWIG.
I have 3 projects - silverlight app A and 2 silverlight class libraries B,C. My serialization logic is in project C, Method CallSer(). If the routine from B calls CallSer(), everything works fine. But if routine from C calls CallSer(), it gives the below error. I have tried setting Copy Local property but it's not helped (I am seeing the assemblies getting copied to the debug folder when Copy Local = True). This seems to be surprising, any one has ideas on how to resolve this? Thanks.
{System.IO.FileNotFoundException: Could not load file or assembly
'System.Xml, Version=5.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The
system cannot find the file specified. File name: 'System.Xml,
Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'}
Update: I did a little more analysis and found the call to CallSer() is actually from another .NET class library D. So call stack shows is D -> C -> CallSer(). I am not sure what difference this can make as long as I have System.Xml.Serialization reference to C. Also, I don't see System.Xml.Serialization listed in Add Reference option for D? Why is that so?
Update: Looks like XmlSerializer is getting confused as to which reference to load.That's because Silverlight has XmlSerializer defined inside System.Xml.Serialization.dll assembly and .NET framework has it in System.Xml.dll. My project D has reference to System.Xml and C has System.Xml and System.Xml.Serialization. How do I make sure C always references Silverlight version of dlls?
I came across the same issue trying to run unit tests, the problem is that if the code that is calling the Silverlight Class Library is built against the "desktop" .Net Framework you will get the conflict as it will not be able to load the Silverlight version of the dll, only the Silverlight runtime can load dll's built against the Silverlight CLR/BCL.
Take a look at creating a Portable Class Library and the Portable Library Tool
I had the same problem with Xml.Writer.
I worked around it by sharing my source code file between my silverlight project and my non-silverlight project, using 'Add as Link' in Visual Studio.
I also had to use #ifdef SILVERLIGHT to have a separate namespace.
Lloyd's Portable Class Library approach seems cleaner but I didn't have time to try it.