RDLC ReportViewer control error with VS2022 WPF [duplicate] - c#

Hi I've created a new solution on .net 6 on VS2022 , and now I need to create reports but it looks like there is no way in vs2022. is there a way to use reporting services RDLC files in WPF on VS2002 ?
Mean a while I've open the solution on VS2009 in order to use it for building RDLC reports, but when I try to associate the data source to an Object I got this error
My object is a Class in a referenced project (class library .net6) the class is:
public class prueba
{
public int MyProperty { get; set; }
public int prop2 { get; set; }
public int prop3 { get; set; }
}

There is now a RDLC Report Designer Add-In for Visual Studio 2022.
To use those reports in your application, you need an RDLC renderer (aka "Microsoft ReportViewer"), which is available for .NET 4.0-4.8 as a nuget package:
Microsoft.ReportingServices.ReportViewerControl.Winforms
Microsoft.ReportingServices.ReportViewerControl.WebForms
Do note, though, that Microsoft did not release a ReportViewer for .NET Core or .NET 5+, and they have announced that do not intend to release one in the future (see, for example, the comments on this blog post).
There are some enthusiast ports/recompilations floating around on github and nuget, but they are not from Microsoft, nor has Microsoft given them permission to do that, so using those packages carries a certain amount of technical and legal risk. That's not something you want to do in a commercial project.

You only can use projects with netstandard, 2.0 or 2.1
so the class you will use as a data source only can be in a project using .NetFramework or netstandard.

Related

Roslyn Source Generator not generating any source in a .net framework 4.7.2

Probably a simple learning issue, but I'm attempting to use the new roslyn source generators to automatically generate some source code for .net framework 4.7.2 (mvc is the goal, but I'll be happy if it worked in my test console app).
Here's my code
[Generator]
public class GenerateCommand : ISourceGenerator
{
public const string TestCode = #"
namespace Test
{
public static class Hello
{
public static string World = ""Hi from generated code."";
}
}";
public void Initialize(InitializationContext context) { }
public void Execute(SourceGeneratorContext context)
{
context.AddSource("Hint_Hello_World", SourceText.From(TestCode, Encoding.UTF8));
}
public void Test()
{
var x = Test.Hello.World; // <-- Refuses to build.
}
}
}
Package versions are Microsoft.CodeAnalysis.CSharp v 3.7.0 (and associated roslyn stuff)
This seems to be about as simple as I can make it and it seems to work if I'm targeting .net core, it's just when I'm trying to add it to a framework project that it does nothing. No errors, no output messages, just not running or generating source.
Any help would be appreciated.
Update: As of Roslyn 3.8 / Visual Studio 16.8 source generators are no longer behind a preview flag, and should work for any language version or target framework.
Ensure you check out the Breaking changes section of the cookbook to address any API differences between preview and release.
Currently source generators are gated behind <langversion>preview</langversion> as they aren't a released feature, and we don't want customers accidentally using them without realizing it.~~
At release time we'll remove the language version restriction and they'll work on any supported Roslyn compiler, although it will be up to the individual generator authors to ensure that the code they generate is correct for the project options the user has selected.
Edit thanks to Chris Sienkiewicz: Currently source code generators are gated behind the preview language version and thus not available for other .NET versions than .NET 5. This will however change once source code generators are released and stable.
Old Answer:
Source code generators are a .NET (Core) 5/ C# 9 feature, there is no way to get it to work with .NET Framework (or .NET Core != 5). If you need to generate code at compile time, you have a few options:
Use a T4 template
Add a pre-build event
Use a NuGet package like Clarius.TransformOnBuild

XMLSerializer class throwing "array must no be null" exception when compiled in Visual Studio 2017 and .NET 3.5

