Closed javiercn closed 4 years ago
Hit this today as well and reopened https://github.com/dotnet/cli/issues/941
This is related to dotnet/cli#2965. CLI is looking for a project.json in the current path and wants to pass "app.dll" as an argument.
I think this was fixed with dotnet/sdk#5994. Can you try again with the latest Preview2 build and close if this has been fixed?
BTW - to run your published app, you don't say dotnet run
. Instead you call, dotnet myapp.dll
. dotnet run
is a "development time" command, thus it needs a project.json file, and your project to be restored, etc.
Perhaps this can be clarified in documentation. I was trying to run my published app using dotnet run
, only to find out now it should be run using dotnet filename.dll
. Never mind, it shouldn't crash with such a vague error message. I haven't tried the preview2 bits yet though.
dotnet run is a "development time" command, thus it needs a project.json file, and your project to be restored, etc.
@eerhardt
But when you actually use dotnet run app.dll
on published self-contained app - it works. That is an expected behaviour?
Perhaps this can be clarified in documentation.
Agree with this. I got the same problem, and fixed it with this thread.
But when you actually use dotnet run app.dll on published self-contained app - it works. That is an expected behaviour?
Can you describe exactly the steps you took and which directory you were running from? The command can work if you execute it from the project directory:
mkdir MyTest
cd MyTest
dotnet new
Change project.json:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": "1.0.0-rc2-3002702"
},
"frameworks": {
"netcoreapp1.0": {}
},
"runtimes": {
"win7-x64": {}
}
}
dotnet restore
dotnet publish
dotnet run bin\Debug\netcoreapp1.0\win7-x64\publish\MyTest.dll
This only works by accident for 2 reasons:
dotnet run
is finding the project file in the current directory.bin\Debug\netcoreapp1.0\publish\MyTest.dll
is being interpreted as a command line argument into your app, and it is being passed into your app. You can confirm this by printing the arguments to the console.If however, I say:
cd bin\Debug\netcoreapp1.0\win7-x64\publish
dotnet run MyTest.dll
I get Object reference not set to an instance of an object.
@toddams
But when you actually use dotnet run app.dll on published self-contained app - it works. That is an expected behavior?
I suspect it is not running app.dll
, but it found a project.json
in the directory that you are running it from, and that is what is getting run.
This has been added to the documentation now (e.g. https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-run). Closing. Since the issue is by design, if the docs need more clarification, feel free to open the issue on dotnet/docs repo.
Steps to reproduce
Expected behavior
An error indicating that to use dotnet on a dll you shoud do dotne app.dll
Actual behavior
Object reference not set to an instance of an object.
Environment data
dotnet --info
output: .NET Command Line Tools (1.0.0-rc2-002611)Product Information: Version: 1.0.0-rc2-002611 Commit Sha: bf8f0edd89
Runtime Environment: OS Name: ubuntu OS Version: 14.04 OS Platform: Linux RID: ubuntu.14.04-x64
Other info "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0-rc2-24008", "type": "platform" }, "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-20581", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-20581" },
"frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "dnxcore50", "portable-net45+win8" ] } }