Attribute.IsDefined is not available in portable class library - c#

Why I do not have access to Attribute.IsDefined() in a portable class library? How could I use this method in PCL? In a class library the following code works perfect but in a pcl it says there is no method there.
if (Attribute.IsDefined(item, typeof(Title))) ...
Title is an attribute. Is it possible to solve this problem by adding a reference or something to the project?

Related

Wrong reference of Newtonsoft assembly for class library in another program

I have a class library in .NET Framework 4.7.2 and I use a reference to Newtonsoft.Json Version 12... something.
If I run the app as a windows application (there is a winform) everything works just fine. However, it is actually a class library that is being called by another program as a plugin. Inside that program I get however this error
Which translates basically to "couldn't find the Assembly...". There Version=12.0.0.0 is begin referenced and the dll in that particular folder (the plugin folder) says version 12.0.3.23909
I tried to clean the solution, delete every reference to newtonsoft I found etc. but the result is always identical. What am I missing?
Sorry if this question has been answered before, I searched dozens of previous questions, but I can't seem to understand what is going on appart from "redo everything", which doesn't work here.
UPDATE
The output bin is as follows
If I change the program to a windows application and run it by calling the exe, it works, but not via the other program where it should run as a plugin. Interestingly, the core dll is being opened and the baseform works, but not newtonsoft.
Change at least one of the versions. I mean:
Change the version of Newtonsoft of your class library to -> 12.0.3.23909 and then build the class library and use it as a plugin.
Or change the Newtonsoft version of your project to 12.0.0 and then use your class lib as a plugin inside it.
Or:
You can carry Newtonsoft (12.0.0) with your class library and load both of Newtonsft and your class library as a plugin. (this works too but you should be aware of Dll conflict between 12.0.0 and 12.0.3)

Global.cs file replacement in .Net Standard Class library

I am new to .net standard/.net core/blazer. In .net framework class library we used to have Global.cs file to store global variables, needs to do the same in .net standard class library, whats the Microsoft recommended way?
OR to summarise above:
where to store Global variables in .Net standard class library project?
In Class library projects you put it in Web.config (or App.config) and it will be available from the class library as well. You basically add manually such file (app.config/webconfig).
If you're going to use a class library, I would recommend having any variables etc passed in via configuration parameters/configuration objects, and if you need defaults - have defaults created in your constructors.
I would personally shy away from having a class lib access web.config/appSettings.json, as you're then tieing your application to a specific implementation.

DLL References into Application but not Class Library

I am trying to integrate the WeifenLuo.WinformsUI.Docking assembly into my application. To rule out external factors I created a new .Net 4 Winforms app and reference the DLL. Works fine.
I then created a .Net 4 Class Library and referenced the DLL. This this doesn't work and as soon as I try to use anything in that Docking namespace it won't compile.
To recap
C# Exe ---reference--> WeifenLuo.WinFormsUI.Docking.DockPanel.dll // OK
C# Class library ---reference--> WeifenLuo.WinFormsUI.Docking.DockPanel.dll // Not OK
I also have the WeifenLuo source and confirmed it's a class library referencing the same version of .Net. I tried adding a class library in their sample solution and referencing the WinForms project directly (not the result in assembly) and it still isn't linking properly.
Updating with Screenshot
You can't declare a private variable Inside a namespace.
Try the following code
namespace Test
{
public class Class1
{
private WeifenLuo.WinFormsUI.Docking.DockPanel dockPannel;
}
}
And if it still doesn't work, provide the error message.

Portable Class Library using F# without FSharp.Core.dll reference

I tried to create portable class library using F# which could be used for example from C# code. But looks like using standard F# constructs, like raise makes FSharp.Core.dll necessary to use created Portable Class Library.
raise(ArgumentNullException("parameter")) is transformed into
Operators.Raise<Unit>(new ArgumentNullException("source"));
(where Operators.Raise lives in Microsoft.FSharp.Core namespace) instead of just
throw new Exception
I assume that's not the only F# construct which is compiled to some static method from FSharp.Core.dll library.
Is there any way to create F# code (especially Portable Class Library) which after compilation does not require a reference to FSharp.Core.dll or any other FSharp-specific library?
If you compile the code with
--standalone
the compiler will do an equivalent of static linking. As a result, the references won't be needed at run time.
This is probably the best you can do.
Ideally you would be referencing a portable version of FSharp.Core that have been built against a certain profile, rather than statically linking everything.
I think there are portable versions of profile 47, 88, and 158.

C# Portable Class Library - How do you include System.Data.Linq

Is it possible to reference the System.Data.Linq in a Portable Class Library project?
Note:
I am just trying to share code between a WP8 and WinStore8 app [DataContext]
No it is not. The Data namespace is unavailable in PCLs.
You can tell because http://msdn.microsoft.com/en-us/library/system.data.aspx none of its members have the PCL icon, and it is not listed on http://msdn.microsoft.com/en-us/library/vstudio/gg597391%28v=vs.100%29.aspx

Categories

Resources