有人能指出我使用XML文件而不是数据库来解释实体框架的好教程吗?我已经看过一些关于SQL数据库的好教程,但是我无法跨越XML文件.
谢谢!
是否有任何工具可以帮助调试/检查xml序列化过程?
例如,假设一个项目被标记为内部而不是公共.没有编译时错误消息,也没有运行时错误消息.如果设置断点并进入序列化过程,则只是跳过该项.换句话说,通常很难找到这些类型的问题.调试工具将允许您逐步完成该过程并提供一些反馈,例如遇到此属性,通过属性迭代并且没有找到相应的公共过程,跳过.另一种选择是检查所有具有xml序列化属性的类的检查工具,以确保它们是可访问的并具有设置方法等.
我试图将Window Title绑定到具有Title属性的ViewModel.以下是MainWindow XAML:
<Window x:Class="MyProject.View.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MyProject.ViewModel;assembly=MyProject.ViewModel"
Title="{Binding Path=Title}" Height="350" Width="525" DataContext="{Binding Source={StaticResource mainWindowViewModel}}">
<Window.Resources>
<vm:MainWindow x:Key="mainWindowViewModel"/>
</Window.Resources>
...
</Window>
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我得到以下异常"在'System.Windows.StaticResourceExtension'上提供值引发异常.行号和位置指向DataContext属性,内部异常指出"找不到名为mainWindowViewModel的资源.
以下是View Model的代码:
namespace MyProject.ViewModel
{
public class MainWindow : INotifyPropertyChanged
{
#region Fields
private const string TitlebarPrefixString = "My Project";
private string title = TitlebarPrefixString;
public string Title {
get
{
return this.title;
} // End getter
set
{
this.title = value;
OnPropertyChanged("Title");
} // End setter
} // End property
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler …Run Code Online (Sandbox Code Playgroud) 我正在编写一个使用SQL Server CE 4.0文件的C#应用程序,这些文件可以通过代码优先通过Entity Framework 6.0访问.(应用程序需要能够使用本地dll进行SQL Server CE连接,即应用程序需要可以部署XCOPY).应用程序在我的开发机器上运行良好,但在其他机器上(例如只有Win7和.NET 4.0的VM),我得到一个ArgumentException:
具有不变名称"System.Data.SqlServerCe.4.0"的ADO.NET提供程序未在计算机或应用程序配置文件中注册,或者无法加载.有关详细信息,请参阅内部异常
内部异常消息说:
无法找到请求的.Net Framework数据提供程序.它可能没有安装.
我搜索过Google和SO,大多数评论表明确保App.config文件正确无误.我相信我的(默认连接工厂和提供商部分),但这里是内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
</configuration>
Run Code Online (Sandbox Code Playgroud)
build文件夹包含以下文件(当然还有特定于应用程序的文件):
在每个amd64和x86子文件夹中都有以下文件:
我确定该程序在开发机器上运行,因为已经安装了SQL Server CE,但是如何在其他机器上使用本地SQL Server CE …
我的 xUnit 测试在本地运行良好,但无法在 Azure DevOps 上运行。受测试的程序集是 .NET 5.0 程序集,测试程序集也是如此。
检查 VsTest 任务的日志文件,我看到以下内容
测试运行检测到针对不同框架和平台版本构建的 DLL。以下 DLL 与当前设置不匹配,即 .NETFramework、Version=v5.0 框架和 X86 平台。
UnitTests.dll 是为 Framework .NETCoreApp、Version=v5.0 和 Platform AnyCPU 构建的。
Microsoft.TestPlatform.CommunicationUtilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。
Microsoft.TestPlatform.CoreUtilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。
Microsoft.TestPlatform.CrossPlatEngine.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。
Microsoft.TestPlatform.PlatformAbstractions.dll 是为 Framework .NETCoreApp、Version=v2.1 和 Platform AnyCPU 构建的。
Microsoft.TestPlatform.Utilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。
Microsoft.VisualStudio.TestPlatform.Common.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform AnyCPU 构建的。
Microsoft.VisualStudio.TestPlatform.ObjectModel.dll 是为 Framework .NETStandard、Version=v2.0 …
我正在开发一个作为服务启动的应用程序,但只有在命令行开关告诉它时(否则打开标准表单).因此,当Windows在启动时启动服务时,它必须通过此命令行选项或服务无法启动.
我想让安装程序(ServiceProcessInstaller)添加一个命令行选项,以便在启动服务时将命令行选项添加到命令中.
示例:MyService.exe -commandlineoption
我认为这就是ServiceProcessorInstaller.Context属性的用途,但这是针对在InstallUtil上执行的参数.
有什么建议?
我正在寻找示例,教程,或只是"这个+这个应该工作",用于从诸如Arduino板之类的微控制器读取和写入SQL服务器(2008).我也看过(并且可能会使用)带有.Net Micro Framework的设备,例如Fez Cobra.Micro Framework不包含ADO.我确信这将涉及一些XML,但我无法弄清楚要进一步调查哪种技术.我不想让PC应用程序充当中间人.
谢谢!
我试图通过添加一个程序集来访问另一个程序集的内部类
[assembly:InternalsVisibleTo("assembly-name")]
Run Code Online (Sandbox Code Playgroud)
到第二个集会.但是,这会导致以下错误:
error CS0246: The type or namespace name 'InternalsVisibleTo' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
我在这里的例子: MSDN参考
我究竟做错了什么?
我在应用程序中实现了一个简单的插件架构.插件要求是使用接口(IPlugin)定义的,该接口位于应用程序和插件引用的*.dll中.该应用程序有一个插件管理器(也在同一个*.dll中),它通过查找插件文件夹中的所有*.dll加载插件,加载它们,然后检查插件是否实现了接口.我已经通过两种不同的方式检查了[以前通过一个简单的if(插件是IPlugin)],但是当插件实现接口时,都不会识别.这是代码:
Assembly pluginAssembly = Assembly.LoadFrom(currFile.FullName);
if (pluginAssembly != null)
{
foreach (Type currType in pluginAssembly.GetTypes())
{
if (currType.GetInterfaces().Contains(typeof(IPlugin)))
{
// Code here is never executing
// even when the currType derives from IPlugin
}
}
}
Run Code Online (Sandbox Code Playgroud)
我曾经测试过一个特定的类名("插件"),但后来我允许它循环遍历程序集中的所有类都无济于事.(这是我在其他地方找到的一个例子.)为了使这更复杂一点,有两个接口,每个接口实现原始接口(IPluginA,IPluginB).该插件实际上实现了一个更具体的接口(IPluginB).但是,我已经尝试使用插件只是实现更通用的接口(IPlugin),这仍然无法正常工作.
[编辑:回应我第一次收到的两个回复]是的,我尝试过使用IsAssignableFrom.请参阅以下内容:
Assembly pluginAssembly = Assembly.LoadFrom(currFile.FullName);
if (pluginAssembly != null)
{
foreach (Type currType in pluginAssembly.GetTypes())
{
if (typeof(IPlugin).IsAssignableFrom(currType))
{
string test = "test";
}
}
}
Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×3
xml ×2
arduino ×1
assemblies ×1
azure-devops ×1
command-line ×1
data-binding ×1
debugging ×1
installer ×1
interface ×1
internal ×1
mvvm ×1
service ×1
sql ×1
vstest ×1
wpf ×1
xunit ×1