I have three solution A, B and C.
I have an enum in A like this:
using System.Runtime.Serialization;
namespace A.Entities
{
[DataContract]
public enum Status
{
[DataMember]
Active = 0,
[DataMember]
Inactive = 1,
}
}
I reference it in solution B like this:
using A.Entities;
namespace B.Entities
{
public class User
{
[DataMember]
public string UserName { get; set; }
[DataMember]
public Status Status { get; set; }
}
}
In solution C, I use them like this:
using B.Entities;
using Status = A.Entities.Status;
namespace C.TestDatas
{
public class UserTestData
{
public static User CreateUser()
{
return new User
{
Status = Status.Active,
}
};
}
}
When I invoke User method, it throw exception:
Method not found: 'Void B.Entities.User.set_Status(A.Entities.Status)'.
Why? I hope someone can help me, thanks!
I can't reproduce the problem. Your code works fine on my computer (on .NET framework 4.5)
Could you make sure that you project is configured correctly:
Both A and B solutions have reference to System.Runtime.Serialization
C has reference to A and B. Make sure you don't link the dll from /Bin folder, but you have the project reference
Hit Clean and Rebuild buttons in Visual Studio.
Related
I have built a solution that builds well on local and runs well on direct deploy. When I want to deploy via Pipeline I get errors like this:
Classname.cs(4,35): Error CS1514: { expected
If the structure is
namespace PostgreDataAccess.Models
{
public class ClassName
{
public string prop1 { get; set; }
public string prop2 { get; set; }
}
}
it has no problem, but If I try
namespace PostgreDataAccess.Models;
public class ClassName
{
public string prop1 { get; set; }
public string prop2 { get; set; }
}
I have series of the quoted error.
I have so many classes like this, how can I solve this problem at once without having to edit over 103 class?
Thanks
"Classname.cs(4,35): Error CS1514: { expected" This is very likely due to the new "permissions" on updated versions of C#. Is it in C# 8.0? Where namespace no longer needs the "{}"? I can't remember... But likely you built your code on the pipeline with a compiler, that works on C# 6.0 but you are locally using the newest version of C# 8.0. Either revert you namespace definitions back to pre- 8.0 OR update the pipeline compiler, like #DavidG recommended. 8.0 can still understand the syntax of 6.0 but not vice versa.
I have a problem using a namespaced component which works in some places but not others:
Pages/Transactions/List.razor
<Test #ref="Test1"></Test>
Pages/Transactions/List.razor.cs:
using Accounting.Web.Components.Test;
namespace Accounting.Web.Pages.Transactions
{
public partial class List
{
private Test Test1 { get; set; } = default!;
}
}
The above reference to Test works as expected.
But then I want to to use the Test component in another component, so I do the following:
Components/Transactions/TRansactionRules/TRansactionRules.razor.cs
using Accounting.Web.Components.Test:
namespace Accounting.Web.Components.Transactions.TransactionRules
{
public partial class TransactionRules
{
[Parameter]
public Test Test1 { get; set; } = default!; // error
}
}
But using it in the component above produces the following error:
"Test" is a namespace but used as a type
At which point I have to replace the line with:
public Accounting.Web.Components.Test.Test Test1 { get; set; } = default!;
while elsewhere I can refer to it as Accounting.Web.Components.Test
It seems the folder / file structure has something to with it:
+Pages
+Transactions
-List.razor
-List.razor.cs
+Components
+Test
-Test.razor
-Test.razor.cs
+Transactions
+TransactionRules
-TransactionRules.razor
-TransactionRules.razor.cs
It seems when I try to use the Test component in a another component which is nested in a extra subfolder, reference to it fails, otherwise it will work.
I wish to refer to it as Accounting.Web.Components.Test rather than Test.Test regardless of where it is used. Am I doing something wrong, if so what?
I belive the error you are getting is because you are 'using' a namespace which also contains the full name of he type you are trying to use. I think removing .Test from the using directive should fix the issue.
using Accounting.Web.Components
namespace Accounting.Web.Components.Transactions.TransactionRules
{
public partial class TransactionRules
{
[Parameter]
public Test Test1 { get; set; } = default!; // error
}
}
(optional) You can move below code inside of _Imports.razor file in blazor solution, and outside of your component code. This way it will make it available everywhere into your blazor solution and not just one component file.
using Accounting.Web.Components
After accidentally hitting rename of my skv_match class to skv_player class I have issue with my ReadMatches method. The Visual studio keeps telling me, there is no definition of methods in class skv_player when I use class skv_match instead (after I renamed the class back to skv_match).
I am desperate and don't know if I am doing something wrong or Visual studio for Mac is. Does anybody know how to solve this or did I miss something in the code?
I tried to restart the app and laptop, rebuild and clean project. I also tried deleting the figuring classes, creating them again and pasting the original content in them.
public string ReadMatches()
{
var matches = _context.skv_match.AsNoTracking();
StringBuilder sb = new StringBuilder();
if (matches == null)
{
return "No matches found";
}
else
{
foreach (var skv_match in matches)
{
sb.Append($"Match id: {skv_match.id }\r\n");
sb.Append($"Match results: {skv_match.home_team}");
sb.Append($"{skv_match.home_score }:");
sb.Append($"{skv_match.visitor_score } ");
sb.Append($" {skv_match.visitor_team }\r\n");
}
}
return sb.ToString();
}
public class skv_match
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)]
public int id { get; set; }
public string home_team { get; set; }
public string visitor_team { get; set; }
public int home_score { get; set; }
public int visitor_score { get; set; }
}
I get error: "'skv_player' does not contain a definition for 'home_team' and no accessible extension method 'home_team' accepting a first argument of type 'skv_player' could be found (are you missing a using directive or an assembly reference?)" and same for other methods
I expect the app to just take this without any errors, yet I get error that class I am not referencing misses methods. Before I accidentally hit rename the class everything worked just fine.
Ok my apologies to everyone who took time trying to help me. There was issue in Entity framework DbContext. I don't know if I was just tiredly stupid, or mentioned missclick changed it.
For anyone trying to solve this issue, try Right click on the declaration and "Go to declaration". It will point you to the part where you define it.
To be specific, I clicked on part skv_match at var matches = _context.skv_match.AsNoTracking();
I have a piece of code
using (InContext inContext = new InContext())
When I right click the definition, it points to C:\Users\me\AppData\Local\Temp\....
What is that? A defined dll?
#region Assembly SharedObjects.dll, v4.0.30319
// C:\source\blah\blah\packages\SharedObjects.1.0.4659.22817\lib\net40\SharedObjects.dll
#endregion
using blahSharedObjects;
using System;
using System.Data.Entity;
namespace something
{
public class InContext : DbContext
{
public InContext();
public InContext(string connectionString);
public DbSet<InDetails> InDetailRecords { get; set; }
public string IPAddress { get; set; }
public string UserName { get; set; }
}
}
The location you are referring to is your local user account temp folder. Is the InContext class in your App_Code folder? Is the name of the DLL your referring to the same as your project?
I can only assume it's being built with the solution which in turn put it in the temp folder. Try cleaning/rebuilding to see if it is still the same.
I wrote simple piece of code to get involved into Afterthought, but it doesn't work and I've got no idea why. A huge part of it is taken from other SO question: How to implement simple Property Ammendment with Afterthought.
using System;
using System.Collections.Generic;
using Afterthought;
namespace SecondAmendmentTest
{
class Program
{
public class TestUser
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public bool HasChanged { get; set; }
public void method()
{
Console.WriteLine("method");
}
}
public class TestUserAmmendment<T> : Amendment<T, T> where T : TestUser
{
public TestUserAmmendment()
{
Properties
.AfterSet((instance, x, y, z, a) => instance.HasChanged = true);
Methods.After(ExceptionMethod);
}
private object ExceptionMethod(T instance, string method, object[] parameters, object result)
{
throw new NotImplementedException();
}
}
static void Main(string[] args)
{
TestUser tu = new TestUser();
Console.WriteLine("Has changed: " + tu.HasChanged.ToString());
Console.WriteLine("Performing changes...");
tu.Id = 5;
tu.FirstName = "name";
tu.LastName = "lastname";
Console.WriteLine("Has changed: " + tu.HasChanged.ToString());
tu.method();
Console.ReadKey();
}
}
}
It compiles, but no changes are made into output exe file. I've configured post build event. Build output:
1>------ Rebuild All started: Project: SecondAmendmentTest, Configuration: Debug Any CPU ------
1> SecondAmendmentTest -> C:\Users\Lukasz\Documents\Visual Studio 11\Projects\SecondAmendmentTest\SecondAmendmentTest\bin\Debug\SecondAmendmentTest.exe
1> Amending SecondAmendmentTest.exe (5,559 seconds)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
And finally output from application after running:
C:\Users\Lukasz\Documents\Visual Studio 11\Projects\SecondAmendmentTest\SecondAmendmentTest\bin\Debug>SecondAmendmentTest.exe
Has changed: False
Performing changes...
Has changed: False
method
Neither HasChanged property were modified nor NotImplementedException was thrown. I'm using last sources from Git. Have you some ideas why it doesn't work?
EDIT: Here is entire solution: SecondAmendmentTest.zip
I know it's a year later but:
To build on Willem van Ketwich's answer, there was actually a bug (oversight?) in Afterthought.NET that wasn't allowing nested types to be amended if thier parent type wasn't amended.
I've submitted a pull request fixing the bug.
In addition to this fix, you still need the [Amendment(typeof(TestUserAmmendment<>))] on your nested class to trigger the amendment.
I got this to work by doing two things:
Move the TestUser and TestUserAmmendment classes out of the Program
class so they aren't nested.
Add the attribute [Amendment(typeof(TestUserAmmendment<>))] to the
TestUser class.
The working solution can be found here.