No System.Drawing dll - c#

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.

Related

C# CodeDom System.TypeLoadException XamMac2 Xamarin macOS

I'm coding a complex application that makes use of CodeDom to instantiate objects with reflection. It is, however, mixed between netstandard2.0 (the wrapper in between that also supports net461) and net461 projects.
As I've read, it is very possible to make reference to previous versions of the framework, this case the following:
{System.TypeLoadException: Could not resolve type with token 01000067 from typeref (expected class 'System.CodeDom.Compiler.CompilerParameters' in assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
Disregarding the System reference that gets loaded in memory for the Xamarin Mac executable.
What doesn't fit is the code looking for the a System assembly that maybe gets overwritten with the Xamarin System assembly.
Do you know any workaround for this? Other than migrating entirely the remaining set of projects to hybrid between netstandard2.0 and net461.
Thanks.
Indeed.
There was a mismatch between the System.CodeDom assembly that is packed inside System.dll and the one that must be referenced for the project to build.
This got solved by targeting netstandard2.0 with both net461 set.
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
</PropertyGroup>
Like so.

Do I need to modify my existing csproj or add a project.json file to a command project that references a new .net standard library?

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.

Xamarin missing references

I have just tried to import one of my windows library into a Xamarin android app and get the following error:
Exception while loading assemblies: System.IO.FileNotFoundException:
Could not load assembly 'System.Web.Extensions, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Perhaps it doesn't
exist in the Mono for Android profile? File name:
'System.Web.Extensions.dll' at
Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference
reference, ReaderParameters parameters) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1
assemblies, AssemblyDefinition assembly, Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.Execute() App7
Even if i try to manually add the reference into the app, it still don't works.
Is there any support by mono for this library(i find it very usefull) System.Web.Extensions.
Any workarounds would be much appreciated cause i wouldn't want either to rewrite a working dll or stop development in xamarin.
PS: I tried adding manually all the required dlls ending up in deploy errors without any description.
System.Web does not really have much meaning outside the context of a web server so from a Xamarin perspective I doubt it will be implemented.
You could try and add it:
System.Web.dll inn project references, click edit -> Net Assembly -> Browse, go to root - Library/Frameworks/Mono.Framework/Versions/4.2.2/lib/mono/4.5/System.Web
Alternatively you might need to look at this external lib that you're trying to import to see if you can remove any references and rebuild.
For example it might be using log4net which includes System.Web
Well it seems that i have located an answer and will post it in order to help others also.
First of all i tried all the dll references suggested by VS in order not to change any parts of my code. That failed after adding more than 20 references. I spent more than an hour on that.
Secondly i decided as suggested by #jaymarvels to check a library from nuget. I went with Json.net changing only one line of code as shown below:
Code before:
var serializer11 = new System.Web.Script.Serialization.JavaScriptSerializer();
T dc1 = serializer11.Deserialize<T>(json);
To code :
T dc1 = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
Then the project started working without any problems. I have some considerations regarding the librarys speed but for my project, speed is not that essential, so i will happily use it for some time.

Unreferenced library and ambiguous DLLs when porting Skinned Model sample to MonoGame

I'm trying to port the Skinned Model animation sample from XNA to Monogame and I got several dll errors.
To get the SkinnedModelProcessor.cs class to work properly I had to reference the content pipeline dlls and this gives the following errors:
error CS0012: The type 'Microsoft.Xna.Framework.Matrix' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553'.
And a bunch of other errors related to the Matrix struct. Matrix gets recognized and Intellisensed, but still wants the other Matrix class. (It picks up the correct Matrix class when using Microsoft.Xna.Framework.Content.Pipeline.Processors; is removed but then the ModelContent type doesn't get referenced.
If I add the assembly as the error tells me I get tons of errors about duplicate data types (the MonoGame and XNA ones crashing each other because they have the same name and namespace.).
I've found solutions online that edit the .sln file and exclude the XNA assemblies out of the build event, but they don't seem to do anything. You can view the sample on MSDN, nothing was changed to the code and most classes aside from the SkinnedModelProcessor compile correctly. Any help?
Thanks,
Nick.
The Monogame doesn't use XNA assemblies after project being built. Skinned model processor is a XNA assembly namely extension of a XNA Content Pipeline. When you are trying to run your project already ported game is trying to access XNA assemblies which cannot be supported by monogame project.
P.S. As you could noticed the monogame project doesn't use XNA content project. It has the assets folder where you put your precompiled .xnb content. Therefore there is no XNA content assemblies which are referenced to a project.

could not load system.xml with silverlight class library

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.

Categories

Resources