I'm doing database unit testing and I'm trying to write data to files via localhost, but I'm getting the error Exception occurred: The network name cannot be found. I have a byte array that I want to put in a text file like so:
File.WriteAllBytes(outputFilePath, res);
Where res is the byte array and outputFilePath is a string assigned as "\\localhost\InterfaceFiles\Requirements.txt".
All the documentation I can find on the data types and operators indicate this should work. Anyone have an idea why it isn't? The file Requirements.txt doesn't exist yet, but WriteAllBytes should create it in that case.
edit: unchecked "trustworthy" in the Visual Studio database settings.
Try replacing localhost with your actual PC name; the computer host name which you get by running hostname command under command prompt.
"\\PC_NAME\InterfaceFiles\Requirements.txt"
Check the string assignment, I mean the string literal. If it contains single backslashes, then it should preceded by #. If no # then all backslashes should be doubled like:
#"\\host\path\filename.any"
// or
"\\\\host\\path\\filename.any"
Related
I'm not entirely sure at all why this is happening...
So I have a ExternalCommand and an application for making a ribbon tab and button. These two programs are in the same solution and under the same namespace, which allows me to have fewer files to deal with. When I create a button for my command, I want to put in the current path of the application that is currently running. I do this with Directory.GetCurrentDirectory() + \AddInsAll\Ribbon17.dll (where AddInsAll is the folder and Ribbon17 is the dll, obviously). I use # when necessary to avoid escape sequences. This string contains the exact assembly name needed, but Revit tells me "Assembly does not exist." If I replace this String variable with the hard coded C:\ProgramData\Autodesk\Revit\Addins\2017\AddInsAll\Ribbon17.dll it works. I want it obviously more robust than that. My code will be below, thanks in advance.
FYI: I have a TaskDialog showing when it first runs, and the fullPath that it returns is exacly the same as the hard coded path. I have to do a replace (Program Files to ProgramData) due to some weird bug with the get directory. Also, I add "\AddInsAll\Ribbon17.dll" to the end of the string because the CurrentDirectory goes only to Addins\2017. Finally, if you think the problem is due to the #'s, I have already tried putting it and taking it off of variables and none of the attempts work. But if you think of them is the problem, I welcome the advice. Thanks.
public class RibApp : IExternalApplication
{
public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application)
{
// Create a custom ribbon tab
String tabName = "Add-Ins";
String fakeFullPath = #Directory.GetCurrentDirectory() + #"\AddInsAll\Ribbon17.dll";
String fullPath = fakeFullPath.Replace(#"\Program Files\", #"\ProgramData\");
TaskDialog.Show("Hi", #fullPath);
application.CreateRibbonTab(tabName);
//Create buttons and panel
// Create two push buttons
PushButtonData CommandButton = new PushButtonData("Command17", "Command",
#fullPath, "Ribbon17.Command");
I suggest you skip the # and replace each backslash \ by a forward slash /.
KISS!
Better still, use an approach similar to the CreateRibbonTab implementation in the HoloLens Escape Path Waypoint JSON Exporter.
I was following the documentation on this OrchardProject.net link. I opened have activated the CodeGeneration module and opened the command prompt at the root of the project (Orchard.Web) and write "bin/Orchard.exe" for running the commands. Till then everything is fine. Now when I try to run the following command, it gives me the below exception. The command is:
codegen theme mishrajiTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true
Below is the output of the command.
Creating Theme
mishrajiTheme
Error executing command "codegen theme mishrajiTheme"
Specified argument was out of the range of valid values. Parameter
name: startIndex
Exception Details: System.ArgumentOutOfRangeException: Specified
argument was out of the range of valid values. Parameter name:
startIndex
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range
of valid values. Parameter name: startIndex] at
System.String.Insert(Int32 startIndex, String value) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.AddToSolution(TextWriter
output, String projectName, String projectGuid, String
containingFolder, String solutionFolderGuid) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateThemeFromTemplates(TextWriter
output, String themeName, String baseTheme, String projectGuid,
Boolean includeInSolution) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.IntegrateTheme(String
themeName, String baseTheme) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateTheme(String
themeName)
What I am doing wrong here or It is a bug in Orchard code generation module.
Please guide. I am using Orchard 1.10 version.
I solved this problem by changing the CodeGenerationCommands Class in line 434 in Orchard 1.10. the line is :
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\r\n"), projectReference);
to this :
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\n"), projectReference);
i don't know why by \r\n can not found the final EndProject and by changing that to \n it works fine
The line of code in question that has failed is this:
solutionText = solutionText.Insert(solutionText
.LastIndexOf("EndProject\r\n"),projectReference)
.Replace("GlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n",
projectConfiguationPlatforms);
If solutionText.LastIndexOf("EndProject\r\n") doesn't find anything it will return -1 - see the MSDN docs here.
It looks like that is then being passed to the string.Insert which is an invalid out of index.
The only thing that I can think is that your git client or however you got your hands on the orchard source has somehow changed the line endings in the file so it can't find the \r\n.
I'm guessing you are from the indian subcontinent, is your OS running a non-english language? I don't think that the .sln file localises fields like EndProject and I don't think Windows varies its newline character representation but something is going wrong here.
Workaround Solution
This is the very last thing that the codegen theme command does, it has created everything else and just failed to add your project into the Orchard.sln. To get moving right now you can just add it to your solution:
In visual studio, open solution explorer window
Right click on your Themes solution folder
Click Add | Existing project
Navigate to the folder and select your new theme
Potential Bug
It seems like there could be a bug here. Would you be willing to post your .sln file to me via email so I can investigate it further?
I am using SharpSVN to connect and retrieve information from Visual SVN Server by C#.
But on SVN Server, a Repository have folder with the name is C# and when read to this folder, exception occurred:
Additional information: URL
'https://< svnserver >/svn/IT/02_SHOPFLOOR/C' non-existent in
revision 13
I debug and found that URI still be:
{https://< svnserver >/svn/IT/02_SHOPFLOOR/C#} System.Uri
How could I do to access SVN repositories which contain special characters?
I had used like following but nothing changed:
if (lists[i].Path.Contains("#"))
{
path = lists[i].Path.Replace("#", "\\#");
}
else
{
path = lists[i].Path;
}
reposss[i] = new Uri("https://< svnserver >/svn/IT/02_SHOPFLOOR/" + path);
svnClient.GetList(reposss[i], out listsInfo); //Exception occur at here
The # is the schema operator in a Url. You need to escape this character using the uri escape rules. There are helper functions for this on the System.Uri class and for some specific scenarios on SvnTools. The escaped character will be something like %23 where 23 is the hexadecimal value of the character.
I want to build my solution file from other c# code using msbuid I have tried
var msbuild_path = #"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
var solution_path = #"D:\Sumit\WorkingCopy\Final\Final.sln";
Process.Start(msbuild_path + " " + solution_path);
but this one throws an error Please help me out!!
According to https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx , the Process.Start method takes two arguments:
public static Process Start(string fileName, string arguments)
So you should change your code to
Process.Start(msbuild_path, solution_path);
What you were doing before was actually trying to run a file named "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe(space)D:\Sumit\WorkingCopy\Final\Final.sln", but no such file exists with that name. The msbuild.exe may exist, but "msbuild.exe D:\Sumit...\Final.sln" is not the filename you meant to pass as the command filename. Also, the argument string was empty, so the system assumed you did not want to pass any arguments to "msbuild.exe D:\Sumit...\Final.sln". But the error message was because the two filenames were mashed into one filename.
Windows allows filenames to contain embedded spaces, which frequently causes problems in dealing with command-line arguments.
I first had this SQLite version: 1.0.77.0 (sqlite-netFx40-static-binary-bundle-Win32-2010-1.0.77.0)
and everything was working fine.
After updating my System.Data.SQLite.dll to version 1.0.82.0 (sqlite-netFx40-static-binary-bundle-Win32-2010-1.0.82.0) I now receive this:
Unable to open database. Connection string: 'datetimeformat=ISO8601;synchronous=Off;uri="file://C:/Users/username/Documents/data/test.db";version=3;journal mode=Truncate;default isolationlevel=ReadCommitted;pooling=True'; Error: 'System.InvalidOperationException: Invalid connection string: invalid URI
I've also tried file:/// instead of file:// without any luck.
Could anybody tell me what is wrong with my URI, why it doesn't work anymore in v1.0.82.0 but worked in v1.0.77.0?
http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
(1.0.82.0 == 3.7.14)
The best way to get correct connection string is to always use the SQLiteConnectionStringBuilder class to generate them.
SQLiteConnectionStringBuilder conn_builder = new SQLiteConnectionStringBuilder
{
DateTimeFormat = SQLiteDateFormats.ISO8601,
SyncMode = SynchronizationModes.Off,
Version = 3,
JournalMode = SQLiteJournalModeEnum.Truncate,
DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted,
Pooling = true,
Uri = new Uri(#"c:\tmp\db.sqlite").AbsoluteUri
};
string conn_str = conn_builder.ConnectionString;
if Uri is not working, try setting DataSource instead (if you are using a local file).
A quick check shows that DataSource is evaluated before Uri in SQLiteConnection.cs and takes precedence over it, so if there is a bug in the Uri handling, using DataSource may help bypassing it.
According to the docs starting from the version 1.0.82.0 it was changed:
Add support for URI file names via the new FullUri connection string
property.
Example:
var connection = new SQLiteConnection("FullUri=file:mydb.sqlite?cache=shared");
following works for me, for following example you can't not use Data Source
FullUri=file::memory:?cache=shared
See these URI filename examples, but your URI (with three slashes) looks correct.
I think you should try to strip down your connection string to the basics and then add the options.
Take a look at this site for example SQLite connection string options.
http://www.connectionstrings.com/sqlite
The 3 /// is only valid when you are trying to escape out the spaces in the uri, I would also say that you should try moving the db out of the users folder to the root on c:\ in case the access permissions are not valid for it to access the DB and it also means a simpler connection string for you to try.
Good luck