I have old code written using VS2008 which I transfered to VS2017. Code was using .NET 2.0
If I build it using VS2017 and .NET 2.0 I get an "Array cannot be null." in the XMLSerializer constructor
If I use VS2015 and .NET 2.0 the code is working. With VS2017 it only works if I switch to .NET 4.0 or higher. With VS2015 it is working with all .NET versions.
The call stack on exception looks like this:
at System.Reflection.Assembly.nLoadImage(...
at System.Reflection.Assembly.Load(...
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(...
at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(...
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(...
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(...
at System.Xml.Serialization.Compiler.Compile(...
at System.Xml.Serialization.TempAssembly.GenerateAssembly(...at System.Xml.Serialization.TempAssembly..ctor(...
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(...
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at XMLSerializerTestVS2017.Form1.button1_Click(....
I was able to reproduce the problem with just a few lines of code.
Exception pops up on the line
XmlSerializer serializer = new XmlSerializer(typeof(MyData));
And I have defined the MyData class like this (just for testing)
[XmlRoot(ElementName = "root")]
public class MyData
{
[XmlElement(ElementName = "MY_XML_A_ENTITY")]
public string A { get; set; }
[XmlAttribute(AttributeName = "xml_b_attrtibute")]
public string B { get; set; }
[XmlElement(ElementName = "MY_XML_C_ENTITY")]
public int C { get; set; }
}
Does anybody has an idea what could be the reason for this behaviour. The code compiles without problems. Why VS2017 with .NET 3.5 or older is not working on this simple example? I also tried to switch the VS2017 to use C# version 3.0 for compilationa but it made no difference. VS2015 and older (I have tried them out 2013, 2010 & 2008) are all working fine with any .NET version.
Any input is more than welcome! Thx!
REMARK:
I am not sure if this is the proper way to handle this, I didn't want to answer my own question because others came with ideas that explained the possible cause for my problem so I I though it would be unapropriate to take the credit for the answer. It seems that something is wrong with my machine (Thx Jack!). Testing the code built with VS2017 and .NET2.0 or 3.5 worked just fine in a fresh VMWare. So I guess there is something wrong on my machine causing the trouble. I still do not know what exactly it is, but if I find out I'll post here.
Thank you all for help!
REMARK No. 2
It seems it is not just my computer. Even though the compiled test code worked in a fresh VMWare, the exception showed again as I run the test code on a machine belonging to a colleague developer. Currently I am inclined to beleive that the problem has to do with VS2017.
REMARK No. 3
I did some more testing on other machines on our site. I have tried machines without Visual Studio 2017. The error popped up on those machines to. I am not sure what to conclude from that, but it seems that the combination of compiling with Visual Studio 2017 and running on machines with all the Microsoft updates on it somehow creates the described problem.

Is this a valid syntax in C# .NET 4.6.2

public class MyClass
{
public string DeviceCommands { get; set; } = "DeviceCommands";
}
I have 30 errors on this kind of lines...
.NET 4.6.2 is a framework version, not a language version. To be able to do that line you must be using C# 6 or newer. If you are compiling with C# 6 you would be allowed to use that syntax in a .NET 2.0 project.
If you are using Visual Studio 2015 or newer you are using C# 6 or newer.
If you are using Visual Studio 2015 and are still getting errors there is some other problem with your code that you are not showing us.
UPDATE:
If you are using VS2015 and are getting a error that says
Error CS8026: Feature 'auto property initializer' is not available in C# 5. Please use language version 6 or greater.
That means in your project properties -> Build -> Advanced screen you set the language version manually to 5 or lower instead of default.
Setting it back to default will fix the problem.
The syntax you have are Auto Property Initializers.
It has nothing to do with the .NET Version. It is a language feature from C# 6.0.
You need the the roslyn compiler plattform to make this work.
If you can not support C# 6.0, you could do it the old way:
public class MyClass
{
public string DeviceCommands { get; set; };
public MyClass()
{
DeviceCommands = "DeviceCommands";
}
}

I am trying to install and use ProtoBuf for Windows .NET C# and I am having problems

I just installed protobuf for Java and that is working great.
I am now trying to install protobuf for .NET 4.0 for C# language.
First of all the protobuf website does not have any install instructions.
I downloaded the latest binaries, which are mostly dlls.
Where do I put these dlls?
Also there is a protoc compiler but it only has an output option for C++, not C#.
Where is there a C# option?
I created a test file, which is an exact copy of the example on this page and I am getting errors(Error 1 - expected top level statement)?
https://code.google.com/p/protobuf-net/wiki/GettingStarted
[ProtoContract]
class Person {
[ProtoMember(1)]
public int Id {get;set;}
[ProtoMember(2)]
public string Name {get;set:}
[ProtoMember(3)]
public Address Address {get;set;}
}
[ProtoContract]
class Address {
[ProtoMember(1)]
public string Line1 {get;set;}
[ProtoMember(2)]
public string Line2 {get;set;}
}
You need to download protobuf project from below link :
Proto Buf C# project Download Link
Install Package manager steps :
enter link description here
If Package manager is not available in you VS IDE. then down load from below link :
Package manager console download link
To generate protobuf Library for C#: follow below steps :
1) Open downloaded project in Visual studio
2) Goto package manager and type below command
PM> Install-Package protobuf-net
3) Above command will generate libraries for protobuf.
(i) Google.ProtocolBuffers
(ii) Google.ProtocolBuffers.Serialization
I hope this helps :)

Sharing assemblies using Portable Class Library with DataAnnotations

I have created a portable class library called DataContracts that contains my projects Messages and Views. Standard stuff like GetStockItemByIDRequest and StockView are contained in it.
The problem lies when I attempt to add DataAnnotations by using System.ComponentModel.DataAnnotations for some of my Views as such.
[DataContract]
public class StockView
{
[Required]
[DataMember]
public Guid StockID { get; set; }
[Required]
[DataMember]
public string Name { get; set; }
}
I can successfully add the System.ComponentModel.DataAnnotations to my Portable Class Library project and can successfully reference it in my Windows Phone 8 app and can even create a new instance of my view as such StockView View = new StockView(); within my Windows Phone App BUT if I try to use either Newtonsoft.Json or System.Net.Http.HttpClient by doing something like
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://myservice.com");
T result = await response.Content.ReadAsAsync<T>();
OR
T result = await Newtonsoft.Json.JsonConvert.DeserializeObjectAsync<T>("{}");
ie: where deserialization is involved...
I am faced with the error Could not load file or assembly 'System.ComponentModel.DataAnnotations, Version=2.0.5.0'. Which I assume is because it doesn't appear that System.ComponentModel.DataAnnotations is supported in Windows Phone 8 (but then why can I add it as a reference to my PCL?).
So my questions are, why isn't this error invoked when I create a new instance of these classes directly and secondly how do I work around this?
Unfortunately DataAnnotations is not currently portable. While a bit complicated, you can probably work around that by writing your own DataAnnotation attributes in a PCL, and creating an assembly with the same name for .NET Framework projects which type-forwards the attributes to the "real" versions. See this answer for some more details on this.
OK, so it turns out that my original assumptions were completely wrong. You absolutely can reference the System.ComponentModel.DataAnnotations namespace from a Windows Phone 8 project.
Basically it comes down to counterintuatively referencing the silverlight version of the dll which can be located in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.ComponentModel.DataAnnotations.dll
For more information about how to build portable class libraries I suggest referring to this article .
Data annotations is supported in certain PCL profiles.
Supported profiles:
.NET 4.0.3 and up
Windows Store 8 and up
Silverlight 4 and up
Most notably, the latest Windows Phone is not supported (8.1 at the time).
See full PCL feature table in:
http://msdn.microsoft.com/en-us/library/gg597391%28v=vs.110%29.aspx
1) The process of create a new class instance doesn't involve read custom attributes, that are loaded by reflection.
2) The System.ComponentModel.DataAnnotations is exclusive for ASP.NET
The System.ComponentModel.DataAnnotations namespace provides attribute
classes that are used to define metadata for ASP.NET MVC and ASP.NET
data controls.
The portable version of System.ComponentModel.DataAnnotations seems incomplete (eg no MaxLengthAttribute).
There is this library:
https://github.com/ryanhorath/PortableDataAnnotations:
Install-Package Portable.DataAnnotations
Your PCL needs to target Silverlight 8, otherwise you will get multiple class definition errors.

Categories

Resources