What is unknown construction in class declaration? - c#

I've just made a mistake while writing my code, and I find out some interesting unknown stuff.
public class OperationFactory(int code)
{
}
What (int code) it is here?
My compiler doesn't tell anything, so that's why I'm asking

I hope that You are not using Visual Studio IDE. are you?
I thought you are using Visual studio Code, need to install c# intelligence extensions if using other IDE's.
Compilation error. You may see warning if you are using Visual Studio IDE.
The Definition of class not allowing to take parameters msdn link
//[access modifier] - [class] - [identifier]
public class Customer
{
// Fields, properties, methods and events go here...
}

Related

public static class Contract && .net core 3.1 && macOS

how do I make Contract work on macOS?
the following code
private static int GetInt(string s)
{
Contract.Requires<ArgumentNullException>(s != null);
return 10;
}
static void Main()
{
Console.WriteLine(GetInt("s"));
}
leads to the exception:
An assembly (probably "TestConsoleApp") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.Requires and the CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild. CCRewrite can be downloaded from http://go.microsoft.com/fwlink/?LinkID=169180. \r\nAfter the rewriter is installed, it can be enabled in Visual Studio from the project's Properties page on the Code Contracts pane. Ensure that "Perform Runtime Contract Checking" is enabled, which will define CONTRACTS_FULL.
it's 2020 today, I work with dot.net core on my mac, but
the link from above is for downloading windows installer that was implemented 5 years ago in 2015 and works with Visual Studio 2010, 2012, 2013, 2015.
And I just wonder if public static class Contract is something that Microsoft uses internally or obsolete or something...
I hope someone can shed some light on the matter, can't you? ))
you were asking "I just wonder if public static class Contract is something that Microsoft uses internally or obsolete or something".
As per my understanding, it's unfortunately obsolete (it used to work with VS 2015 as you pointed out, provided you installed an extension).
See:
Does Visual Studio 2017 work with Code Contracts?
You could perhaps try PostSharp's version of Code Contracts?
I hope that MS will continue support of code contracts sometime in the future.

MediaSource doesn't contain any method

I followed this tutorial: https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/media-playback-with-mediasource and copied following line:
mediaSource = MediaSource.CreateFromStorageFile(file);
But Visual Studio shows an error:
"The type name 'CreateFromStoargeFile' does not exist in the type 'MediaSource'"
And MediaSource doesn't contain any Method/Property/... The IntelliSense poup doesn't even show.
I guess there is something wrong with Visual Studio or the UniversalWindowsPlatform core. I let Visual Studio repair itself but it doesn't work.
Edit:
The metadata of MediaSource contains all methods though...
Solution:
I put the new keyword in front of the MediaSource...
I am ashamed of myself...
From your screenshots, it looks like you are using the new keyword in front of your method call.
Try removing that.

Attach to process on Visual Studio

I trying to do something very simple here.
I use Visual Studio 2012. I created simple visual Studio class called BLA. The whole code is below.
using System;
using System.Collections.Generic;
using System.Text;
namespace BLA
{
public class Class1
{
public void hit() {
Console.Write("sdf");
}
}
}
I build it without errors. I put a breakpoint in "Console.Write("sdf")" and then try attach to process to iexplore.exe.
The process it attached but I get an error
The breakpoint will not currently be hit. No symbols have been loaded for the document.
I tried searching in google and stackoverflow I got many answers but none of them solved my problem.
Any idea how?
What kind of application are you building, you mention that you attach to iexplore.exe is it a webapplication?
You could allways try System.Diagnostics.Debugger.Break() to give you a debugging option.
You have to create the object of class Class1 and call the method hit() from that object.

Can't create Type Library File with Visual Studio 2010 generated DLL, but can with command-line compiled

I have a TestClass.cs file that contains an interface, and a class, much like this:
namespace CPierce.CSharpBridge
{
[System.Runtime.InteropServices.Guid("3D08DF02-EFBA-4A65-AD84-B08ADEADBEEF")]
public interface ICSide
{
// interface definition omitted...
}
[System.Runtime.InteropServices.Guid("CBC04D81-398B-4B03-A3D1-C6D5DEADBEEF")]
public partial class CSide : ICSide
{
// class definition omitted...
}
}
When I compile this at the command line, and run regasm on it:
csc /debug /t:library TestClass.cs
regasm TestClass.dll /tlb:TestClass.tlb
I get a nice, big .tlb file suitable for including in a C++ project elsewhere....
10/27/2011 01:50 PM 3,616 TestClass.tlb
When I put TestClass.cs into a "Class Project" in Visual Studio, compile it, run regasm, the resulting .tlb is pathetic and nearly useless -- it has no interface, no method signatures, etc...
[Compiled TestClass.cs as part of Project "ClassProject" in Visual Studio]
regasm ClassProject.dll /tlb:ClassProject.dll
10/27/2011 01:58 PM 1,132 ClassProject.tlb
This is the same C# code in both cases, one being compiled with Visual Studio one at the command line, giving me completely different results.
What gives?
--
Update: Hans suggests that the [ComVisible(true)] attribute missing is causing the problem. Tried it, and it worked. But that still doesn't answer the question, why? Why do I get different results based on which compile method I use?
If you create a new Class Library in Visual Studio, the default AssemblyInfo.cs file includes the line:
[assembly: ComVisible(false)]
The command-line command you're using is only compiling your TestClass.cs file, so you get the default setting for ComVisible (which, judging from the available evidence, is probably true). When you compile from the IDE, you include AssemblyInfo.cs as well, so its explicit setting overrides the compiler's default.
Also check if your class has functions of accessor type public.
In our case, the project was working fine when it was being used from within the solution but when we extracted the logic to create a DLL, it stopped creating the TLB file with no indication on why...
So if you have a class like so,
public class tlbuser{
private void functionTLB(){
//function code
}
// rest of the class code
}
Ensure it is changed to:
public class tlbuser{
public void functionTLB(){
//function code
}
// rest of the class code
}

upgrading a project from vs 2008 to 2010 loses generated code in service reference

I have a project that I'm upgrading from 2008 to 2010.
My problem is with the code being generated by a service reference. Any classes used in the Reference.cs are given by their full name according to the reference
The difference results in a 'cannot convert from foo.Data.MtkBaseRequest to foo.WebServicesClient.ModelDataService.MtkBaseRequest'
So I have the old code
namespace foo
{
public abstract class MtkBaseRequest{}
}
And this code being called
List<MtkBaseRequest> newList = new List<MtkBaseRequest>(requestArray);
this.DataAccessWebService.doStuff(newList);
but this is the method it means to call(which is generated)
public void doStuff(System.Collections.Generic.List<foo.WebServicesClient.ModelDataService.MtkBaseRequest> requests)
So what's happening is that the namespace no longer matches for the class which should be the same. In the code generated by VS 2008 the method being called is:
public void doStuff(System.Collections.Generic.List<foo.Data.MtkBaseRequest> requests)
Is there a work-around, or something I can do to get the code generating properly?
BTW: the project this is in is called WebServicesClient, the service reference is ModelDataService
I fixed it, turns out there were some assemblies hanging around in the GAC.
stupid GAC

Categories