.NET Framework 4.0 System.IO reference missing Path Class - .net-4.0

I've been reading some answers on stack overflow specifically.. Get file name from a path string in C#. My problem is that after I've added using System.IO; above the namespace. Then attempted to call the method Path.GetFileNameWithoutExtension(fullPath);, I can't because the Path Class has not been included within my System.IO reference.
(source: iforce.co.nz)
Even though I'm using .NET framework 4.0 with VisualStudio 2010.
(source: iforce.co.nz)
Could the using System.Windows.Shapes; reference cause issues with the System.IO reference? why can't I use the Path Class (even though MSDN states that .NET Framework 4.0 is compatible)??

System.IO.Path is not a valid using directive. All you need to do is remove it!
using System.IO; is adequate enough, then Path.GetFileNameWithoutExtension() validates fine:
The Path is a class and System.IO is the namespace.

Related

Generate a class from xsd file in net core

I need to generate a class from an xsd in net core.
In dotnet standard I used commandline xsd filename.xsd /c.
But how to I create this class in net core.
Anyone knows how to do this?
When I add a class generated with xsd.exe I get several errors.
Example
Error CS0234 The type or namespace name 'SerializableAttributeAttribute' does not exist in the namespace 'System' (are you missing an assembly reference?)
Error CS0234 The type or namespace name 'DesignerCategoryAttribute' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?)
Error CS0234 The type or namespace name 'XmlTypeAttributeAttribute' does not exist in the namespace 'System.Xml.Serialization' (are you missing an assembly reference?)
Error CS0246 The type or namespace name 'AnonymousType' could not be found (are you missing a using directive or an assembly reference?)
Attributes from a class in autogen file
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
I have now solved this issue with adding nugets to my project.
System.Xml.XmlSerializer
Solution: Removes the serializations attribute issues except the DesignerCategoryAttribute
Newtonsoft.json
Solution: Removes the DesignerCategoryAttribute
Now it is possible to compile the xsd.exe generated class and use it in net core
netstandard2.0 can compile xsd.exe generated files with no problems
There is no way actualy but if you see this it's a part of the future .net core release (.Net Core 1.2 release on Q2 2017).
If you want more Info, see this discuss and specially this point.

DNX core application version information

In earlier .NET based applications I implemented a central method for returning application information, usually product name, version and legal copyright. This method was implemented via System.Reflection.Assembly or in newer applications via System.Diagnostics.FileVersionInfo. This allowed me keep the version number in a central place, namely the main assembly file, and edit it easily in Visual Studio project properties.
Now in DNX core all this doesn't seem to be available, neither System.Reflection nor System.Diagnostics.
How would you suggest to manage version information in a DNX core based ASP.NET 5 application in a platform neutral way?
You can implement something like dnx's IRuntimeEnvironment:
IRuntimeEnvironment
RuntimeEnvironment (the implementation of IRuntimeEnvironment)
Now in DNX core all this doesn't seem to be available, neither System.Reflection nor System.Diagnostics.
Not sure what you mean by that. System.Reflection and System.Diagnostics are available: https://github.com/aspnet/dnx/blob/219871c6063d00f8297eeafe93266f1048f59a45/src/Microsoft.Dnx.Host/project.json#L21-L23
If you cannot find a particular type, use the PackageSearch website to see in which NuGet package it is
The project.json file has a version number, name, description, copyright, authors etc. These are the same properties used to build a NuGet package. In fact, if you create a 'Class Library (Package)' project, you can compile it directly to a NuGet .nupkg file by checking the option in project properties.
I believe you can read this file using Configuration.GetConfigurationSection. ApplicationSettings is just a class with the properties from the project.json that you want to read.
var configurationSection = configuration.GetConfigurationSection(nameof(ApplicationSettings));
var applicationSettings = ConfigurationBinder.Bind<ApplicationSettings>(configurationSection);

Could not add system.web.routing in class library

I want to create a class library for an MVC 4 web application.I created class library project in same solution and write classes and other stuff in class library.I added the reference System .Web.Routing in my class library project. But when i tried to use
System.Web.Routing in project that displays following error
The type or namespace Routing does not exist in the namespace System.Web
How to add this in my class library project?

How do I convert a COM assembly to a CLR Assembly?

How Can I convert a COM server to a CLR Assembly so that I don't have to initially rewrite anything.
I posted this here for the OP, as they posted it origionally as an edit to question.
Rather than rewriting a COM server (written in 1992 using C++/MFC) in .Net, I have decided to convert it to a CLR assembly. To take a COM assembly (add32.exe) and use it from a .Net client, we need to create a callable wrapper. Run all tools with the Visual Studio Command Prompt (as Administrator).
Step 1: Sign a COM assembly with a strong name
Step 2: Convert definitions found in a COM type library into a CLR assembly
Convert the definitions found in a COM type library into a CLR assembly using the tool Tlbimp.exe. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library. The output is a DLL file. I specify a namespace so that we can easily include the metadata in the .Net COM client.
Step 3: Use ILDASM.EXE to view the assembly.
To use the CLR assembly, we to create a reference for it in the solution. Browse for the dll file and add it as a reference.
Clients that use COM objects should import metadata using the namespace created in Step 2.
#using "Add32Pkg";
Then, to use the COM functionality:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Add32Pkg;
namespace TestAdd32
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Add32Server Add32 = new Add32Server();
Add32.Init(201);
}
}
}

System.Runtime.Serialization.DataContractAttribute doesn't exist in the namespace System.Runtime.Serialization

I'm doing some WCF work and I don't see why I run into this error.
System.Runtime.Serialization.DataContractAttribute doesn't exist in the namespace
System.Runtime.Serialization
The microsoft documentation clearly shows this hierarchy
System.Object
System.Attribute
System.Runtime.Serialization.ContractNamespaceAttribute
Anyone knows what is going on?
Make sure you have added reference to the System.Runtime.Serialization assembly to your project.